1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 #include "MPIAccessTest.hxx"
27 #include <cppunit/TestAssert.h>
29 //#include "CommInterface.hxx"
30 //#include "ProcessorGroup.hxx"
31 //#include "MPIProcessorGroup.hxx"
32 #include "MPIAccess.hxx"
34 // use this define to enable lines, execution of which leads to Segmentation Fault
37 // use this define to enable CPPUNIT asserts and fails, showing bugs
38 #define ENABLE_FORCED_FAILURES
41 using namespace MEDCoupling;
43 void MPIAccessTest::test_MPI_Access_ISend_IRecv_Length_1() {
45 // MPI_Init(&argc, &argv) ;
49 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
50 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
53 ostringstream strstream ;
54 strstream << "test_MPI_Access_ISend_IRecv_Length_1 must be run with 2 procs" << endl ;
55 cerr << strstream.str() << endl ;
56 //CPPUNIT_FAIL( strstream.str() ) ;
60 debugStream << "test_MPI_Access_ISend_IRecv_Length_1" << myrank << endl ;
62 MEDCoupling::CommInterface interface ;
64 MEDCoupling::MPIProcessorGroup* group = new MEDCoupling::MPIProcessorGroup(interface) ;
66 MEDCoupling::MPIAccess mpi_access( group ) ;
71 mpi_access.barrier() ;
76 int target = 1 - myrank ;
77 int SendRequestId[maxreq] ;
78 int RecvRequestId[maxreq] ;
80 int sendbuf[1000*(maxreq-1)] ;
81 int recvbuf[maxreq][1000*(maxreq-1)] ;
84 RecvRequestId[0] = -1 ;
85 for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) {
88 for ( i = 0 ; i < maxreq ; i++ ) {
91 sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ;
92 debugStream << "test" << myrank << " ISend RequestId " << SendRequestId[i]
93 << " tag " << mpi_access.sendMPITag(target) << endl ;
96 for (j = 1 ; j <= i ; j++) {
98 MPI_Datatype datatype = 0;
102 mpi_access.test( SendRequestId[j], flag ) ;
106 sts = mpi_access.IProbe( target , source, MPITag, datatype,
108 char msgerr[MPI_MAX_ERROR_STRING] ;
110 mpi_access.errorString(sts, msgerr, &lenerr) ;
111 debugStream << "test" << myrank << " IProbe lenerr " << lenerr << " "
113 if ( sts != MPI_SUCCESS ) {
114 ostringstream strstream ;
115 strstream << "==========================================================="
116 << "test" << myrank << " IProbe KO"
117 << "==========================================================="
119 debugStream << strstream.str() << endl ;
120 CPPUNIT_FAIL( strstream.str() ) ;
122 debugStream << "test" << myrank << " IProbe i/j " << i << "/" << j
123 << " MPITag " << MPITag << " datatype " << datatype
124 << " outcount " << outcount << " flag " << flag << endl ;
129 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
131 debugStream << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
132 << ") : target " << target << " tag " << tag << " error " << error
133 << " flag " << flag << endl ;
136 sts = mpi_access.IRecv( recvbuf[maxirecv], outcount, datatype, source,
137 RecvRequestId[maxirecv] ) ;
138 debugStream << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId "
139 << RecvRequestId[maxirecv] << " source " << source
140 << " outcount " << outcount << " tag "
141 << mpi_access.recvMPITag(target) << endl ;
142 maxirecv = maxirecv + 1 ;
145 else if ( myrank == 1 && i == maxreq-1 && j >= maxirecv ) {
146 sts = mpi_access.IRecv( recvbuf[j], 1000*j, MPI_INT, target,
148 debugStream << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId "
149 << RecvRequestId[j] << " target " << target << " length " << 1000*j
150 << " tag " << mpi_access.recvMPITag(target) << endl ;
151 maxirecv = maxirecv + 1 ;
154 char msgerr[MPI_MAX_ERROR_STRING] ;
156 mpi_access.errorString(sts, msgerr, &lenerr) ;
157 debugStream << "test" << myrank << " lenerr " << lenerr << " "
160 if ( sts != MPI_SUCCESS ) {
161 ostringstream strstream ;
162 strstream << "==========================================================="
163 << endl << "test" << myrank << " KO" << endl
164 << "==========================================================="
166 debugStream << strstream.str() << endl ;
167 CPPUNIT_FAIL( strstream.str() ) ;
171 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
174 mpi_access.testAll( maxreq, SendRequestId, flag ) ;
175 debugStream << "test" << myrank << " TestAll SendRequest flag " << flag << endl ;
180 if ( maxirecv != maxreq ) {
181 ostringstream strstream ;
182 strstream << "==========================================================="
183 << endl << "test" << myrank << " KO" << " maxirecv " << maxirecv
184 << " != maxreq " << maxreq << endl
185 << "==========================================================="
187 debugStream << strstream.str() << endl ;
188 CPPUNIT_FAIL( strstream.str() ) ;
190 while ( maxirecv > 0 ) {
191 for ( i = 1 ; i < maxreq ; i++ ) {
192 debugStream << "test" << myrank << " IProbe : " << endl ;
193 sts = mpi_access.test( RecvRequestId[i] , flag ) ;
194 char msgerr[MPI_MAX_ERROR_STRING] ;
196 mpi_access.errorString(sts, msgerr, &lenerr) ;
197 debugStream << "test" << myrank << " flag " << flag << " lenerr "
198 << lenerr << " " << msgerr << " maxirecv " << maxirecv << endl ;
199 if ( sts != MPI_SUCCESS ) {
200 ostringstream strstream ;
201 strstream << "==========================================================="
202 << "test" << myrank << " KO"
203 << "==========================================================="
205 debugStream << strstream.str() << endl ;
206 CPPUNIT_FAIL( strstream.str() ) ;
208 debugStream << "test" << myrank << " Test flag " << flag << endl ;
211 mpi_access.status( RecvRequestId[i] , source , tag , error ,
214 if (( outcount != 1000*i ) ||
215 ((recvbuf[i][outcount-1] != (outcount-1)))) {
216 ostringstream strstream ;
217 strstream << "========================================================"
218 << endl << "test" << myrank << " outcount " << outcount
219 << " KO" << " i " << i
220 << " recvbuf " << recvbuf[i][outcount-1] << endl
221 << "========================================================"
223 debugStream << strstream.str() << endl ;
224 CPPUNIT_FAIL( strstream.str() ) ;
227 else if ( outcount != 0 ) {
228 ostringstream strstream ;
229 strstream << "========================================================"
230 << endl << "test" << myrank << " outcount " << outcount
231 << " KO" << " i " << i << endl
232 << "========================================================"
234 debugStream << strstream.str() << endl ;
235 CPPUNIT_FAIL( strstream.str() ) ;
237 maxirecv = maxirecv - 1 ;
241 mpi_access.testAll( maxreq, RecvRequestId, flag ) ;
242 debugStream << "test" << myrank << " TestAll RecvRequest flag " << flag << endl ;
244 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
245 debugStream << "test" << myrank << " WaitAll :" << endl ;
247 mpi_access.waitAll( maxreq, SendRequestId ) ;
248 mpi_access.deleteRequests( maxreq, SendRequestId ) ;
251 mpi_access.waitAll( maxreq, RecvRequestId ) ;
252 mpi_access.deleteRequests( maxreq, RecvRequestId ) ;
256 int sendrequests[maxreq] ;
257 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
258 sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
259 if ( sendreqsize != 0 ) {
260 ostringstream strstream ;
261 strstream << "=========================================================" << endl
262 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
263 << "=========================================================" << endl ;
264 debugStream << strstream.str() << endl ;
265 CPPUNIT_FAIL( strstream.str() ) ;
268 debugStream << "=========================================================" << endl
269 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
270 << "=========================================================" << endl ;
274 int recvrequests[maxreq] ;
275 int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
276 if ( recvreqsize != 0 ) {
277 ostringstream strstream ;
278 strstream << "=========================================================" << endl
279 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
280 << "=========================================================" << endl ;
281 debugStream << strstream.str() << endl ;
282 CPPUNIT_FAIL( strstream.str() ) ;
285 debugStream << "=========================================================" << endl
286 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
287 << "=========================================================" << endl ;
291 mpi_access.barrier() ;
297 debugStream << "test" << myrank << " OK" << endl ;