Advertisement
Sawy3R11

MPI_2_status

Apr 16th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 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.         MPI_Status mpi_status;
  22.         int number_of_data;
  23.  
  24.         char message[6];
  25.         MPI_Recv( message, 6, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &mpi_status);
  26.         printf("process 2 recv: %s", message);
  27.  
  28.         //get info
  29.         MPI_Get_count(&mpi_status, MPI_CHAR, &number_of_data);
  30.         printf("\nNumber of data: %d, source: %d, tag: %d", number_of_data, mpi_status.MPI_SOURCE, mpi_status.MPI_TAG );
  31.     }
  32.  
  33.     MPI_Finalize();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement