Advertisement
Sawy3R11

MPI_1

Apr 16th, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <mpi.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char** argv) {
  6.     MPI_Init(&argc, &argv);
  7.     int world_size;
  8.     MPI_Comm_size(MPI_COMM_WORLD, &world_size);
  9.     int rank;
  10.     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  11.  
  12.     printf("process: #%d", rank);
  13.  
  14.     //comunication
  15.     if (rank == 0) {
  16.         char helloMessage[] = "proc1";
  17.         MPI_Send( helloMessage, 6, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
  18.         //printf("process 1 send: %d", number);
  19.     }
  20.     else if (rank == 1) {
  21.         char message[6];
  22.         MPI_Recv( message, 6, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
  23.         printf("process 2 recv: %s", message);
  24.     }
  25.  
  26.     MPI_Finalize();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement