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 | |
---|
12 | using namespace std; |
---|
13 | |
---|
14 | namespace ep_lib |
---|
15 | { |
---|
16 | |
---|
17 | int Message_Check(MPI_Comm comm) |
---|
18 | { |
---|
19 | int myRank; |
---|
20 | MPI_Comm_rank(comm, &myRank); |
---|
21 | |
---|
22 | //printf("myRank = %d, comm.is_ep = %d, comm.is_intercomm = %d\n", myRank, comm.is_ep, comm.is_intercomm); |
---|
23 | if(!comm.is_ep) return 0; |
---|
24 | |
---|
25 | if(comm.is_intercomm) |
---|
26 | { |
---|
27 | return Message_Check_intercomm(comm); |
---|
28 | } |
---|
29 | |
---|
30 | int flag = true; |
---|
31 | ::MPI_Message message; |
---|
32 | ::MPI_Status status; |
---|
33 | int mpi_source; |
---|
34 | |
---|
35 | while(flag) // loop until the end of global queue |
---|
36 | { |
---|
37 | Debug("Message probing for intracomm\n"); |
---|
38 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm); |
---|
39 | #ifdef _openmpi |
---|
40 | #pragma omp critical (_mpi_call) |
---|
41 | { |
---|
42 | ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, mpi_comm, &flag, &status); |
---|
43 | if(flag) |
---|
44 | { |
---|
45 | Debug("find message in mpi comm \n"); |
---|
46 | mpi_source = status.MPI_SOURCE; |
---|
47 | int tag = status.MPI_TAG; |
---|
48 | ::MPI_Mprobe(mpi_source, tag, mpi_comm, &message, &status); |
---|
49 | |
---|
50 | } |
---|
51 | } |
---|
52 | #elif _intelmpi |
---|
53 | //::MPI_Improbe(MPI_ANY_SOURCE, MPI_ANY_TAG, mpi_comm, &flag, &message, &status); |
---|
54 | ::MPI_Improbe(-2, -1, mpi_comm, &flag, &message, &status); |
---|
55 | //printf("myRank = %d, ::MPI_Improbe flag = %d\n", myRank, flag); |
---|
56 | #endif |
---|
57 | |
---|
58 | if(flag) |
---|
59 | { |
---|
60 | |
---|
61 | MPI_Message *msg_block = new MPI_Message; //printf("myRank = %d, new ok\n", myRank); |
---|
62 | msg_block->mpi_message = message; //printf("myRank = %d, msg_block->mpi_message = %d\n", myRank, msg_block->mpi_message); |
---|
63 | msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); //printf("myRank = %d, msg_block->ep_tag = %d\n", myRank, msg_block->ep_tag); |
---|
64 | int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); //printf("myRank = %d, src_loc = %d\n", myRank, src_loc); |
---|
65 | int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); //printf("myRank = %d, dest_loc = %d\n", myRank, dest_loc); |
---|
66 | int src_mpi = status.MPI_SOURCE; //printf("myRank = %d, src_mpi = %d\n", myRank, src_mpi); |
---|
67 | |
---|
68 | msg_block->ep_src = get_ep_rank(comm, src_loc, src_mpi); //printf("myRank = %d, msg_block->ep_src = %d\n", myRank, msg_block->ep_src); |
---|
69 | |
---|
70 | //printf("myRank = %d, probed one message, ep_src = %d, ep_dest = %d, tag = %d, message = %d\n", myRank, msg_block->ep_src, msg_block->ep_dest, msg_block->ep_tag, msg_block->mpi_message); |
---|
71 | msg_block->mpi_status = new ::MPI_Status(status); |
---|
72 | |
---|
73 | MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; |
---|
74 | MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc]; |
---|
75 | |
---|
76 | |
---|
77 | #pragma omp critical (_query) |
---|
78 | { |
---|
79 | #pragma omp flush |
---|
80 | ptr_comm_target->ep_comm_ptr->message_queue->push_back(*msg_block); |
---|
81 | // printf("myRank = %d, push_back OK, ep_src = %d, ep_tag = %d, mpi_status = %p (%p)\n", myRank, |
---|
82 | // ptr_comm_target->ep_comm_ptr->message_queue->back().ep_src, |
---|
83 | // ptr_comm_target->ep_comm_ptr->message_queue->back().ep_tag, |
---|
84 | // msg_block->mpi_status, &status); |
---|
85 | |
---|
86 | #pragma omp flush |
---|
87 | } |
---|
88 | |
---|
89 | delete msg_block; |
---|
90 | //printf("myRank = %d, delete msg_block, queue size = %lu\n", myRank, ptr_comm_target->ep_comm_ptr->message_queue->size()); |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | return MPI_SUCCESS; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | int Message_Check_intercomm(MPI_Comm comm) |
---|
102 | { |
---|
103 | if(!comm.ep_comm_ptr->intercomm->mpi_inter_comm) return 0; |
---|
104 | |
---|
105 | Debug("Message probing for intercomm\n"); |
---|
106 | |
---|
107 | int flag = true; |
---|
108 | ::MPI_Message message; |
---|
109 | ::MPI_Status status; |
---|
110 | int mpi_source; |
---|
111 | int current_ep_rank; |
---|
112 | MPI_Comm_rank(comm, ¤t_ep_rank); |
---|
113 | |
---|
114 | while(flag) // loop until the end of global queue "comm.ep_comm_ptr->intercomm->mpi_inter_comm" |
---|
115 | { |
---|
116 | Debug("Message probing for intracomm\n"); |
---|
117 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.ep_comm_ptr->intercomm->mpi_inter_comm); // => mpi_intercomm |
---|
118 | |
---|
119 | #ifdef _openmpi |
---|
120 | #pragma omp critical (_mpi_call) |
---|
121 | { |
---|
122 | ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, mpi_comm, &flag, &status); |
---|
123 | if(flag) |
---|
124 | { |
---|
125 | Debug("find message in mpi comm \n"); |
---|
126 | mpi_source = status.MPI_SOURCE; |
---|
127 | int tag = status.MPI_TAG; |
---|
128 | ::MPI_Mprobe(mpi_source, tag, mpi_comm, &message, &status); |
---|
129 | |
---|
130 | } |
---|
131 | } |
---|
132 | #elif _intelmpi |
---|
133 | //::MPI_Improbe(MPI_ANY_SOURCE, MPI_ANY_TAG, mpi_comm, &flag, &message, &status); |
---|
134 | ::MPI_Improbe(-2, -1, mpi_comm, &flag, &message, &status); |
---|
135 | #endif |
---|
136 | |
---|
137 | if(flag) |
---|
138 | { |
---|
139 | |
---|
140 | MPI_Message *msg_block = new MPI_Message; |
---|
141 | |
---|
142 | msg_block->mpi_message = message; |
---|
143 | msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); |
---|
144 | int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); |
---|
145 | int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); |
---|
146 | int src_mpi = status.MPI_SOURCE; |
---|
147 | int current_inter = comm.ep_comm_ptr->intercomm->local_rank_map->at(current_ep_rank).first; |
---|
148 | |
---|
149 | msg_block->ep_src = get_ep_rank_intercomm(comm, src_loc, src_mpi); |
---|
150 | msg_block->mpi_status = new ::MPI_Status(status); |
---|
151 | |
---|
152 | |
---|
153 | MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; |
---|
154 | MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc]; |
---|
155 | |
---|
156 | |
---|
157 | #pragma omp critical (_query) |
---|
158 | { |
---|
159 | #pragma omp flush |
---|
160 | ptr_comm_target->ep_comm_ptr->message_queue->push_back(*msg_block); |
---|
161 | //printf("probed one message, ep_src = %d, ep_dest = %d, tag = %d, queue = %p, message = %d\n", msg_block->ep_src, msg_block->ep_dest, msg_block->ep_tag, ptr_comm_target->ep_comm_ptr->message_queue, msg_block->mpi_message); |
---|
162 | #pragma omp flush |
---|
163 | } |
---|
164 | |
---|
165 | delete msg_block; |
---|
166 | |
---|
167 | } |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | flag = true; |
---|
172 | while(flag) // loop until the end of global queue "comm.mpi_comm" |
---|
173 | { |
---|
174 | Debug("Message probing for intracomm\n"); |
---|
175 | ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm); |
---|
176 | #ifdef _openmpi |
---|
177 | #pragma omp critical (_mpi_call) |
---|
178 | { |
---|
179 | ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, mpi_comm, &flag, &status); |
---|
180 | if(flag) |
---|
181 | { |
---|
182 | Debug("find message in mpi comm \n"); |
---|
183 | mpi_source = status.MPI_SOURCE; |
---|
184 | int tag = status.MPI_TAG; |
---|
185 | ::MPI_Mprobe(mpi_source, tag, mpi_comm, &message, &status); |
---|
186 | |
---|
187 | } |
---|
188 | } |
---|
189 | #elif _intelmpi |
---|
190 | ::MPI_Improbe(-2, -1, mpi_comm, &flag, &message, &status); |
---|
191 | #endif |
---|
192 | |
---|
193 | if(flag) |
---|
194 | { |
---|
195 | |
---|
196 | MPI_Message *msg_block = new MPI_Message; |
---|
197 | |
---|
198 | msg_block->mpi_message = message; |
---|
199 | msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); |
---|
200 | int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); |
---|
201 | int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); |
---|
202 | int src_mpi = status.MPI_SOURCE; |
---|
203 | int current_inter = comm.ep_comm_ptr->intercomm->local_rank_map->at(current_ep_rank).first; |
---|
204 | |
---|
205 | msg_block->ep_src = get_ep_rank_intercomm(comm, src_loc, src_mpi); |
---|
206 | msg_block->mpi_status = new ::MPI_Status(status); |
---|
207 | |
---|
208 | |
---|
209 | MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; |
---|
210 | MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc]; |
---|
211 | |
---|
212 | |
---|
213 | #pragma omp critical (_query) |
---|
214 | { |
---|
215 | #pragma omp flush |
---|
216 | ptr_comm_target->ep_comm_ptr->message_queue->push_back(*msg_block); |
---|
217 | printf("probed one message, ep_src = %d, tag = %d, mpi_status = %p (%p), message = %d\n", msg_block->ep_src, msg_block->ep_tag, msg_block->mpi_status, &status, msg_block->mpi_message); |
---|
218 | #pragma omp flush |
---|
219 | } |
---|
220 | |
---|
221 | delete msg_block; |
---|
222 | |
---|
223 | } |
---|
224 | |
---|
225 | } |
---|
226 | |
---|
227 | return MPI_SUCCESS; |
---|
228 | } |
---|
229 | |
---|
230 | } |
---|