comm.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #include "mpiP.h"
  2. /*
  3. * Communicators
  4. *
  5. */
  6. MPI_Comm mpi_comm_new(void)
  7. {
  8. MPI_Comm chandle;
  9. Comm *cptr;
  10. static int num=0;
  11. mpi_alloc_handle(&chandle,(void **) &cptr);
  12. cptr->sendlist=AP_list_new();
  13. cptr->recvlist=AP_list_new();
  14. cptr->num=num++;
  15. return(chandle);
  16. }
  17. /*********/
  18. FC_FUNC( mpi_comm_free , MPI_COMM_FREE )(int *comm, int *ierror)
  19. {
  20. *ierror=MPI_Comm_free(comm);
  21. }
  22. /*
  23. * MPI_Comm_free()
  24. *
  25. * Note: will NOT free any pending MPI_Request handles
  26. * that are allocated... correct user code should have
  27. * already done a Wait or Test to free them.
  28. *
  29. */
  30. int MPI_Comm_free(MPI_Comm *comm)
  31. {
  32. pList sendlist, recvlist;
  33. int size;
  34. Comm *mycomm;
  35. mycomm=mpi_handle_to_ptr(*comm); /* (Comm *)(*comm) */
  36. sendlist=mycomm->sendlist;
  37. recvlist=mycomm->recvlist;
  38. size=AP_list_size(sendlist);
  39. if (size!=0)
  40. fprintf(stderr,"MPI_Comm_free: warning: %d pending send reqs\n",
  41. size);
  42. AP_list_free(sendlist);
  43. size=AP_list_size(recvlist);
  44. if (size!=0)
  45. fprintf(stderr,"MPI_Comm_free: warning: %d pending receive reqs\n",
  46. size);
  47. AP_list_free(recvlist);
  48. mpi_free_handle(*comm); /* free(mycomm); */
  49. *comm=MPI_COMM_NULL;
  50. return(MPI_SUCCESS);
  51. }
  52. /*********/
  53. FC_FUNC( mpi_comm_size , MPI_COMM_SIZE )(int *comm, int *size, int *ierror)
  54. {
  55. *ierror=MPI_Comm_size(*comm, size);
  56. }
  57. int MPI_Comm_size(MPI_Comm comm, int *size)
  58. {
  59. *size=1;
  60. return(MPI_SUCCESS);
  61. }
  62. /*********/
  63. FC_FUNC( mpi_comm_rank , MPI_COMM_RANK )(int *comm, int *rank, int *ierror)
  64. {
  65. *ierror=MPI_Comm_rank( *comm, rank);
  66. }
  67. int MPI_Comm_rank(MPI_Comm comm, int *rank)
  68. {
  69. *rank=0;
  70. return(MPI_SUCCESS);
  71. }
  72. /*********/
  73. FC_FUNC( mpi_comm_dup , MPI_COMM_DUP )(int *comm, int *newcomm, int *ierror)
  74. {
  75. *ierror=MPI_Comm_dup( *comm, newcomm);
  76. }
  77. int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
  78. {
  79. *newcomm= mpi_comm_new();
  80. #ifdef INFO
  81. fflush(stdout);
  82. fprintf(stderr,"MPI_Comm_dup: new comm handle=%d\n",*newcomm);
  83. #endif
  84. return(MPI_SUCCESS);
  85. }
  86. /*********/
  87. int FC_FUNC( mpi_comm_create, MPI_COMM_CREATE)
  88. (int *comm, int *group, int *newcomm, int *ierror)
  89. {
  90. *ierror=MPI_Comm_create(*comm,*group,newcomm);
  91. }
  92. int MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm *newcomm)
  93. {
  94. if (group==MPI_GROUP_NULL || group==MPI_GROUP_EMPTY)
  95. *newcomm= MPI_COMM_NULL;
  96. else
  97. *newcomm=mpi_comm_new();
  98. return(MPI_SUCCESS);
  99. }
  100. /*********/
  101. FC_FUNC( mpi_comm_split, MPI_COMM_SPLIT )
  102. (int *comm, int *color, int *key, int *newcomm, int *ierror)
  103. {
  104. *ierror=MPI_Comm_split(*comm,*color,*key,newcomm);
  105. }
  106. int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm)
  107. {
  108. if (color==MPI_UNDEFINED)
  109. *newcomm=MPI_COMM_NULL;
  110. else
  111. *newcomm= mpi_comm_new();
  112. return(MPI_SUCCESS);
  113. }
  114. /*********/
  115. FC_FUNC( mpi_comm_group, MPI_COMM_GROUP )
  116. (int *comm, int *group, int *ierror)
  117. {
  118. *ierror= MPI_Comm_group(*comm, group);
  119. }
  120. int MPI_Comm_group(MPI_Comm comm, MPI_Group *group)
  121. {
  122. if (comm==MPI_COMM_NULL)
  123. *group= MPI_GROUP_NULL;
  124. else
  125. *group= MPI_GROUP_ONE;
  126. return(MPI_SUCCESS);
  127. }
  128. /*********/
  129. MPI_Comm MPI_Comm_f2c(MPI_Fint comm)
  130. {
  131. /* Comm is an integer handle used both by C and Fortran */
  132. return(comm);
  133. }
  134. MPI_Fint MPI_Comm_c2f(MPI_Comm comm)
  135. {
  136. return(comm);
  137. }