1 // Copyright (C) 2007-2008 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
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 ParaMEDMEM;
43 void MPIAccessTest::test_MPI_Access_Cancel() {
45 cout << "test_MPI_Access_Cancel" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 ostringstream strstream ;
56 strstream << "test_MPI_Access_Cancel must be runned with 2 procs" << endl ;
57 cout << strstream.str() << endl ;
58 CPPUNIT_FAIL( strstream.str() ) ;
61 cout << "test_MPI_Access_Cancel" << myrank << endl ;
63 ParaMEDMEM::CommInterface interface ;
65 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
67 ParaMEDMEM::MPIAccess mpi_access( group ) ;
70 mpi_access.barrier() ;
75 int target = 1 - myrank ;
77 double doublesendbuf[10] ;
81 for ( j = 0 ; j < 3 ; j++ ) {
82 for ( i = 0 ; i < 10 ; i++ ) {
83 cout << "test" << myrank << " ============================ i " << i
84 << "============================" << endl ;
88 sts = mpi_access.ISend(&intsendbuf[i],1,MPI_INT,target, RequestId[i]) ;
89 cout << "test" << myrank << " Send MPI_INT RequestId " << RequestId[i]
93 doublesendbuf[i] = i ;
94 sts = mpi_access.ISend(&doublesendbuf[i],1,MPI_DOUBLE,target,
96 cout << "test" << myrank << " Send MPI_DOUBLE RequestId " << RequestId[i]
103 int source, tag, outcount ;
104 MPI_Datatype datatype ;
105 sts = mpi_access.IProbe(target, source, tag, datatype, outcount,
108 cout << "test" << myrank << " " << i << " IProbe target " << target
109 << " source " << source << " tag " << tag
110 << " outcount " << outcount << " flag " << flag << endl ;
113 cout << "test" << myrank << " flag " << flag << endl ;
118 sts = mpi_access.IRecv(&recvbuf,outcount,MPI_INT,source,
120 if ( datatype == MPI_INT ) {
121 int source, tag, error, outcount ;
122 mpi_access.wait( RequestId[i] ) ;
123 mpi_access.status( RequestId[i], source, tag, error, outcount,
125 if ( (outcount != 1) | (recvbuf != i) ) {
126 ostringstream strstream ;
127 strstream << "======================================================"
128 << endl << "test" << myrank << " outcount " << outcount
129 << " recvbuf " << recvbuf << " KO" << endl
130 << "======================================================"
132 cout << strstream.str() << endl ;
133 CPPUNIT_FAIL( strstream.str() ) ;
135 cout << "========================================================"
136 << endl << "test" << myrank << " outcount " << outcount
137 << " recvbuf " << recvbuf << " OK" << endl
138 << "========================================================"
144 char msgerr[MPI_MAX_ERROR_STRING] ;
146 mpi_access.errorString(sts, msgerr, &lenerr) ;
147 cout << "test" << myrank << " lenerr " << lenerr << " "
149 if ( sts != MPI_SUCCESS ) {
150 ostringstream strstream ;
151 strstream << "==========================================================="
152 << endl << "test" << myrank << " KO"
153 << "==========================================================="
155 cout << strstream.str() << endl ;
156 CPPUNIT_FAIL( strstream.str() ) ;
163 for ( iprobe = 5 ; iprobe < 10 ; iprobe++ ) {
164 cout << "test" << myrank << " ============================ iprobe "
165 << iprobe << "============================" << endl ;
166 int source, tag, outcount ;
167 MPI_Datatype datatype ;
168 int probeflag = false ;
169 while ( !probeflag ) {
170 sts = mpi_access.IProbe( target, source, tag, datatype, outcount,
172 char msgerr[MPI_MAX_ERROR_STRING] ;
174 mpi_access.errorString(sts, msgerr, &lenerr) ;
175 cout << "test" << myrank << " IProbe iprobe " << iprobe
176 << " target " << target << " probeflag " << probeflag
177 << " tag " << tag << " outcount " << outcount << " datatype "
178 << datatype << " lenerr " << lenerr << " " << msgerr << endl ;
179 if ( sts != MPI_SUCCESS ) {
180 ostringstream strstream ;
181 strstream << "=========================================================="
182 << endl << "test" << myrank << " IProbe KO iprobe " << iprobe
184 << "=========================================================="
186 cout << strstream.str() << endl ;
187 CPPUNIT_FAIL( strstream.str() ) ;
190 //cout << "========================================================"
191 // << endl << "test" << myrank << " IProbe KO(OK) iprobe " << iprobe
192 // << " probeflag " << probeflag << endl
193 // << "========================================================"
197 cout << "test" << myrank << " " << iprobe << " IProbe target "
198 << target << " source " << source << " tag " << tag
199 << " outcount " << outcount << " probeflag " << probeflag
201 if ( datatype != MPI_DOUBLE ) {
202 ostringstream strstream ;
203 strstream << "========================================================"
204 << endl << "test" << myrank << " MPI_DOUBLE KO" << endl
205 << "========================================================"
207 cout << strstream.str() << endl ;
208 CPPUNIT_FAIL( strstream.str() ) ;
212 sts = mpi_access.cancel( source, tag, datatype, outcount, flag ) ;
213 if ( sts != MPI_SUCCESS || !flag ) {
214 mpi_access.errorString(sts, msgerr, &lenerr) ;
215 cout << "======================================================"
216 << endl << "test" << myrank << " lenerr " << lenerr << " "
217 << msgerr << endl << "test" << myrank
218 << " Cancel PendingIrecv KO flag " << flag << " iprobe "
219 << iprobe << " Irecv completed" << endl
220 << "======================================================"
225 cout << "======================================================"
226 << endl << "test" << myrank
227 << " Cancel PendingIrecv OK RequestId " << " flag "
228 << flag << " iprobe " << iprobe << endl
229 << "======================================================"
233 int Reqtarget, Reqtag, Reqerror, Reqoutcount ;
234 mpi_access.status( RequestId[iprobe], Reqtarget, Reqtag, Reqerror,
235 Reqoutcount, true ) ;
236 cout << "test" << myrank << " Status Reqtarget "<< Reqtarget
237 << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount
240 sts = mpi_access.cancel( RequestId[iprobe] , Reqflag ) ;
241 cout << "test" << myrank << " " << iprobe
242 << " Cancel Irecv done Reqtarget " << Reqtarget
243 << " Reqtag " << Reqtag << " Reqoutcount " << Reqoutcount
244 << " Reqflag " << Reqflag << endl ;
245 if ( sts != MPI_SUCCESS || !Reqflag ) {
246 mpi_access.errorString(sts, msgerr, &lenerr) ;
247 ostringstream strstream ;
248 strstream << "========================================================"
249 << endl << "test" << myrank << " lenerr " << lenerr << " "
250 << msgerr << endl << "test" << myrank
251 << " Cancel Irecv KO Reqflag " << Reqflag << " iprobe "
253 << "========================================================"
255 cout << strstream.str() << endl ;
256 CPPUNIT_FAIL( strstream.str() ) ;
259 cout << "========================================================"
260 << endl << "test" << myrank
261 << " Cancel Irecv OK RequestId " << RequestId[iprobe]
262 << " Reqflag " << Reqflag << " iprobe " << iprobe << endl
263 << "========================================================"
265 probeflag = Reqflag ;
271 mpi_access.waitAll(10,RequestId) ;
272 mpi_access.deleteRequests(10,RequestId) ;
275 int source, tag, outcount, flag ;
276 MPI_Datatype datatype ;
277 sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ;
278 char msgerr[MPI_MAX_ERROR_STRING] ;
280 mpi_access.errorString(sts, msgerr, &lenerr) ;
281 cout << "test" << myrank << " lenerr " << lenerr << " "
283 if ( sts != MPI_SUCCESS || flag ) {
284 ostringstream strstream ;
285 strstream << "==========================================================="
286 << endl << "test" << myrank << " IProbe KO flag " << flag
287 << " remaining unread/cancelled message :" << endl
288 << " source " << source << " tag " << tag << endl
289 << "==========================================================="
291 cout << strstream.str() << endl ;
292 CPPUNIT_FAIL( strstream.str() ) ;
295 mpi_access.testAll(10,RequestId,flag) ;
296 mpi_access.waitAll(10,RequestId) ;
297 mpi_access.deleteRequests(10,RequestId) ;
298 mpi_access.testAll(10,RequestId,flag) ;
300 ostringstream strstream ;
301 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
302 cout << strstream.str() << endl ;
303 CPPUNIT_FAIL( strstream.str() ) ;
307 mpi_access.barrier() ;
313 cout << "test" << myrank << " OK" << endl ;