Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. int mpi_Gather(int* send_data, int send_count, MPI_Datatype send_datatype, int* recv_data, int recv_count, MPI_Datatype recv_datatype, int root, MPI_Comm communicator)
  2. {
  3. int myid, numprocs;
  4. int* tmp = new int[send_count];
  5. MPI_Status status;
  6. MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  7. MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  8.  
  9. int index = 0;
  10. if (myid != root)
  11. {
  12. MPI_Send(send_data, send_count, MPI_INT, root, 99, MPI_COMM_WORLD);
  13. }
  14. else
  15. {
  16. for (int i = 0; i < send_count; i++)
  17. {
  18. recv_data[index] = send_data[i];
  19. index++;
  20. }
  21. for (int i = 1; i < numprocs; i++)
  22. {
  23. MPI_Recv(tmp, recv_count, MPI_INT, i, 99, MPI_COMM_WORLD, &status);
  24. for (int j = 0; j < send_count; j++)
  25. {
  26. recv_data[index] = *tmp;
  27. *(++tmp);
  28. index++;
  29. }
  30. }
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement