req.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "mpiP.h"
  2. /*
  3. * COMPLETION
  4. */
  5. FC_FUNC( mpi_test , MPI_TEST)(int *request, int *flag, int *status,
  6. int *ierror)
  7. {
  8. *ierror=MPI_Test( (void *)request ,flag,(MPI_Status *)status);
  9. }
  10. int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status)
  11. {
  12. Req *req;
  13. if (*request==MPI_REQUEST_NULL)
  14. {
  15. status->MPI_TAG= MPI_ANY_TAG;
  16. status->MPI_SOURCE= MPI_ANY_SOURCE;
  17. *flag=1;
  18. return(MPI_SUCCESS);
  19. }
  20. req=mpi_handle_to_ptr(*request);
  21. *flag=req->complete;
  22. if (*flag)
  23. {
  24. status->MPI_SOURCE= req->source;
  25. status->MPI_TAG= req->tag;
  26. mpi_free_handle(*request);
  27. *request=MPI_REQUEST_NULL;
  28. }
  29. return(MPI_SUCCESS);
  30. }
  31. FC_FUNC( mpi_wait , MPI_WAIT )(int *request, int *status, int *ierror)
  32. {
  33. *ierror=MPI_Wait( (void *)request, (MPI_Status *)status );
  34. }
  35. int MPI_Wait(MPI_Request *request, MPI_Status *status)
  36. {
  37. int flag;
  38. MPI_Test(request,&flag,status);
  39. if (!flag)
  40. {
  41. fprintf(stderr,"MPI_Wait: request not complete, deadlock\n");
  42. abort();
  43. }
  44. return(MPI_SUCCESS);
  45. }
  46. /*********/
  47. FC_FUNC( mpi_waitany , MPI_WAITANY )(int *count, int *requests,
  48. int *index, int *status, int *ierror)
  49. {
  50. *ierror=MPI_Waitany(*count, (void *)requests,index,(MPI_Status *)status);
  51. }
  52. int MPI_Waitany(int count, MPI_Request *array_of_requests,
  53. int *index, MPI_Status *status)
  54. {
  55. int i;
  56. int flag;
  57. for (i=0; i<count; i++)
  58. {
  59. MPI_Test(&array_of_requests[i],&flag,status);
  60. if (flag)
  61. return(MPI_SUCCESS);
  62. }
  63. /* none are completed */
  64. fprintf(stderr,"MPI_Waitany: no requests complete, deadlock\n");
  65. abort();
  66. }
  67. /*********/
  68. FC_FUNC( mpi_waitall , MPI_WAITALL )(int *count, int *array_of_requests,
  69. int *array_of_statuses, int *ierror)
  70. {
  71. *ierror=MPI_Waitall(*count, (void *)array_of_requests,
  72. (MPI_Status *)array_of_statuses);
  73. }
  74. int MPI_Waitall(int count, MPI_Request *array_of_requests,
  75. MPI_Status *array_of_statuses)
  76. {
  77. int i;
  78. int flag;
  79. for (i=0; i<count; i++)
  80. {
  81. MPI_Test(&array_of_requests[i],&flag,&array_of_statuses[i]);
  82. if (!flag)
  83. {
  84. fprintf(stderr,"MPI_Waitall: request not complete, deadlock\n");
  85. abort();
  86. }
  87. }
  88. return(MPI_SUCCESS);
  89. }
  90. /*********/
  91. MPI_Request MPI_Request_f2c(MPI_Fint request)
  92. {
  93. return(request);
  94. }
  95. /*********/
  96. MPI_Fint MPI_Request_c2f(MPI_Request request)
  97. {
  98. return(request);
  99. }