[1381] | 1 | /*! |
---|
| 2 | \file ep_test.cpp |
---|
| 3 | \since 2 may 2016 |
---|
| 4 | |
---|
| 5 | \brief Definitions of MPI test function: MPI_Test, MPI_Testsome, MPI_Testany, MPI_Testall |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "ep_lib.hpp" |
---|
| 9 | #include <mpi.h> |
---|
| 10 | #include "ep_declaration.hpp" |
---|
[1522] | 11 | #include "ep_mpi.hpp" |
---|
[1381] | 12 | |
---|
| 13 | using namespace std; |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | namespace ep_lib { |
---|
| 17 | |
---|
| 18 | int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status) |
---|
| 19 | { |
---|
| 20 | Debug("MPI_Test with EP"); |
---|
| 21 | |
---|
[1522] | 22 | if(*request==0) return *flag=true; |
---|
| 23 | |
---|
| 24 | if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) |
---|
[1381] | 25 | { |
---|
[1522] | 26 | printf("MPI_Test : Error in request type\n"); |
---|
| 27 | |
---|
| 28 | exit(1); |
---|
[1381] | 29 | } |
---|
| 30 | |
---|
[1500] | 31 | if((*request)->type == 2) // irecv message not probed |
---|
[1381] | 32 | { |
---|
[1522] | 33 | *flag = false; |
---|
| 34 | return Request_Check(); |
---|
[1381] | 35 | } |
---|
[1522] | 36 | |
---|
| 37 | else //(*request)->type == 1 || (*request)->type == 3 // isend or imrecv |
---|
[1381] | 38 | { |
---|
[1522] | 39 | |
---|
[1381] | 40 | ::MPI_Status mpi_status; |
---|
| 41 | |
---|
| 42 | |
---|
[1522] | 43 | ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status); |
---|
[1381] | 44 | |
---|
[1522] | 45 | if(*flag) |
---|
[1381] | 46 | { |
---|
[1522] | 47 | |
---|
| 48 | status->mpi_status=new ::MPI_Status(mpi_status); |
---|
[1500] | 49 | status->ep_src = (*request)->ep_src; |
---|
| 50 | status->ep_tag = (*request)->ep_tag; |
---|
| 51 | status->ep_datatype = (*request)->ep_datatype; |
---|
[1522] | 52 | |
---|
| 53 | (*request)->state = 2; |
---|
| 54 | |
---|
| 55 | memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request"); |
---|
[1520] | 56 | delete (*request)->mpi_request; |
---|
[1522] | 57 | delete *request; |
---|
| 58 | *request=0; |
---|
| 59 | } |
---|
[1381] | 60 | } |
---|
[1522] | 61 | |
---|
| 62 | return Request_Check(); |
---|
[1381] | 63 | |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | int MPI_Testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses) |
---|
| 68 | { |
---|
| 69 | Debug("MPI_Testall with EP"); |
---|
[1522] | 70 | *flag = false; |
---|
| 71 | |
---|
| 72 | int rank = array_of_requests[0]->comm->ep_comm_ptr->size_rank_info[0].first; |
---|
| 73 | |
---|
| 74 | for(int i=0; i<count; i++) |
---|
| 75 | { |
---|
| 76 | if(array_of_requests[i]->type == 2) |
---|
| 77 | { |
---|
| 78 | *flag=false; |
---|
| 79 | return Request_Check(); |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
[1520] | 83 | ::MPI_Request* mpi_request = new ::MPI_Request[count]; |
---|
| 84 | ::MPI_Status* mpi_status = new ::MPI_Status[count]; |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | for(int i=0; i<count; i++) |
---|
[1381] | 88 | { |
---|
[1520] | 89 | mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); |
---|
[1381] | 90 | } |
---|
[1500] | 91 | |
---|
[1520] | 92 | ::MPI_Testall(count, mpi_request, flag, mpi_status); |
---|
| 93 | |
---|
[1522] | 94 | if(*flag) |
---|
[1520] | 95 | { |
---|
| 96 | for(int i=0; i<count; i++) |
---|
| 97 | { |
---|
[1522] | 98 | array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]); |
---|
[1520] | 99 | array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; |
---|
| 100 | array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; |
---|
| 101 | array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; |
---|
[1522] | 102 | |
---|
| 103 | array_of_requests[i]->state = 2; |
---|
[1520] | 104 | |
---|
[1522] | 105 | memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request"); |
---|
[1520] | 106 | delete array_of_requests[i]->mpi_request; |
---|
[1522] | 107 | delete array_of_requests[i]; |
---|
| 108 | array_of_requests[i]=0; |
---|
| 109 | |
---|
[1520] | 110 | } |
---|
| 111 | |
---|
| 112 | } |
---|
[1522] | 113 | |
---|
| 114 | return Request_Check(); |
---|
[1520] | 115 | |
---|
[1381] | 116 | } |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | } |
---|
[1520] | 120 | |
---|