Created
September 5, 2010 19:58
-
-
Save nerdyworm/566274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stddef.h> | |
#include <stdlib.h> | |
#include "mpi.h" | |
main(int argc, char **argv ) | |
{ | |
char buffer[100]; | |
int i, rank, size, type=99; | |
MPI_Status status; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_size(MPI_COMM_WORLD, &size); | |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
if(rank == 0) { | |
printf("Master: Hello slaves give me your messages\n"); | |
for (i=1; i<size; i++) { | |
MPI_Send("hi msg plz", 10, MPI_CHAR, i, type, MPI_COMM_WORLD); | |
} | |
int message_count = 0; | |
while(message_count < size - 1) { | |
MPI_Recv(buffer, 100, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); | |
message_count++; | |
printf("Message reveived from process: %s\n", buffer); | |
} | |
} else { | |
MPI_Recv(buffer, 10, MPI_CHAR, 0, type, MPI_COMM_WORLD, &status); | |
char hostname[80]; gethostname(&hostname, 80); | |
sprintf(buffer, "Hi, my name is %s and my rank is: %d", hostname, rank); | |
MPI_Send(buffer, 100, MPI_CHAR, 0, type, MPI_COMM_WORLD); | |
} | |
MPI_Finalize(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grid01:4 | |
grid02:4 | |
grid03:4 | |
grid04:4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[brhodes6@coit-grid01 mpi_assign]$ mpiexec -machinefile machines -np 4 ./a.out | |
Master: Hello slaves give me your messages | |
Message reveived from process: Hi, my name is coit-grid01.uncc.edu and my rank is: 1 | |
Message reveived from process: Hi, my name is coit-grid01.uncc.edu and my rank is: 2 | |
Message reveived from process: Hi, my name is coit-grid01.uncc.edu and my rank is: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment