Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. int checkBit = 1 << ((int)(log(size) / log(2)) - (iteration + 1));
  2.  
  3. if (! (rank & checkBit)) {
  4. // TODO Select main in group
  5. MPI_Recv(&addSize, 1, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  6. MPI_Recv(&(subArray[mySize]), addSize, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  7.  
  8. int partLength = mySize + addSize;
  9.  
  10. int less = 0;
  11. int greater = partLength - 1;
  12.  
  13. while (less <= greater) {
  14. if (subArray[less] >= pivot) {
  15. int buf = subArray[less];
  16. subArray[less] = subArray[greater];
  17. subArray[greater] = buf;
  18. greater--;
  19. } else {
  20. less++;
  21. }
  22. }
  23.  
  24. sendSize = partLength - less;
  25. MPI_Send(&sendSize, 1, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD);
  26. MPI_Send(&(subArray[less]), sendSize, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD);
  27.  
  28. sendSize = less;
  29. } else {
  30. MPI_Send(&mySize, 1, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD);
  31. MPI_Send(subArray, mySize, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD);
  32. MPI_Recv(&sendSize, 1, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  33. MPI_Recv(subArray, sendSize, MPI_INT, rank ^ checkBit, 1000, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  34. cout << rank << "/" << size << " (" << localRank << "/" << localSize << ") size = " << mySize << ": ";
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement