-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI_msg.c
More file actions
34 lines (30 loc) · 720 Bytes
/
MPI_msg.c
File metadata and controls
34 lines (30 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <mpi.h>
#include <string.h>
#include <stdio.h>
const int MAX_STRING = 100;
int main(void)
{
char greeting[MAX_STRING];
int size;
int rank;
int i;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if(rank != 0)
{
sprintf(greeting, "Greeting from proceess %d of %d!", rank, size);
MPI_Send(greeting, strlen(greeting)+1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
}
else
{
printf("Greeting from Master process %d of %d!\n", rank, size);
for(i=1; i<size; i++)
{
MPI_Recv(greeting, MAX_STRING, MPI_CHAR, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("%s\n", greeting);
}
}
MPI_Finalize();
return 0;
}