1 // Copyright (C) 2007-2013 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.
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 ParaMEDMEM;
48 void MPIAccessTest::test_MPI_Access_Cancel() {
50 cout << "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 runned with 2 procs" << endl ;
62 cout << strstream.str() << endl ;
63 CPPUNIT_FAIL( strstream.str() ) ;
66 cout << "test_MPI_Access_Cancel" << myrank << endl ;
68 ParaMEDMEM::CommInterface interface ;
70 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
72 ParaMEDMEM::MPIAccess mpi_access( group ) ;
75 mpi_access.barrier() ;
80 int target = 1 - myrank ;
82 double doublesendbuf[10] ;
86 for ( j = 0 ; j < 3 ; j++ ) {
87 for ( i = 0 ; i < 10 ; i++ ) {
88 cout << "test" << myrank << " ============================ i " << i
89 << "============================" << endl ;
93 sts = mpi_access.ISend(&intsendbuf[i],1,MPI_INT,target, RequestId[i]) ;
94 cout << "test" << myrank << " Send MPI_INT RequestId " << RequestId[i]
98 doublesendbuf[i] = i ;
99 sts = mpi_access.ISend(&doublesendbuf[i],1,MPI_DOUBLE,target,
101 cout << "test" << myrank << " Send MPI_DOUBLE RequestId " << RequestId[i]
108 int source, tag, outcount ;
109 MPI_Datatype datatype ;
110 sts = mpi_access.IProbe(target, source, tag, datatype, outcount,
113 cout << "test" << myrank << " " << i << " IProbe target " << target
114 << " source " << source << " tag " << tag
115 << " outcount " << outcount << " flag " << flag << endl ;
118 cout << "test" << myrank << " flag " << flag << endl ;
123 sts = mpi_access.IRecv(&recvbuf,outcount,MPI_INT,source,
125 if ( datatype == MPI_INT ) {
126 int source, tag, error, outcount ;
127 mpi_access.wait( RequestId[i] ) ;
128 mpi_access.status( RequestId[i], source, tag, error, outcount,
130 if ( (outcount != 1) | (recvbuf != i) ) {
131 ostringstream strstream ;
132 strstream << "======================================================"
133 << endl << "test" << myrank << " outcount " << outcount
134 << " recvbuf " << recvbuf << " KO" << endl
135 << "======================================================"
137 cout << strstream.str() << endl ;
138 CPPUNIT_FAIL( strstream.str() ) ;
140 cout << "========================================================"
141 << endl << "test" << myrank << " outcount " << outcount
142 << " recvbuf " << recvbuf << " OK" << endl
143 << "========================================================"
149 char msgerr[MPI_MAX_ERROR_STRING] ;
151 mpi_access.errorString(sts, msgerr, &lenerr) ;
152 cout << "test" << myrank << " lenerr " << lenerr << " "
154 if ( sts != MPI_SUCCESS ) {
155 ostringstream strstream ;
156 strstream << "==========================================================="
157 << endl << "test" << myrank << " KO"
158 << "==========================================================="
160 cout << strstream.str() << endl ;
161 CPPUNIT_FAIL( strstream.str() ) ;
168 for ( iprobe = 5 ; iprobe < 10 ; iprobe++ ) {
169 cout << "test" << myrank << " ============================ iprobe "
170 << iprobe << "============================" << endl ;
171 int source, tag, outcount ;
172 MPI_Datatype datatype ;
173 int probeflag = false ;
174 while ( !probeflag ) {
175 sts = mpi_access.IProbe( target, source, tag, datatype, outcount,
177 char msgerr[MPI_MAX_ERROR_STRING] ;
179 mpi_access.errorString(sts, msgerr, &lenerr) ;
180 cout << "test" << myrank << " IProbe iprobe " << iprobe
181 << " target " << target << " probeflag " << probeflag
182 << " tag " << tag << " outcount " << outcount << " datatype "
183 << datatype << " lenerr " << lenerr << " " << msgerr << endl ;
184 if ( sts != MPI_SUCCESS ) {
185 ostringstream strstream ;
186 strstream << "=========================================================="
187 << endl << "test" << myrank << " IProbe KO iprobe " << iprobe
189 << "=========================================================="
191 cout << strstream.str() << endl ;
192 CPPUNIT_FAIL( strstream.str() ) ;
195 //cout << "========================================================"
196 // << endl << "test" << myrank << " IProbe KO(OK) iprobe " << iprobe
197 // << " probeflag " << probeflag << endl
198 // << "========================================================"
202 cout << "test" << myrank << " " << iprobe << " IProbe target "
203 << target << " source " << source << " tag " << tag
204 << " outcount " << outcount << " probeflag " << probeflag
206 if ( datatype != MPI_DOUBLE ) {
207 ostringstream strstream ;
208 strstream << "========================================================"
209 << endl << "test" << myrank << " MPI_DOUBLE KO" << endl
210 << "========================================================"
212 cout << strstream.str() << endl ;
213 CPPUNIT_FAIL( strstream.str() ) ;
217 sts = mpi_access.cancel( source, tag, datatype, outcount, flag ) ;
218 if ( sts != MPI_SUCCESS || !flag ) {
219 mpi_access.errorString(sts, msgerr, &lenerr) ;
220 cout << "======================================================"
221 << endl << "test" << myrank << " lenerr " << lenerr << " "
222 << msgerr << endl << "test" << myrank
223 << " Cancel PendingIrecv KO flag " << flag << " iprobe "
224 << iprobe << " Irecv completed" << endl
225 << "======================================================"
230 cout << "======================================================"
231 << endl << "test" << myrank
232 << " Cancel PendingIrecv OK RequestId " << " flag "
233 << flag << " iprobe " << iprobe << endl
234 << "======================================================"
238 int Reqtarget, Reqtag, Reqerror, Reqoutcount ;
239 mpi_access.status( RequestId[iprobe], Reqtarget, Reqtag, Reqerror,
240 Reqoutcount, true ) ;
241 cout << "test" << myrank << " Status Reqtarget "<< Reqtarget
242 << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount
245 sts = mpi_access.cancel( RequestId[iprobe] , Reqflag ) ;
246 cout << "test" << myrank << " " << iprobe
247 << " Cancel Irecv done Reqtarget " << Reqtarget
248 << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount
249 << " Reqflag " << Reqflag << endl ;
250 if ( sts != MPI_SUCCESS || !Reqflag ) {
251 mpi_access.errorString(sts, msgerr, &lenerr) ;
252 ostringstream strstream ;
253 strstream << "========================================================"
254 << endl << "test" << myrank << " lenerr " << lenerr << " "
255 << msgerr << endl << "test" << myrank
256 << " Cancel Irecv KO Reqflag " << Reqflag << " iprobe "
258 << "========================================================"
260 cout << strstream.str() << endl ;
261 CPPUNIT_FAIL( strstream.str() ) ;
264 cout << "========================================================"
265 << endl << "test" << myrank
266 << " Cancel Irecv OK RequestId " << RequestId[iprobe]
267 << " Reqflag " << Reqflag << " iprobe " << iprobe << endl
268 << "========================================================"
270 probeflag = Reqflag ;
276 mpi_access.waitAll(10,RequestId) ;
277 mpi_access.deleteRequests(10,RequestId) ;
280 int source, tag, outcount, flag ;
281 MPI_Datatype datatype ;
282 sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ;
283 char msgerr[MPI_MAX_ERROR_STRING] ;
285 mpi_access.errorString(sts, msgerr, &lenerr) ;
286 cout << "test" << myrank << " lenerr " << lenerr << " "
288 if ( sts != MPI_SUCCESS || flag ) {
289 ostringstream strstream ;
290 strstream << "==========================================================="
291 << endl << "test" << myrank << " IProbe KO flag " << flag
292 << " remaining unread/cancelled message :" << endl
293 << " source " << source << " tag " << tag << endl
294 << "==========================================================="
296 cout << strstream.str() << endl ;
297 CPPUNIT_FAIL( strstream.str() ) ;
300 mpi_access.testAll(10,RequestId,flag) ;
301 mpi_access.waitAll(10,RequestId) ;
302 mpi_access.deleteRequests(10,RequestId) ;
303 mpi_access.testAll(10,RequestId,flag) ;
305 ostringstream strstream ;
306 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
307 cout << strstream.str() << endl ;
308 CPPUNIT_FAIL( strstream.str() ) ;
312 mpi_access.barrier() ;
318 cout << "test" << myrank << " OK" << endl ;