Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- 35
- 36
- 37
- #include "mpi.h"
- #include <stdio.h>
- #include <string.h>
- int main(int argc, char**argv) {
- int rank, size, i, buf[1];
- const int strsize = 100;
- char msg[strsize];
- MPI_Status status;
- //initialize MPI
- MPI_Init(&argc, &argv);
- //set the number of processes
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- //set rank of all processes / nodes
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- if(rank != 0 ){
- sprintf( msg, "msg from node %d out of %d nodes\n", rank, size);
- MPI_Send(msg, strlen(msg)+1, MPI_CHAR, 0, 0, MPI_COMM_WORLD );
- }
- else{
- for(i=1; i<size;i++ ){
- MPI_Recv(msg, strsize, MPI_CHAR, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE );
- printf("%s\n", msg);
- }
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment