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
25 #include "MPIAccessTest.hxx"
26 #include <cppunit/TestAssert.h>
28 //#include "CommInterface.hxx"
29 //#include "ProcessorGroup.hxx"
30 //#include "MPIProcessorGroup.hxx"
31 #include "MPIAccess.hxx"
33 // use this define to enable lines, execution of which leads to Segmentation Fault
36 // use this define to enable CPPUNIT asserts and fails, showing bugs
37 #define ENABLE_FORCED_FAILURES
40 using namespace ParaMEDMEM;
42 void MPIAccessTest::test_MPI_Access_Time() {
44 cout << "test_MPI_Access_Time" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 ostringstream strstream ;
55 strstream << "test_MPI_Access_Time must be runned with 2 procs" << endl ;
56 cout << strstream.str() << endl ;
57 CPPUNIT_FAIL( strstream.str() ) ;
60 cout << "test_MPI_Access_Time" << myrank << endl ;
62 ParaMEDMEM::CommInterface interface ;
64 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
66 ParaMEDMEM::MPIAccess mpi_access( group ) ;
71 cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ;
72 mpi_access.barrier() ;
73 cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ;
75 cout << "test_MPI_Access_Time" << myrank << " OK" << endl ;
79 int target = 1 - myrank ;
80 int SendTimeRequestId[maxreq] ;
81 int RecvTimeRequestId[maxreq] ;
82 int SendRequestId[maxreq] ;
83 int RecvRequestId[maxreq] ;
88 ParaMEDMEM::TimeMessage aSendTimeMsg[maxreq] ;
89 ParaMEDMEM::TimeMessage aRecvTimeMsg[maxreq] ;
93 for ( t = 0 ; t < maxt ; t = t+dt ) {
95 aSendTimeMsg[i].time = t ;
96 aSendTimeMsg[i].deltatime = dt ;
97 //aSendTimeMsg[i].maxtime = maxt ;
98 //sts = mpi_access.ISend( &aSendTimeMsg , mpi_access.timeExtent() ,
99 sts = mpi_access.ISend( &aSendTimeMsg[i] , 1 ,
100 mpi_access.timeType() , target ,
101 SendTimeRequestId[i]) ;
102 cout << "test" << myrank << " ISend RequestId " << SendTimeRequestId[i]
103 << " tag " << mpi_access.sendMPITag(target) << endl ;
105 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, SendRequestId[i]) ;
106 cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
107 << " tag " << mpi_access.sendMPITag(target) << endl ;
110 //sts = mpi_access.IRecv( &aRecvTimeMsg , mpi_access.timeExtent() ,
111 sts = mpi_access.IRecv( &aRecvTimeMsg[i] , 1 ,
112 mpi_access.timeType() , target ,
113 RecvTimeRequestId[i]) ;
114 cout << "test" << myrank << " IRecv RequestId " << RecvTimeRequestId[i]
115 << " tag " << mpi_access.recvMPITag(target) << endl ;
116 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
117 cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
118 << " tag " << mpi_access.recvMPITag(target) << endl ;
121 for (j = 0 ; j <= i ; j++) {
124 mpi_access.test( SendTimeRequestId[j], flag ) ;
127 mpi_access.test( RecvTimeRequestId[j], flag ) ;
130 int target,source, tag, error, outcount ;
132 mpi_access.status( SendTimeRequestId[j], target, tag, error, outcount,
134 cout << "test" << myrank << " Test(Send TimeRequestId " << SendTimeRequestId[j]
135 << ") : target " << target << " tag " << tag << " error " << error
136 << " flag " << flag << aSendTimeMsg[j] << endl ;
139 mpi_access.status( RecvTimeRequestId[j], source, tag, error, outcount,
141 cout << "test" << myrank << " Test(Recv TimeRequestId "
142 << RecvTimeRequestId[j] << ") : source " << source << " tag " << tag
143 << " error " << error << " outcount " << outcount
144 << " flag " << flag << aRecvTimeMsg[j] << endl ;
145 if ( (outcount != 1) | (aRecvTimeMsg[j].time != j) ) {
146 ostringstream strstream ;
147 strstream << "==========================================================="
148 << endl << "test" << myrank << " outcount " << outcount << " KO"
149 << " RecvTimeRequestId " << RecvTimeRequestId[j] << endl
150 << "==========================================================="
152 cout << strstream.str() << endl ;
153 CPPUNIT_FAIL( strstream.str() ) ;
156 cout << "==========================================================="
157 << endl << "test" << myrank << " outcount " << outcount
158 << " RecvTimeRequestId " << RecvTimeRequestId[j] << " OK" << endl
159 << "==========================================================="
165 mpi_access.test( SendRequestId[j], flag ) ;
168 mpi_access.test( RecvRequestId[j], flag ) ;
171 int target,source, tag, error, outcount ;
173 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
175 cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
176 << ") : target " << target << " tag " << tag << " error " << error
177 << " flag " << flag << endl ;
180 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
182 cout << "test" << myrank << " Test(Recv RequestId "
183 << RecvRequestId[j] << ") : source " << source << " tag " << tag
184 << " error " << error << " outcount " << outcount
185 << " flag " << flag << endl ;
186 if ( (outcount != 1) | (recvbuf[j] != j) ) {
187 ostringstream strstream ;
188 strstream << "==========================================================="
189 << endl << "test" << myrank << " outcount "
190 << outcount << " recvbuf " << recvbuf[j] << " KO" << endl
191 << "==========================================================="
193 cout << strstream.str() << endl ;
194 CPPUNIT_FAIL( strstream.str() ) ;
197 cout << "==========================================================="
198 << endl << "test" << myrank << " outcount " << outcount
199 << " RequestId " << RecvRequestId[j] << " OK" << endl
200 << "==========================================================="
206 char msgerr[MPI_MAX_ERROR_STRING] ;
208 mpi_access.errorString(sts, msgerr, &lenerr) ;
209 cout << "test" << myrank << " lenerr " << lenerr << " "
212 if ( sts != MPI_SUCCESS ) {
213 ostringstream strstream ;
214 strstream << "==========================================================="
215 << "test" << myrank << " KO"
216 << "==========================================================="
218 cout << strstream.str() << endl ;
219 CPPUNIT_FAIL( strstream.str() ) ;
226 mpi_access.waitAll(maxreq, SendTimeRequestId) ;
227 mpi_access.deleteRequests(maxreq, SendTimeRequestId) ;
228 mpi_access.waitAll(maxreq, SendRequestId) ;
229 mpi_access.deleteRequests(maxreq, SendRequestId) ;
232 mpi_access.waitAll(maxreq, RecvTimeRequestId) ;
233 mpi_access.deleteRequests(maxreq, RecvTimeRequestId) ;
234 mpi_access.waitAll(maxreq, RecvRequestId) ;
235 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
240 int sendrequests[2*maxreq] ;
241 int sendreqsize = mpi_access.sendRequestIds( target , 2*maxreq , sendrequests ) ;
242 if ( sendreqsize != 0 ) {
243 ostringstream strstream ;
244 strstream << "=========================================================" << endl
245 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
246 << "=========================================================" << endl ;
247 cout << strstream.str() << endl ;
248 CPPUNIT_FAIL( strstream.str() ) ;
251 cout << "=========================================================" << endl
252 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
253 << "=========================================================" << endl ;
257 int recvrequests[2*maxreq] ;
258 int recvreqsize = mpi_access.sendRequestIds( target , 2*maxreq , recvrequests ) ;
259 if ( recvreqsize != 0 ) {
260 ostringstream strstream ;
261 strstream << "=========================================================" << endl
262 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
263 << "=========================================================" << endl ;
264 cout << strstream.str() << endl ;
265 CPPUNIT_FAIL( strstream.str() ) ;
268 cout << "=========================================================" << endl
269 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
270 << "=========================================================" << endl ;
274 cout << "test_MPI_Access_Time_0 rank" << myrank << " --> mpi_access->Barrier" << endl ;
275 mpi_access.barrier() ;
276 cout << "test_MPI_Access_Time_0 rank" << myrank << " <-- mpi_access->Barrier" << endl ;
282 cout << "test_MPI_Access_Time" << myrank << " OK" << endl ;