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_Cyclic_ISend_IRecv() {
45 debugStream << "test_MPI_Access_Cyclic_ISend_IRecv" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 cerr << "test_MPI_Access_Cyclic_ISend_IRecv must be run with 3 procs" << endl ;
56 //CPPUNIT_FAIL("test_MPI_Access_Cyclic_ISend_IRecv must be run with 3 procs") ;
60 debugStream << "test_MPI_Access_Cyclic_ISend_IRecv" << 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 alltarget[3] = {1 , 2 , 0 } ;
77 int allsource[3] = {2 , 0 , 1 } ;
78 int SendRequestId[maxsend] ;
79 int RecvRequestId[maxsend] ;
80 int sendbuf[maxsend] ;
81 int recvbuf[maxsend] ;
86 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank],
88 debugStream << "test" << myrank << " Send RequestId " << SendRequestId[i]
89 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
91 for ( i = 0 ; i < maxsend ; i++ ) {
93 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,allsource[myrank],
95 debugStream << "test" << myrank << " Recv RequestId " << RecvRequestId[i]
96 << " tag " << mpi_access.recvMPITag(allsource[myrank]) << endl ;
97 char msgerr[MPI_MAX_ERROR_STRING] ;
99 mpi_access.errorString(sts, msgerr, &lenerr) ;
100 debugStream << "test" << myrank << " lenerr " << lenerr
101 << " " << msgerr << endl ;
103 if ( sts != MPI_SUCCESS ) {
104 ostringstream strstream ;
105 strstream << "==========================================================="
106 << "test" << myrank << " KO"
107 << "==========================================================="
109 debugStream << strstream.str() << endl ;
110 CPPUNIT_FAIL( strstream.str() ) ;
113 for (j = 0 ; j <= i ; j++) {
116 debugStream << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j]
118 mpi_access.test( SendRequestId[j], flag ) ;
120 int target, tag, error, outcount ;
121 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
123 debugStream << "test" << myrank << " Send RequestId " << SendRequestId[j]
124 << " target " << target << " tag " << tag << " error " << error
126 mpi_access.deleteRequest( SendRequestId[j] ) ;
129 debugStream << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j]
131 mpi_access.test( RecvRequestId[j], flag ) ;
133 int source, tag, error, outcount ;
134 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
136 debugStream << "test" << myrank << " Recv RequestId" << j << " "
137 << RecvRequestId[j] << " source " << source << " tag " << tag
138 << " error " << error << " outcount " << outcount << endl ;
139 if ( (outcount != 1) | (recvbuf[j] != j) ) {
140 ostringstream strstream ;
141 strstream << "====================================================="
142 << endl << "test" << myrank << " outcount "
143 << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO"
144 << endl << "====================================================="
146 debugStream << strstream.str() << endl ;
147 CPPUNIT_FAIL( strstream.str() ) ;
152 if ( i != maxsend-1 ) {
153 sendbuf[i+1] = i + 1 ;
154 sts = mpi_access.ISend(&sendbuf[i+1],1,MPI_INT,alltarget[myrank],
155 SendRequestId[i+1]) ;
156 debugStream << "test" << myrank << " Send RequestId " << SendRequestId[i+1]
157 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
162 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank],
164 debugStream << "test" << myrank << " Send RequestId " << SendRequestId[i]
165 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
167 mpi_access.errorString(sts, msgerr, &lenerr) ;
168 debugStream << "test" << myrank << " lenerr " << lenerr
169 << " " << msgerr << endl ;
171 if ( sts != MPI_SUCCESS ) {
172 ostringstream strstream ;
173 strstream << "==========================================================="
174 << "test" << myrank << " KO"
175 << "==========================================================="
177 debugStream << strstream.str() << endl ;
178 CPPUNIT_FAIL( strstream.str() ) ;
180 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
184 mpi_access.testAll(maxsend,SendRequestId,flag) ;
185 mpi_access.testAll(maxsend,RecvRequestId,flag) ;
186 mpi_access.waitAll(maxsend,SendRequestId) ;
187 mpi_access.deleteRequests(maxsend,SendRequestId) ;
188 mpi_access.waitAll(maxsend,RecvRequestId) ;
189 mpi_access.deleteRequests(maxsend,RecvRequestId) ;
190 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
191 mpi_access.testAll(maxsend,SendRequestId,flag) ;
193 ostringstream strstream ;
194 strstream << "=========================================================" << endl
195 << "test" << myrank << " TestAllSendflag " << flag << " KO" << endl
196 << "=========================================================" << endl ;
197 debugStream << strstream.str() << endl ;
198 CPPUNIT_FAIL( strstream.str() ) ;
201 debugStream << "=========================================================" << endl
202 << "test" << myrank << " TestAllSendflag " << flag << " OK" << endl
203 << "=========================================================" << endl ;
205 mpi_access.testAll(maxsend,RecvRequestId,flag) ;
207 ostringstream strstream ;
208 strstream << "=========================================================" << endl
209 << "test" << myrank << " TestAllRecvflag " << flag << " KO" << endl
210 << "=========================================================" << endl ;
211 debugStream << strstream.str() << endl ;
212 CPPUNIT_FAIL( strstream.str() ) ;
215 debugStream << "=========================================================" << endl
216 << "test" << myrank << " TestAllRecvflag " << flag << " OK" << endl
217 << "=========================================================" << endl ;
220 int sendrequests[maxsend] ;
221 int sendreqsize = mpi_access.sendRequestIds( alltarget[myrank] , maxsend ,
223 if ( sendreqsize != 0 ) {
224 ostringstream strstream ;
225 strstream << "=========================================================" << endl
226 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
227 << "=========================================================" << endl ;
228 debugStream << strstream.str() << endl ;
229 int source, tag, error, outcount ;
230 mpi_access.status(sendrequests[0], source, tag, error, outcount, true) ;
231 debugStream << "test" << myrank << " RequestId " << sendrequests[0]
232 << " source " << source << " tag " << tag << " error " << error
233 << " outcount " << outcount << endl ;
234 CPPUNIT_FAIL( strstream.str() ) ;
237 debugStream << "=========================================================" << endl
238 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
239 << "=========================================================" << endl ;
241 int recvrequests[maxsend] ;
242 int recvreqsize = mpi_access.sendRequestIds( allsource[myrank] , maxsend ,
244 if ( recvreqsize != 0 ) {
245 ostringstream strstream ;
246 strstream << "=========================================================" << endl
247 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
248 << "=========================================================" << endl ;
249 debugStream << strstream.str() << endl ;
250 CPPUNIT_FAIL( strstream.str() ) ;
253 debugStream << "=========================================================" << endl
254 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
255 << "=========================================================" << endl ;
258 mpi_access.barrier() ;
264 debugStream << "test" << myrank << " OK" << endl ;