pborawski

mpi funkcje send recv zad 2

Dec 17th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include <mpi.h>
  2. #include <stdio.h>
  3. //#include <math.h>
  4.  
  5. int main( int argc, char *argv[] )
  6. {
  7.     int i;
  8.     int numproc,myid;
  9.     int from,to,tag, count;
  10.     int r_count, r_source, r_tag;
  11.     double data[100];
  12.    
  13.     MPI_Status status;
  14.     MPI_Init(&argc,&argv);
  15.     MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  16.     MPI_Comm_size(MPI_COMM_WORLD, &numproc);
  17.    
  18.     if( myid == 0 )
  19.     {
  20.         for(i = 0; i < 100; i++)
  21.         {
  22.             data[i] = (double)i;
  23.         }
  24.         count = 9;
  25.         to = 3;
  26.         tag = 2012;
  27.         MPI_Send(data, count, MPI_DOUBLE, to, tag, MPI_COMM_WORLD);
  28.     }
  29.     else if (myid == 3)
  30.     {
  31.         count = 100;
  32.         from = MPI_ANY_SOURCE;
  33.         tag = MPI_ANY_TAG;
  34.         MPI_Recv(data,count,MPI_DOUBLE,from,tag,MPI_COMM_WORLD,&status);
  35.         MPI_Get_count(&status, MPI_DOUBLE, &r_count);
  36.         r_source = status.MPI_SOURCE;
  37.         r_tag = status.MPI_TAG;
  38.         printf("Zmienna status - informacje;\n");
  39.         printf("Pochodzenie komunikatu i proces: %d\n", r_source);
  40.         printf("Znacznik komunikatu: %d\n", r_tag);
  41.         printf("Liczba elementow: %d\n", r_count);
  42.         printf("Proces %d odebral: \n", myid);
  43.        
  44.         for( i = 0; i < r_count; i++ )
  45.         {
  46.             printf("%f ", data[i]);
  47.         }
  48.         printf("\n");
  49.     }
  50.     else {}
  51.     MPI_Finalize();
  52.    
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment