Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <mpi.h>
  4.  
  5. const int MAX_STRING = 100;
  6.  
  7. int main(void) {
  8. char greeting[MAX_STRING];
  9. int comm_sz;
  10. int my_rank;
  11. int q;
  12.  
  13. MPI_Init(NULL, NULL);
  14. MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
  15. MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  16.  
  17. if (my_rank != 0) {
  18. sprintf(greeting, "Greetings from process %d of %d!", my_rank, comm_sz);
  19. MPI_Send(greeting, strlen(greeting) + 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
  20. }
  21. else {
  22. printf("Greetings from process %d of %d!\n", my_rank, comm_sz);
  23. for (q=1, q<comm_sz, q++) {
  24. MPI_Recv(greeting, MAX_STRING, MPI_CHAR, q, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  25. printf("%s\n", greeting);
  26. }
  27. }
  28. MPI_Finalize();
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement