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
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_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 runned with 2 procs" << endl ;
55 cout << strstream.str() << endl ;
56 CPPUNIT_FAIL( strstream.str() ) ;
59 cout << "test_MPI_Access_ISend_IRecv_Length_1" << myrank << endl ;
61 ParaMEDMEM::CommInterface interface ;
63 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
65 ParaMEDMEM::MPIAccess mpi_access( group ) ;
70 mpi_access.barrier() ;
75 int target = 1 - myrank ;
76 int SendRequestId[maxreq] ;
77 int RecvRequestId[maxreq] ;
79 int sendbuf[1000*(maxreq-1)] ;
80 int recvbuf[maxreq-1][1000*(maxreq-1)] ;
83 RecvRequestId[0] = -1 ;
84 for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) {
87 for ( i = 0 ; i < maxreq ; i++ ) {
90 sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ;
91 cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
92 << " tag " << mpi_access.sendMPITag(target) << endl ;
95 for (j = 1 ; j <= i ; j++) {
97 MPI_Datatype datatype ;
101 mpi_access.test( SendRequestId[j], flag ) ;
105 sts = mpi_access.IProbe( target , source, MPITag, datatype,
107 char msgerr[MPI_MAX_ERROR_STRING] ;
109 mpi_access.errorString(sts, msgerr, &lenerr) ;
110 cout << "test" << myrank << " IProbe lenerr " << lenerr << " "
112 if ( sts != MPI_SUCCESS ) {
113 ostringstream strstream ;
114 strstream << "==========================================================="
115 << "test" << myrank << " IProbe KO"
116 << "==========================================================="
118 cout << strstream.str() << endl ;
119 CPPUNIT_FAIL( strstream.str() ) ;
121 cout << "test" << myrank << " IProbe i/j " << i << "/" << j
122 << " MPITag " << MPITag << " datatype " << datatype
123 << " outcount " << outcount << " flag " << flag << endl ;
127 int target, tag, error, outcount ;
128 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
130 cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
131 << ") : target " << target << " tag " << tag << " error " << error
132 << " flag " << flag << endl ;
135 sts = mpi_access.IRecv( recvbuf[maxirecv], outcount, datatype, source,
136 RecvRequestId[maxirecv] ) ;
137 cout << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId "
138 << RecvRequestId[maxirecv] << " source " << source
139 << " outcount " << outcount << " tag "
140 << mpi_access.recvMPITag(target) << endl ;
141 maxirecv = maxirecv + 1 ;
144 else if ( myrank == 1 && i == maxreq-1 && j >= maxirecv ) {
145 sts = mpi_access.IRecv( recvbuf[j], 1000*j, MPI_INT, target,
147 cout << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId "
148 << RecvRequestId[j] << " target " << target << " length " << 1000*j
149 << " tag " << mpi_access.recvMPITag(target) << endl ;
150 maxirecv = maxirecv + 1 ;
153 char msgerr[MPI_MAX_ERROR_STRING] ;
155 mpi_access.errorString(sts, msgerr, &lenerr) ;
156 cout << "test" << myrank << " lenerr " << lenerr << " "
159 if ( sts != MPI_SUCCESS ) {
160 ostringstream strstream ;
161 strstream << "==========================================================="
162 << endl << "test" << myrank << " KO" << endl
163 << "==========================================================="
165 cout << strstream.str() << endl ;
166 CPPUNIT_FAIL( strstream.str() ) ;
173 mpi_access.testAll( maxreq, SendRequestId, flag ) ;
174 cout << "test" << myrank << " TestAll SendRequest flag " << flag << endl ;
181 if ( maxirecv != maxreq ) {
182 ostringstream strstream ;
183 strstream << "==========================================================="
184 << endl << "test" << myrank << " KO" << " maxirecv " << maxirecv
185 << " != maxreq " << maxreq << endl
186 << "==========================================================="
188 cout << strstream.str() << endl ;
189 CPPUNIT_FAIL( strstream.str() ) ;
191 while ( maxirecv > 0 ) {
192 for ( i = 1 ; i < maxreq ; i++ ) {
193 cout << "test" << myrank << " IProbe : " << endl ;
194 sts = mpi_access.test( RecvRequestId[i] , flag ) ;
195 char msgerr[MPI_MAX_ERROR_STRING] ;
197 mpi_access.errorString(sts, msgerr, &lenerr) ;
198 cout << "test" << myrank << " flag " << flag << " lenerr "
199 << lenerr << " " << msgerr << " maxirecv " << maxirecv << endl ;
200 if ( sts != MPI_SUCCESS ) {
201 ostringstream strstream ;
202 strstream << "==========================================================="
203 << "test" << myrank << " KO"
204 << "==========================================================="
206 cout << strstream.str() << endl ;
207 CPPUNIT_FAIL( strstream.str() ) ;
209 cout << "test" << myrank << " Test flag " << flag << endl ;
212 mpi_access.status( RecvRequestId[i] , source , tag , error ,
215 if ( outcount != 1000*i |
216 (recvbuf[i][outcount-1] != (outcount-1)) ) {
217 ostringstream strstream ;
218 strstream << "========================================================"
219 << endl << "test" << myrank << " outcount " << outcount
220 << " KO" << " i " << i
221 << " recvbuf " << recvbuf[i][outcount-1] << endl
222 << "========================================================"
224 cout << strstream.str() << endl ;
225 CPPUNIT_FAIL( strstream.str() ) ;
228 else if ( outcount != 0 ) {
229 ostringstream strstream ;
230 strstream << "========================================================"
231 << endl << "test" << myrank << " outcount " << outcount
232 << " KO" << " i " << i << endl
233 << "========================================================"
235 cout << strstream.str() << endl ;
236 CPPUNIT_FAIL( strstream.str() ) ;
238 maxirecv = maxirecv - 1 ;
242 mpi_access.testAll( maxreq, RecvRequestId, flag ) ;
243 cout << "test" << myrank << " TestAll RecvRequest flag " << flag << endl ;
246 cout << "test" << myrank << " WaitAll :" << endl ;
248 mpi_access.waitAll( maxreq, SendRequestId ) ;
249 mpi_access.deleteRequests( maxreq, SendRequestId ) ;
252 mpi_access.waitAll( maxreq, RecvRequestId ) ;
253 mpi_access.deleteRequests( maxreq, RecvRequestId ) ;
257 int sendrequests[maxreq] ;
258 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
259 sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
260 if ( sendreqsize != 0 ) {
261 ostringstream strstream ;
262 strstream << "=========================================================" << endl
263 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
264 << "=========================================================" << endl ;
265 cout << strstream.str() << endl ;
266 CPPUNIT_FAIL( strstream.str() ) ;
269 cout << "=========================================================" << endl
270 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
271 << "=========================================================" << endl ;
275 int recvrequests[maxreq] ;
276 int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
277 if ( recvreqsize != 0 ) {
278 ostringstream strstream ;
279 strstream << "=========================================================" << endl
280 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
281 << "=========================================================" << endl ;
282 cout << strstream.str() << endl ;
283 CPPUNIT_FAIL( strstream.str() ) ;
286 cout << "=========================================================" << endl
287 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
288 << "=========================================================" << endl ;
292 mpi_access.barrier() ;
298 cout << "test" << myrank << " OK" << endl ;