You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mpi_pingpong.c 1.8 kB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <mpi.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #define MAX_ITER 1000
  6. int main (int argc, char **argv) {
  7. int rc;
  8. int size;
  9. int myrank;
  10. size_t max_send = 1<<22;
  11. char *send_buf = (char*)malloc(sizeof(char)*max_send);
  12. char *recv_buf = (char*)malloc(sizeof(char)*max_send);
  13. size_t send_size;
  14. clock_t start, end;
  15. rc = MPI_Init (&argc, &argv);
  16. if (rc != MPI_SUCCESS) {
  17. fprintf (stderr, "MPI_Init() failed");
  18. return EXIT_FAILURE;
  19. }
  20. rc = MPI_Comm_size (MPI_COMM_WORLD, &size);
  21. if (rc != MPI_SUCCESS) {
  22. fprintf (stderr, "MPI_Comm_size() failed");
  23. goto exit_with_error;
  24. }
  25. if(size!= 2) {
  26. fprintf(stderr, "This process requieres exact two processes\n");
  27. }
  28. rc = MPI_Comm_rank (MPI_COMM_WORLD, &myrank);
  29. if (rc != MPI_SUCCESS) {
  30. fprintf (stderr, "MPI_Comm_rank() failed");
  31. goto exit_with_error;
  32. }
  33. if(myrank==0)
  34. fprintf (stdout, "Size\t Time(ms)\n");
  35. for(send_size=1 ; send_size<= max_send; send_size*=2){
  36. for (int i = 0; i<MAX_ITER+2; i++) {
  37. if(i == 2)
  38. start = clock();
  39. if(myrank == 0){
  40. MPI_Send(send_buf, send_size, MPI_CHAR, 1, 0x4, MPI_COMM_WORLD);
  41. MPI_Recv(recv_buf, send_size, MPI_CHAR, 1, 0x5, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  42. }
  43. else {
  44. MPI_Recv(recv_buf, send_size, MPI_CHAR, 0, 0x4, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  45. MPI_Send(send_buf, send_size, MPI_CHAR, 0, 0x5, MPI_COMM_WORLD);
  46. }
  47. }
  48. end= clock();
  49. double time_taken = (double)(end-start)/CLOCKS_PER_SEC;
  50. if(myrank == 0 )
  51. fprintf(stdout, "%ld\t %f\n", send_size, time_taken);
  52. }
  53. MPI_Finalize();
  54. return EXIT_SUCCESS;
  55. exit_with_error:
  56. MPI_Finalize();
  57. return EXIT_FAILURE;
  58. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.