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
31 #include "MPIAccessTest.hxx"
32 #include <cppunit/TestAssert.h>
34 //#include "CommInterface.hxx"
35 //#include "ProcessorGroup.hxx"
36 //#include "MPIProcessorGroup.hxx"
37 #include "MPIAccess.hxx"
39 // use this define to enable lines, execution of which leads to Segmentation Fault
42 // use this define to enable CPPUNIT asserts and fails, showing bugs
43 #define ENABLE_FORCED_FAILURES
46 using namespace MEDCoupling;
48 void MPIAccessTest::test_MPI_Access_Cancel() {
50 debugStream << "test_MPI_Access_Cancel" << endl ;
52 // MPI_Init(&argc, &argv) ;
56 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
57 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
60 ostringstream strstream ;
61 strstream << "test_MPI_Access_Cancel must be run with 2 procs" << endl ;
62 cerr << strstream.str() << endl ;
63 //CPPUNIT_FAIL( strstream.str() ) ;
67 debugStream << "test_MPI_Access_Cancel" << myrank << endl ;
69 MEDCoupling::CommInterface interface ;
71 MEDCoupling::MPIProcessorGroup* group = new MEDCoupling::MPIProcessorGroup(interface) ;
73 MEDCoupling::MPIAccess mpi_access( group ) ;
76 mpi_access.barrier() ;
81 int target = 1 - myrank ;
83 double doublesendbuf[10] ;
87 for ( j = 0 ; j < 3 ; j++ ) {
88 for ( i = 0 ; i < 10 ; i++ ) {
89 debugStream << "test" << myrank << " ============================ i " << i
90 << "============================" << endl ;
94 sts = mpi_access.ISend(&intsendbuf[i],1,MPI_INT,target, RequestId[i]) ;
95 debugStream << "test" << myrank << " Send MPI_INT RequestId " << RequestId[i]
99 doublesendbuf[i] = i ;
100 sts = mpi_access.ISend(&doublesendbuf[i],1,MPI_DOUBLE,target,
102 debugStream << "test" << myrank << " Send MPI_DOUBLE RequestId " << RequestId[i]
109 int source, tag, outcount ;
110 MPI_Datatype datatype ;
111 sts = mpi_access.IProbe(target, source, tag, datatype, outcount,
114 debugStream << "test" << myrank << " " << i << " IProbe target " << target
115 << " source " << source << " tag " << tag
116 << " outcount " << outcount << " flag " << flag << endl ;
119 debugStream << "test" << myrank << " flag " << flag << endl ;
124 sts = mpi_access.IRecv(&recvbuf,outcount,MPI_INT,source,
126 if ( datatype == MPI_INT ) {
128 mpi_access.wait( RequestId[i] ) ;
129 mpi_access.status( RequestId[i], source, tag, error, outcount,
131 if ( (outcount != 1) | (recvbuf != i) ) {
132 ostringstream strstream ;
133 strstream << "======================================================"
134 << endl << "test" << myrank << " outcount " << outcount
135 << " recvbuf " << recvbuf << " KO" << endl
136 << "======================================================"
138 debugStream << strstream.str() << endl ;
139 CPPUNIT_FAIL( strstream.str() ) ;
141 debugStream << "========================================================"
142 << endl << "test" << myrank << " outcount " << outcount
143 << " recvbuf " << recvbuf << " OK" << endl
144 << "========================================================"
150 char msgerr[MPI_MAX_ERROR_STRING] ;
152 mpi_access.errorString(sts, msgerr, &lenerr) ;
153 debugStream << "test" << myrank << " lenerr " << lenerr << " "
155 if ( sts != MPI_SUCCESS ) {
156 ostringstream strstream ;
157 strstream << "==========================================================="
158 << endl << "test" << myrank << " KO"
159 << "==========================================================="
161 debugStream << strstream.str() << endl ;
162 CPPUNIT_FAIL( strstream.str() ) ;
164 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
169 for ( iprobe = 5 ; iprobe < 10 ; iprobe++ ) {
170 debugStream << "test" << myrank << " ============================ iprobe "
171 << iprobe << "============================" << endl ;
172 int source, tag, outcount ;
173 MPI_Datatype datatype ;
174 int probeflag = false ;
175 while ( !probeflag ) {
176 sts = mpi_access.IProbe( target, source, tag, datatype, outcount,
178 char msgerr[MPI_MAX_ERROR_STRING] ;
180 mpi_access.errorString(sts, msgerr, &lenerr) ;
181 debugStream << "test" << myrank << " IProbe iprobe " << iprobe
182 << " target " << target << " probeflag " << probeflag
183 << " tag " << tag << " outcount " << outcount << " datatype "
184 << datatype << " lenerr " << lenerr << " " << msgerr << endl ;
185 if ( sts != MPI_SUCCESS ) {
186 ostringstream strstream ;
187 strstream << "=========================================================="
188 << endl << "test" << myrank << " IProbe KO iprobe " << iprobe
190 << "=========================================================="
192 debugStream << strstream.str() << endl ;
193 CPPUNIT_FAIL( strstream.str() ) ;
196 //debugStream << "========================================================"
197 // << endl << "test" << myrank << " IProbe KO(OK) iprobe " << iprobe
198 // << " probeflag " << probeflag << endl
199 // << "========================================================"
203 debugStream << "test" << myrank << " " << iprobe << " IProbe target "
204 << target << " source " << source << " tag " << tag
205 << " outcount " << outcount << " probeflag " << probeflag
207 if ( datatype != MPI_DOUBLE ) {
208 ostringstream strstream ;
209 strstream << "========================================================"
210 << endl << "test" << myrank << " MPI_DOUBLE KO" << endl
211 << "========================================================"
213 debugStream << strstream.str() << endl ;
214 CPPUNIT_FAIL( strstream.str() ) ;
218 sts = mpi_access.cancel( source, tag, datatype, outcount, flag ) ;
219 if ( sts != MPI_SUCCESS || !flag ) {
220 mpi_access.errorString(sts, msgerr, &lenerr) ;
221 debugStream << "======================================================"
222 << endl << "test" << myrank << " lenerr " << lenerr << " "
223 << msgerr << endl << "test" << myrank
224 << " Cancel PendingIrecv KO flag " << flag << " iprobe "
225 << iprobe << " Irecv completed" << endl
226 << "======================================================"
231 debugStream << "======================================================"
232 << endl << "test" << myrank
233 << " Cancel PendingIrecv OK RequestId " << " flag "
234 << flag << " iprobe " << iprobe << endl
235 << "======================================================"
239 int Reqtarget, Reqtag, Reqerror, Reqoutcount ;
240 mpi_access.status( RequestId[iprobe], Reqtarget, Reqtag, Reqerror,
241 Reqoutcount, true ) ;
242 debugStream << "test" << myrank << " Status Reqtarget "<< Reqtarget
243 << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount
246 sts = mpi_access.cancel( RequestId[iprobe] , Reqflag ) ;
247 debugStream << "test" << myrank << " " << iprobe
248 << " Cancel Irecv done Reqtarget " << Reqtarget
249 << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount
250 << " Reqflag " << Reqflag << endl ;
251 if ( sts != MPI_SUCCESS || !Reqflag ) {
252 mpi_access.errorString(sts, msgerr, &lenerr) ;
253 ostringstream strstream ;
254 strstream << "========================================================"
255 << endl << "test" << myrank << " lenerr " << lenerr << " "
256 << msgerr << endl << "test" << myrank
257 << " Cancel Irecv KO Reqflag " << Reqflag << " iprobe "
259 << "========================================================"
261 debugStream << strstream.str() << endl ;
262 CPPUNIT_FAIL( strstream.str() ) ;
265 debugStream << "========================================================"
266 << endl << "test" << myrank
267 << " Cancel Irecv OK RequestId " << RequestId[iprobe]
268 << " Reqflag " << Reqflag << " iprobe " << iprobe << endl
269 << "========================================================"
271 probeflag = Reqflag ;
277 mpi_access.waitAll(10,RequestId) ;
278 mpi_access.deleteRequests(10,RequestId) ;
281 int source, tag, outcount, flag ;
282 MPI_Datatype datatype ;
283 sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ;
284 char msgerr[MPI_MAX_ERROR_STRING] ;
286 mpi_access.errorString(sts, msgerr, &lenerr) ;
287 debugStream << "test" << myrank << " lenerr " << lenerr << " "
289 if ( sts != MPI_SUCCESS || flag ) {
290 ostringstream strstream ;
291 strstream << "==========================================================="
292 << endl << "test" << myrank << " IProbe KO flag " << flag
293 << " remaining unread/cancelled message :" << endl
294 << " source " << source << " tag " << tag << endl
295 << "==========================================================="
297 debugStream << strstream.str() << endl ;
298 CPPUNIT_FAIL( strstream.str() ) ;
301 mpi_access.testAll(10,RequestId,flag) ;
302 mpi_access.waitAll(10,RequestId) ;
303 mpi_access.deleteRequests(10,RequestId) ;
304 mpi_access.testAll(10,RequestId,flag) ;
306 ostringstream strstream ;
307 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
308 debugStream << strstream.str() << endl ;
309 CPPUNIT_FAIL( strstream.str() ) ;
311 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
313 mpi_access.barrier() ;
319 debugStream << "test" << myrank << " OK" << endl ;