Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <mpi.h>
  3.  
  4. int main (void)
  5. {
  6.  
  7. int rank(0);
  8. MPI_Init(0, NULL);
  9. MPI_Comm_size(MPI_COMM_WORLD, &rank);
  10. std::cout << "Rank: " << rank << std::endl;
  11. char port_name[MPI_MAX_PORT_NAME];
  12. MPI_Open_port(MPI_INFO_NULL, port_name);
  13. char publish_name[1024] = {'t','e','s','t','_','p','o','r','t',''};
  14. MPI_Publish_name(publish_name, MPI_INFO_NULL, port_name);
  15. std::cout << "Port: " << publish_name << " (" << port_name << ")" << std::endl;
  16. MPI_Comm client;
  17. std::cout << "Wating for Comm..." << std::endl;
  18. MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client);
  19. std::cout << "Comm accepted" << std::endl;
  20. MPI_Comm_free(&client);
  21. MPI_Unpublish_name(publish_name, MPI_INFO_NULL, port_name);
  22. MPI_Close_port(port_name);
  23. MPI_Finalize();
  24. return 1;
  25.  
  26. }
  27.  
  28. #include <iostream>
  29. #include <mpi.h>
  30.  
  31. int main (void)
  32. {
  33.  
  34. int rank(0);
  35. MPI_Init(0, NULL);
  36. MPI_Comm_size(MPI_COMM_WORLD, &rank);
  37. std::cout << "Rank: " << rank << std::endl;
  38. char port_name[MPI_MAX_PORT_NAME];
  39. MPI_Open_port(MPI_INFO_NULL, port_name);
  40. char publish_name[1024] = {'t','e','s','t','_','p','o','r','t',''};
  41. MPI_Publish_name(publish_name, MPI_INFO_NULL, port_name);
  42. std::cout << "Port: " << publish_name << " (" << port_name << ")" << std::endl;
  43. MPI_Comm client;
  44. std::cout << "Wating for Comm..." << std::endl;
  45. MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client);
  46. std::cout << "Comm accepted" << std::endl;
  47. MPI_Comm_free(&client);
  48. MPI_Unpublish_name(publish_name, MPI_INFO_NULL, port_name);
  49. MPI_Close_port(port_name);
  50. MPI_Finalize();
  51. return 1;
  52.  
  53. }
  54.  
  55. mpic++ mpi_src.cc -o mpi_srv.x
  56. mpirun mpi_srv.x
  57.  
  58. #include <iostream>
  59. #include <mpi.h>
  60.  
  61. int main (void)
  62. {
  63.  
  64. int rank(0);
  65. MPI_Init(0, NULL);
  66. MPI_Comm_size(MPI_COMM_WORLD, &rank);
  67. std::cout << "Rank: " << rank << std::endl;
  68. char port_name[MPI_MAX_PORT_NAME];
  69. char publish_name[1024] = {'t','e','s','t','_','p','o','r','t',''};
  70. MPI_Lookup_name(publish_name, MPI_INFO_NULL, port_name);
  71. MPI_Comm client;
  72. MPI_Comm_connect(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client);
  73. MPI_Comm_disconnect(&client);
  74. MPI_Finalize();
  75. return 1;
  76.  
  77. }
  78.  
  79. #include <iostream>
  80. #include <mpi.h>
  81.  
  82. int main (void)
  83. {
  84.  
  85. int rank(0);
  86. MPI_Init(0, NULL);
  87. MPI_Comm_size(MPI_COMM_WORLD, &rank);
  88. std::cout << "Rank: " << rank << std::endl;
  89. char port_name[MPI_MAX_PORT_NAME];
  90. char publish_name[1024] = {'t','e','s','t','_','p','o','r','t',''};
  91. MPI_Lookup_name(publish_name, MPI_INFO_NULL, port_name);
  92. MPI_Comm client;
  93. MPI_Comm_connect(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client);
  94. MPI_Comm_disconnect(&client);
  95. MPI_Finalize();
  96. return 1;
  97.  
  98. }
  99.  
  100. mpic++ mpi_client.cc -o mpi_client.x
  101. mpirun mpi_client.x
  102.  
  103. $ mpirun mpi_server.x
  104. ...
  105.  
  106. $ mpirun mpi_server.x
  107. ...
  108.  
  109. $ mpirun mpi_client.x
  110. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement