daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Nov 9th, 2018 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <mpi.h>
  2. #include <iostream>
  3. using namespace std;
  4. int main(int argc, char **argv) {
  5. int rank,size,len;
  6. string message;
  7. char host[MPI_MAX_PROCESSOR_NAME];
  8. MPI_Status status;
  9. MPI_Init( &argc, &argv);
  10. MPI_Comm_rank( MPI_COMM_WORLD, &rank );
  11. MPI_Comm_size( MPI_COMM_WORLD, &size );
  12. MPI_Get_processor_name(host,&len);
  13. int taskid=rank;
  14. int numtask=size;
  15. int partner;
  16. char* hostname;
  17. if(size>0 && size%2==0){
  18. cout<<"" <<"Zbyt mala liczba zadan"<<size<<endl;
  19. return 0;
  20. }
  21. else{
  22. if(taskid==0)
  23. {
  24. cout<<"Masternumber of MPI task is:"<<numtask<<endl;
  25. MPI_Get_processor_name(hostname,&len);  
  26. cout<<"Hello from task"<<taskid<<"on"<<hostname<<endl;
  27. }
  28.  
  29. if(taskid< numtask/2) {
  30.  
  31. partner=numtask/2 +taskid;
  32. MPI_Recv(&message,1,MPI_INT, partner,1,MPI_COMM_WORLD,&status);
  33.  MPI_Send(&taskid, 1, MPI_INT, partner, 1, MPI_COMM_WORLD);
  34. }
  35. else if(taskid>=numtask/2){
  36.  
  37. partner = taskid-numtask/2;
  38. MPI_Send(&taskid, 1, MPI_INT, partner, 1, MPI_COMM_WORLD);
  39. MPI_Recv(&message,1,MPI_INT, partner,1,MPI_COMM_WORLD,&status);
  40.  
  41. }
  42. cout<<"Task"<<taskid<<"Is partenr with"<<message<<endl;
  43. }
  44.  
  45. MPI_Finalize();
  46. return 0; }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top