1 // Copyright (C) 2007-2016 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_Time() {
45 debugStream << "test_MPI_Access_Time" << 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_Time must be run with 2 procs" << endl ;
57 cerr << strstream.str() << endl ;
58 //CPPUNIT_FAIL( strstream.str() ) ;
62 debugStream << "test_MPI_Access_Time" << myrank << endl ;
64 MEDCoupling::CommInterface interface ;
66 MEDCoupling::MPIProcessorGroup* group = new MEDCoupling::MPIProcessorGroup(interface) ;
68 MEDCoupling::MPIAccess mpi_access( group ) ;
73 debugStream << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ;
74 mpi_access.barrier() ;
75 debugStream << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ;
77 debugStream << "test_MPI_Access_Time" << myrank << " OK" << endl ;
81 int target = 1 - myrank ;
82 int SendTimeRequestId[maxreq] ;
83 int RecvTimeRequestId[maxreq] ;
84 int SendRequestId[maxreq] ;
85 int RecvRequestId[maxreq] ;
90 MEDCoupling::TimeMessage aSendTimeMsg[maxreq] ;
91 MEDCoupling::TimeMessage aRecvTimeMsg[maxreq] ;
95 for ( t = 0 ; t < maxt ; t = t+dt ) {
97 aSendTimeMsg[i].time = t ;
98 aSendTimeMsg[i].deltatime = dt ;
99 //aSendTimeMsg[i].maxtime = maxt ;
100 //sts = mpi_access.ISend( &aSendTimeMsg , mpi_access.timeExtent() ,
101 sts = mpi_access.ISend( &aSendTimeMsg[i] , 1 ,
102 mpi_access.timeType() , target ,
103 SendTimeRequestId[i]) ;
104 debugStream << "test" << myrank << " ISend RequestId " << SendTimeRequestId[i]
105 << " tag " << mpi_access.sendMPITag(target) << endl ;
107 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, SendRequestId[i]) ;
108 debugStream << "test" << myrank << " ISend RequestId " << SendRequestId[i]
109 << " tag " << mpi_access.sendMPITag(target) << endl ;
112 //sts = mpi_access.IRecv( &aRecvTimeMsg , mpi_access.timeExtent() ,
113 sts = mpi_access.IRecv( &aRecvTimeMsg[i] , 1 ,
114 mpi_access.timeType() , target ,
115 RecvTimeRequestId[i]) ;
116 debugStream << "test" << myrank << " IRecv RequestId " << RecvTimeRequestId[i]
117 << " tag " << mpi_access.recvMPITag(target) << endl ;
118 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
119 debugStream << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
120 << " tag " << mpi_access.recvMPITag(target) << endl ;
123 for (j = 0 ; j <= i ; j++) {
126 mpi_access.test( SendTimeRequestId[j], flag ) ;
129 mpi_access.test( RecvTimeRequestId[j], flag ) ;
132 int target,source, tag, error, outcount ;
134 mpi_access.status( SendTimeRequestId[j], target, tag, error, outcount,
136 debugStream << "test" << myrank << " Test(Send TimeRequestId " << SendTimeRequestId[j]
137 << ") : target " << target << " tag " << tag << " error " << error
138 << " flag " << flag << aSendTimeMsg[j] << endl ;
141 mpi_access.status( RecvTimeRequestId[j], source, tag, error, outcount,
143 debugStream << "test" << myrank << " Test(Recv TimeRequestId "
144 << RecvTimeRequestId[j] << ") : source " << source << " tag " << tag
145 << " error " << error << " outcount " << outcount
146 << " flag " << flag << aRecvTimeMsg[j] << endl ;
147 if ( (outcount != 1) | (aRecvTimeMsg[j].time != j) ) {
148 ostringstream strstream ;
149 strstream << "==========================================================="
150 << endl << "test" << myrank << " outcount " << outcount << " KO"
151 << " RecvTimeRequestId " << RecvTimeRequestId[j] << endl
152 << "==========================================================="
154 debugStream << strstream.str() << endl ;
155 CPPUNIT_FAIL( strstream.str() ) ;
158 debugStream << "==========================================================="
159 << endl << "test" << myrank << " outcount " << outcount
160 << " RecvTimeRequestId " << RecvTimeRequestId[j] << " OK" << endl
161 << "==========================================================="
167 mpi_access.test( SendRequestId[j], flag ) ;
170 mpi_access.test( RecvRequestId[j], flag ) ;
173 int target,source, tag, error, outcount ;
175 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
177 debugStream << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
178 << ") : target " << target << " tag " << tag << " error " << error
179 << " flag " << flag << endl ;
182 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
184 debugStream << "test" << myrank << " Test(Recv RequestId "
185 << RecvRequestId[j] << ") : source " << source << " tag " << tag
186 << " error " << error << " outcount " << outcount
187 << " flag " << flag << endl ;
188 if ( (outcount != 1) | (recvbuf[j] != j) ) {
189 ostringstream strstream ;
190 strstream << "==========================================================="
191 << endl << "test" << myrank << " outcount "
192 << outcount << " recvbuf " << recvbuf[j] << " KO" << endl
193 << "==========================================================="
195 debugStream << strstream.str() << endl ;
196 CPPUNIT_FAIL( strstream.str() ) ;
199 debugStream << "==========================================================="
200 << endl << "test" << myrank << " outcount " << outcount
201 << " RequestId " << RecvRequestId[j] << " OK" << endl
202 << "==========================================================="
208 char msgerr[MPI_MAX_ERROR_STRING] ;
210 mpi_access.errorString(sts, msgerr, &lenerr) ;
211 debugStream << "test" << myrank << " lenerr " << lenerr << " "
214 if ( sts != MPI_SUCCESS ) {
215 ostringstream strstream ;
216 strstream << "==========================================================="
217 << "test" << myrank << " KO"
218 << "==========================================================="
220 debugStream << strstream.str() << endl ;
221 CPPUNIT_FAIL( strstream.str() ) ;
226 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
228 mpi_access.waitAll(maxreq, SendTimeRequestId) ;
229 mpi_access.deleteRequests(maxreq, SendTimeRequestId) ;
230 mpi_access.waitAll(maxreq, SendRequestId) ;
231 mpi_access.deleteRequests(maxreq, SendRequestId) ;
234 mpi_access.waitAll(maxreq, RecvTimeRequestId) ;
235 mpi_access.deleteRequests(maxreq, RecvTimeRequestId) ;
236 mpi_access.waitAll(maxreq, RecvRequestId) ;
237 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
239 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
242 int sendrequests[2*maxreq] ;
243 int sendreqsize = mpi_access.sendRequestIds( target , 2*maxreq , sendrequests ) ;
244 if ( sendreqsize != 0 ) {
245 ostringstream strstream ;
246 strstream << "=========================================================" << endl
247 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
248 << "=========================================================" << endl ;
249 debugStream << strstream.str() << endl ;
250 CPPUNIT_FAIL( strstream.str() ) ;
253 debugStream << "=========================================================" << endl
254 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
255 << "=========================================================" << endl ;
259 int recvrequests[2*maxreq] ;
260 int recvreqsize = mpi_access.sendRequestIds( target , 2*maxreq , recvrequests ) ;
261 if ( recvreqsize != 0 ) {
262 ostringstream strstream ;
263 strstream << "=========================================================" << endl
264 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
265 << "=========================================================" << endl ;
266 debugStream << strstream.str() << endl ;
267 CPPUNIT_FAIL( strstream.str() ) ;
270 debugStream << "=========================================================" << endl
271 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
272 << "=========================================================" << endl ;
276 debugStream << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ;
277 mpi_access.barrier() ;
278 debugStream << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ;
284 debugStream << "test_MPI_Access_Time" << myrank << " OK" << endl ;