[1381] | 1 | /*! |
---|
| 2 | \file ep_message.cpp |
---|
| 3 | \since 2 may 2016 |
---|
| 4 | |
---|
| 5 | \brief Definitions of MPI endpoint function: Message_Check |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "ep_lib.hpp" |
---|
| 9 | #include <mpi.h> |
---|
| 10 | #include "ep_declaration.hpp" |
---|
| 11 | #include "ep_mpi.hpp" |
---|
| 12 | |
---|
| 13 | using namespace std; |
---|
| 14 | |
---|
| 15 | extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests; |
---|
| 16 | #pragma omp threadprivate(EP_PendingRequests) |
---|
| 17 | |
---|
| 18 | namespace ep_lib |
---|
| 19 | { |
---|
[1500] | 20 | int Request_Check() |
---|
| 21 | { |
---|
[1503] | 22 | if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >; |
---|
| 23 | |
---|
| 24 | if(EP_PendingRequests->size() == 0) return 0; |
---|
| 25 | |
---|
[1522] | 26 | show_EP_PendingRequests(EP_PendingRequests); |
---|
| 27 | |
---|
[1500] | 28 | MPI_Status status; |
---|
| 29 | MPI_Message *message; |
---|
| 30 | int probed = false; |
---|
| 31 | int recv_count = 0; |
---|
| 32 | std::list<MPI_Request* >::iterator it; |
---|
| 33 | |
---|
[1527] | 34 | show_EP_PendingRequests(EP_PendingRequests); |
---|
[1500] | 35 | |
---|
[1522] | 36 | |
---|
[1500] | 37 | for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++) |
---|
| 38 | { |
---|
[1522] | 39 | if(*(*it) == 0) |
---|
| 40 | { |
---|
| 41 | EP_PendingRequests->erase(it); |
---|
| 42 | |
---|
| 43 | memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size()); |
---|
| 44 | it = EP_PendingRequests->begin(); |
---|
| 45 | continue; |
---|
| 46 | } |
---|
| 47 | |
---|
[1500] | 48 | Message_Check(((*(*it))->comm)); |
---|
| 49 | } |
---|
[1522] | 50 | |
---|
| 51 | |
---|
[1381] | 52 | |
---|
[1500] | 53 | |
---|
| 54 | for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) |
---|
| 55 | { |
---|
[1522] | 56 | if(*(*it) == 0) |
---|
| 57 | { |
---|
| 58 | EP_PendingRequests->erase(it); |
---|
| 59 | |
---|
| 60 | memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size()); |
---|
| 61 | it = EP_PendingRequests->begin(); |
---|
| 62 | continue; |
---|
| 63 | } |
---|
| 64 | |
---|
[1527] | 65 | if((*(*it))->probed == false) |
---|
[1522] | 66 | { |
---|
[1503] | 67 | #pragma omp critical (_query0) |
---|
| 68 | { |
---|
[1532] | 69 | MPI_Iprobe_endpoint((*(*it))->ep_src, (*(*it))->ep_tag, ((*(*it))->comm), &probed, &status); |
---|
[1503] | 70 | if(probed) |
---|
| 71 | { |
---|
| 72 | message = new MPI_Message; |
---|
| 73 | *message = new ep_message; |
---|
[1500] | 74 | |
---|
[1503] | 75 | memcheck("new "<< message <<" : in ep_lib::Request_Check, message = new MPI_Message"); |
---|
| 76 | memcheck("new "<< *message <<" : in ep_lib::Request_Check, *message = new ep_message"); |
---|
[1500] | 77 | |
---|
| 78 | |
---|
[1532] | 79 | MPI_Improbe_endpoint((*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->comm, &probed, message, &status); |
---|
[1503] | 80 | |
---|
| 81 | } |
---|
| 82 | } |
---|
[1500] | 83 | |
---|
| 84 | |
---|
| 85 | if(probed) |
---|
| 86 | { |
---|
[1517] | 87 | MPI_Get_count(&status, (*(*it))->ep_datatype, &recv_count); |
---|
[1500] | 88 | |
---|
| 89 | MPI_Imrecv((*(*it))->buf, recv_count, (*(*it))->ep_datatype, message, *it); |
---|
| 90 | (*(*it))->type = 3; |
---|
[1527] | 91 | (*(*it))->probed = true; |
---|
[1500] | 92 | |
---|
[1503] | 93 | memcheck("delete "<< status.mpi_status <<" : in ep_lib::Request_Check, delete status.mpi_status"); |
---|
| 94 | delete status.mpi_status; |
---|
[1500] | 95 | |
---|
[1503] | 96 | memcheck("delete "<< *message <<" : in ep_lib::Request_Check, delete *message"); |
---|
| 97 | memcheck("delete "<< message <<" : in ep_lib::Request_Check, delete message"); |
---|
| 98 | |
---|
[1500] | 99 | delete *message; |
---|
| 100 | delete message; |
---|
| 101 | |
---|
| 102 | it++; |
---|
| 103 | continue; |
---|
[1503] | 104 | } |
---|
[1500] | 105 | } |
---|
| 106 | |
---|
[1522] | 107 | it++; |
---|
[1500] | 108 | } |
---|
[1522] | 109 | |
---|
| 110 | show_EP_PendingRequests(EP_PendingRequests); |
---|
[1500] | 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
[1381] | 115 | int Message_Check(MPI_Comm comm) |
---|
| 116 | { |
---|
[1527] | 117 | if(comm->is_ep) return Message_Check_endpoint(comm); |
---|
[1500] | 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
[1527] | 121 | int Message_Check_endpoint(MPI_Comm comm) |
---|
[1500] | 122 | { |
---|
| 123 | |
---|
[1381] | 124 | int flag = true; |
---|
[1500] | 125 | ::MPI_Status status; |
---|
[1381] | 126 | ::MPI_Message message; |
---|
| 127 | |
---|
| 128 | while(flag) // loop until the end of global queue |
---|
| 129 | { |
---|
| 130 | Debug("Message probing for intracomm\n"); |
---|
[1500] | 131 | |
---|
[1381] | 132 | #pragma omp critical (_mpi_call) |
---|
| 133 | { |
---|
[1500] | 134 | ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->mpi_comm), &flag, &status); |
---|
[1381] | 135 | if(flag) |
---|
| 136 | { |
---|
| 137 | Debug("find message in mpi comm \n"); |
---|
[1500] | 138 | ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->mpi_comm), &message, &status); |
---|
[1381] | 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | if(flag) |
---|
| 144 | { |
---|
[1500] | 145 | MPI_Message msg = new ep_message; |
---|
| 146 | msg->mpi_message = new ::MPI_Message(message); |
---|
[1381] | 147 | |
---|
[1503] | 148 | memcheck("new "<< msg <<" : in ep_lib::Message_Check, msg = new ep_message"); |
---|
| 149 | memcheck("new "<< msg->mpi_message <<" : in ep_lib::Message_Check, msg->mpi_message = new ::MPI_Message"); |
---|
[1500] | 150 | |
---|
| 151 | |
---|
| 152 | msg->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); |
---|
| 153 | int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); |
---|
| 154 | int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); |
---|
| 155 | int src_mpi = status.MPI_SOURCE; |
---|
[1381] | 156 | |
---|
[1515] | 157 | msg->ep_src = get_ep_rank(comm, src_loc, src_mpi); |
---|
| 158 | |
---|
| 159 | #ifdef _showinfo |
---|
| 160 | printf("status.MPI_TAG = %d, src_loc = %d, dest_loc = %d, ep_tag = %d\n", status.MPI_TAG, src_loc, dest_loc, msg->ep_tag); |
---|
| 161 | #endif |
---|
| 162 | |
---|
[1500] | 163 | msg->mpi_status = new ::MPI_Status(status); |
---|
[1503] | 164 | memcheck("new "<< msg->mpi_status <<" : in ep_lib::Message_Check, msg->mpi_status = new ::MPI_Status"); |
---|
[1381] | 165 | |
---|
| 166 | #pragma omp critical (_query) |
---|
| 167 | { |
---|
| 168 | #pragma omp flush |
---|
[1500] | 169 | comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->push_back(msg); |
---|
[1503] | 170 | int dest_mpi = comm->ep_comm_ptr->size_rank_info[2].first; |
---|
| 171 | memcheck("message_queue["<<dest_mpi<<","<<dest_loc<<"]->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size()); |
---|
[1381] | 172 | #pragma omp flush |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | return MPI_SUCCESS; |
---|
| 178 | } |
---|
| 179 | |
---|
[1522] | 180 | |
---|
| 181 | void show_EP_PendingRequests(std::list< ep_lib::MPI_Request* > * EP_PendingRequest) |
---|
| 182 | { |
---|
| 183 | #ifdef _showinfo |
---|
| 184 | std::list<MPI_Request* >::iterator it; |
---|
| 185 | |
---|
| 186 | int i=0; |
---|
| 187 | |
---|
| 188 | for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++) |
---|
| 189 | { |
---|
| 190 | if(*(*it) == 0) |
---|
| 191 | { |
---|
| 192 | EP_PendingRequests->erase(it); |
---|
| 193 | |
---|
| 194 | memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size()); |
---|
| 195 | it = EP_PendingRequests->begin(); |
---|
| 196 | continue; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | if((*(*it))->ep_src>6) |
---|
| 200 | printf("EP_PendingRequests[%d] : ep_src = %d, ep_tag = %d, type = %d, state = %d, comm = %d\n", i, (*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->type, (*(*it))->state, to_mpi_comm(((*(*it))->comm)->mpi_comm)); |
---|
| 201 | i++; |
---|
| 202 | } |
---|
| 203 | #endif |
---|
[1381] | 204 | |
---|
[1522] | 205 | } |
---|
| 206 | |
---|
[1500] | 207 | |
---|
[1381] | 208 | |
---|
| 209 | } |
---|
[1532] | 210 | |
---|