1 // Copyright (C) 2007-2015 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 ParaMEDMEM;
43 void MPIAccessTest::test_MPI_Access_Time() {
45 cout << "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 runned with 2 procs" << endl ;
57 cout << strstream.str() << endl ;
58 CPPUNIT_FAIL( strstream.str() ) ;
61 cout << "test_MPI_Access_Time" << myrank << endl ;
63 ParaMEDMEM::CommInterface interface ;
65 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
67 ParaMEDMEM::MPIAccess mpi_access( group ) ;
72 cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ;
73 mpi_access.barrier() ;
74 cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ;
76 cout << "test_MPI_Access_Time" << myrank << " OK" << endl ;
80 int target = 1 - myrank ;
81 int SendTimeRequestId[maxreq] ;
82 int RecvTimeRequestId[maxreq] ;
83 int SendRequestId[maxreq] ;
84 int RecvRequestId[maxreq] ;
89 ParaMEDMEM::TimeMessage aSendTimeMsg[maxreq] ;
90 ParaMEDMEM::TimeMessage aRecvTimeMsg[maxreq] ;
94 for ( t = 0 ; t < maxt ; t = t+dt ) {
96 aSendTimeMsg[i].time = t ;
97 aSendTimeMsg[i].deltatime = dt ;
98 //aSendTimeMsg[i].maxtime = maxt ;
99 //sts = mpi_access.ISend( &aSendTimeMsg , mpi_access.timeExtent() ,
100 sts = mpi_access.ISend( &aSendTimeMsg[i] , 1 ,
101 mpi_access.timeType() , target ,
102 SendTimeRequestId[i]) ;
103 cout << "test" << myrank << " ISend RequestId " << SendTimeRequestId[i]
104 << " tag " << mpi_access.sendMPITag(target) << endl ;
106 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, SendRequestId[i]) ;
107 cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
108 << " tag " << mpi_access.sendMPITag(target) << endl ;
111 //sts = mpi_access.IRecv( &aRecvTimeMsg , mpi_access.timeExtent() ,
112 sts = mpi_access.IRecv( &aRecvTimeMsg[i] , 1 ,
113 mpi_access.timeType() , target ,
114 RecvTimeRequestId[i]) ;
115 cout << "test" << myrank << " IRecv RequestId " << RecvTimeRequestId[i]
116 << " tag " << mpi_access.recvMPITag(target) << endl ;
117 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
118 cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
119 << " tag " << mpi_access.recvMPITag(target) << endl ;
122 for (j = 0 ; j <= i ; j++) {
125 mpi_access.test( SendTimeRequestId[j], flag ) ;
128 mpi_access.test( RecvTimeRequestId[j], flag ) ;
131 int target,source, tag, error, outcount ;
133 mpi_access.status( SendTimeRequestId[j], target, tag, error, outcount,
135 cout << "test" << myrank << " Test(Send TimeRequestId " << SendTimeRequestId[j]
136 << ") : target " << target << " tag " << tag << " error " << error
137 << " flag " << flag << aSendTimeMsg[j] << endl ;
140 mpi_access.status( RecvTimeRequestId[j], source, tag, error, outcount,
142 cout << "test" << myrank << " Test(Recv TimeRequestId "
143 << RecvTimeRequestId[j] << ") : source " << source << " tag " << tag
144 << " error " << error << " outcount " << outcount
145 << " flag " << flag << aRecvTimeMsg[j] << endl ;
146 if ( (outcount != 1) | (aRecvTimeMsg[j].time != j) ) {
147 ostringstream strstream ;
148 strstream << "==========================================================="
149 << endl << "test" << myrank << " outcount " << outcount << " KO"
150 << " RecvTimeRequestId " << RecvTimeRequestId[j] << endl
151 << "==========================================================="
153 cout << strstream.str() << endl ;
154 CPPUNIT_FAIL( strstream.str() ) ;
157 cout << "==========================================================="
158 << endl << "test" << myrank << " outcount " << outcount
159 << " RecvTimeRequestId " << RecvTimeRequestId[j] << " OK" << endl
160 << "==========================================================="
166 mpi_access.test( SendRequestId[j], flag ) ;
169 mpi_access.test( RecvRequestId[j], flag ) ;
172 int target,source, tag, error, outcount ;
174 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
176 cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
177 << ") : target " << target << " tag " << tag << " error " << error
178 << " flag " << flag << endl ;
181 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
183 cout << "test" << myrank << " Test(Recv RequestId "
184 << RecvRequestId[j] << ") : source " << source << " tag " << tag
185 << " error " << error << " outcount " << outcount
186 << " flag " << flag << endl ;
187 if ( (outcount != 1) | (recvbuf[j] != j) ) {
188 ostringstream strstream ;
189 strstream << "==========================================================="
190 << endl << "test" << myrank << " outcount "
191 << outcount << " recvbuf " << recvbuf[j] << " KO" << endl
192 << "==========================================================="
194 cout << strstream.str() << endl ;
195 CPPUNIT_FAIL( strstream.str() ) ;
198 cout << "==========================================================="
199 << endl << "test" << myrank << " outcount " << outcount
200 << " RequestId " << RecvRequestId[j] << " OK" << endl
201 << "==========================================================="
207 char msgerr[MPI_MAX_ERROR_STRING] ;
209 mpi_access.errorString(sts, msgerr, &lenerr) ;
210 cout << "test" << myrank << " lenerr " << lenerr << " "
213 if ( sts != MPI_SUCCESS ) {
214 ostringstream strstream ;
215 strstream << "==========================================================="
216 << "test" << myrank << " KO"
217 << "==========================================================="
219 cout << strstream.str() << endl ;
220 CPPUNIT_FAIL( strstream.str() ) ;
227 mpi_access.waitAll(maxreq, SendTimeRequestId) ;
228 mpi_access.deleteRequests(maxreq, SendTimeRequestId) ;
229 mpi_access.waitAll(maxreq, SendRequestId) ;
230 mpi_access.deleteRequests(maxreq, SendRequestId) ;
233 mpi_access.waitAll(maxreq, RecvTimeRequestId) ;
234 mpi_access.deleteRequests(maxreq, RecvTimeRequestId) ;
235 mpi_access.waitAll(maxreq, RecvRequestId) ;
236 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
241 int sendrequests[2*maxreq] ;
242 int sendreqsize = mpi_access.sendRequestIds( target , 2*maxreq , sendrequests ) ;
243 if ( sendreqsize != 0 ) {
244 ostringstream strstream ;
245 strstream << "=========================================================" << endl
246 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
247 << "=========================================================" << endl ;
248 cout << strstream.str() << endl ;
249 CPPUNIT_FAIL( strstream.str() ) ;
252 cout << "=========================================================" << endl
253 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
254 << "=========================================================" << endl ;
258 int recvrequests[2*maxreq] ;
259 int recvreqsize = mpi_access.sendRequestIds( target , 2*maxreq , recvrequests ) ;
260 if ( recvreqsize != 0 ) {
261 ostringstream strstream ;
262 strstream << "=========================================================" << endl
263 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
264 << "=========================================================" << endl ;
265 cout << strstream.str() << endl ;
266 CPPUNIT_FAIL( strstream.str() ) ;
269 cout << "=========================================================" << endl
270 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
271 << "=========================================================" << endl ;
275 cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ;
276 mpi_access.barrier() ;
277 cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ;
283 cout << "test_MPI_Access_Time" << myrank << " OK" << endl ;