Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. GNU nano 2.2.6 Plik: /home/student/RafalS/lab11_l1.c
  2.  
  3. #include <stdio.h>
  4. #include <mpi.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. int main(int argc, char* argv[])
  8. {
  9.  
  10. int id, p;
  11. int to, from, tag;
  12. int i;
  13. char data[100];
  14. MPI_Status status;
  15.  
  16. MPI_Init(&argc, &argv);
  17. MPI_Comm_rank(MPI_COMM_WORLD, &id);
  18. MPI_Comm_size(MPI_COMM_WORLD, &p);
  19.  
  20.  
  21. if(id!=0){
  22. to=0;
  23. tag=2017;
  24. sprintf(data,"Pozdrowienia od procesu %d\n",id);
  25. MPI_Send(&data,strlen(data)+1, MPI_CHAR, to, tag, MPI_COMM_WORLD);
  26. }
  27.  
  28. if (id == 0) {
  29.  
  30. for(from=1;from<p;from++)
  31. {
  32.  
  33.  
  34. MPI_Recv(&data,100,MPI_CHAR,from,tag,MPI_COMM_WORLD,&status);
  35. printf("%s\n",data);
  36. }
  37. }
  38.  
  39.  
  40.  
  41. MPI_Finalize();
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement