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_Cyclic_ISend_IRecv() {
45 cout << "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 cout << "test_MPI_Access_Cyclic_ISend_IRecv must be runned with 3 procs" << endl ;
56 CPPUNIT_FAIL("test_MPI_Access_Cyclic_ISend_IRecv must be runned with 3 procs") ;
59 cout << "test_MPI_Access_Cyclic_ISend_IRecv" << 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 alltarget[3] = {1 , 2 , 0 } ;
76 int allsource[3] = {2 , 0 , 1 } ;
77 int SendRequestId[maxsend] ;
78 int RecvRequestId[maxsend] ;
79 int sendbuf[maxsend] ;
80 int recvbuf[maxsend] ;
85 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank],
87 cout << "test" << myrank << " Send RequestId " << SendRequestId[i]
88 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
90 for ( i = 0 ; i < maxsend ; i++ ) {
92 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,allsource[myrank],
94 cout << "test" << myrank << " Recv RequestId " << RecvRequestId[i]
95 << " tag " << mpi_access.recvMPITag(allsource[myrank]) << endl ;
96 char msgerr[MPI_MAX_ERROR_STRING] ;
98 mpi_access.errorString(sts, msgerr, &lenerr) ;
99 cout << "test" << myrank << " lenerr " << lenerr
100 << " " << msgerr << endl ;
102 if ( sts != MPI_SUCCESS ) {
103 ostringstream strstream ;
104 strstream << "==========================================================="
105 << "test" << myrank << " KO"
106 << "==========================================================="
108 cout << strstream.str() << endl ;
109 CPPUNIT_FAIL( strstream.str() ) ;
112 for (j = 0 ; j <= i ; j++) {
115 cout << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j]
117 mpi_access.test( SendRequestId[j], flag ) ;
119 int target, tag, error, outcount ;
120 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
122 cout << "test" << myrank << " Send RequestId " << SendRequestId[j]
123 << " target " << target << " tag " << tag << " error " << error
125 mpi_access.deleteRequest( SendRequestId[j] ) ;
128 cout << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j]
130 mpi_access.test( RecvRequestId[j], flag ) ;
132 int source, tag, error, outcount ;
133 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
135 cout << "test" << myrank << " Recv RequestId" << j << " "
136 << RecvRequestId[j] << " source " << source << " tag " << tag
137 << " error " << error << " outcount " << outcount << endl ;
138 if ( (outcount != 1) | (recvbuf[j] != j) ) {
139 ostringstream strstream ;
140 strstream << "====================================================="
141 << endl << "test" << myrank << " outcount "
142 << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO"
143 << endl << "====================================================="
145 cout << strstream.str() << endl ;
146 CPPUNIT_FAIL( strstream.str() ) ;
151 if ( i != maxsend-1 ) {
152 sendbuf[i+1] = i + 1 ;
153 sts = mpi_access.ISend(&sendbuf[i+1],1,MPI_INT,alltarget[myrank],
154 SendRequestId[i+1]) ;
155 cout << "test" << myrank << " Send RequestId " << SendRequestId[i+1]
156 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
161 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank],
163 cout << "test" << myrank << " Send RequestId " << SendRequestId[i]
164 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
166 mpi_access.errorString(sts, msgerr, &lenerr) ;
167 cout << "test" << myrank << " lenerr " << lenerr
168 << " " << msgerr << endl ;
170 if ( sts != MPI_SUCCESS ) {
171 ostringstream strstream ;
172 strstream << "==========================================================="
173 << "test" << myrank << " KO"
174 << "==========================================================="
176 cout << strstream.str() << endl ;
177 CPPUNIT_FAIL( strstream.str() ) ;
183 mpi_access.testAll(maxsend,SendRequestId,flag) ;
184 mpi_access.testAll(maxsend,RecvRequestId,flag) ;
185 mpi_access.waitAll(maxsend,SendRequestId) ;
186 mpi_access.deleteRequests(maxsend,SendRequestId) ;
187 mpi_access.waitAll(maxsend,RecvRequestId) ;
188 mpi_access.deleteRequests(maxsend,RecvRequestId) ;
190 mpi_access.testAll(maxsend,SendRequestId,flag) ;
192 ostringstream strstream ;
193 strstream << "=========================================================" << endl
194 << "test" << myrank << " TestAllSendflag " << flag << " KO" << endl
195 << "=========================================================" << endl ;
196 cout << strstream.str() << endl ;
197 CPPUNIT_FAIL( strstream.str() ) ;
200 cout << "=========================================================" << endl
201 << "test" << myrank << " TestAllSendflag " << flag << " OK" << endl
202 << "=========================================================" << endl ;
204 mpi_access.testAll(maxsend,RecvRequestId,flag) ;
206 ostringstream strstream ;
207 strstream << "=========================================================" << endl
208 << "test" << myrank << " TestAllRecvflag " << flag << " KO" << endl
209 << "=========================================================" << endl ;
210 cout << strstream.str() << endl ;
211 CPPUNIT_FAIL( strstream.str() ) ;
214 cout << "=========================================================" << endl
215 << "test" << myrank << " TestAllRecvflag " << flag << " OK" << endl
216 << "=========================================================" << endl ;
219 int sendrequests[maxsend] ;
220 int sendreqsize = mpi_access.sendRequestIds( alltarget[myrank] , maxsend ,
222 if ( sendreqsize != 0 ) {
223 ostringstream strstream ;
224 strstream << "=========================================================" << endl
225 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
226 << "=========================================================" << endl ;
227 cout << strstream.str() << endl ;
228 int source, tag, error, outcount ;
229 mpi_access.status(sendrequests[0], source, tag, error, outcount, true) ;
230 cout << "test" << myrank << " RequestId " << sendrequests[0]
231 << " source " << source << " tag " << tag << " error " << error
232 << " outcount " << outcount << endl ;
233 CPPUNIT_FAIL( strstream.str() ) ;
236 cout << "=========================================================" << endl
237 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
238 << "=========================================================" << endl ;
240 int recvrequests[maxsend] ;
241 int recvreqsize = mpi_access.sendRequestIds( allsource[myrank] , maxsend ,
243 if ( recvreqsize != 0 ) {
244 ostringstream strstream ;
245 strstream << "=========================================================" << endl
246 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
247 << "=========================================================" << endl ;
248 cout << strstream.str() << endl ;
249 CPPUNIT_FAIL( strstream.str() ) ;
252 cout << "=========================================================" << endl
253 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
254 << "=========================================================" << endl ;
257 mpi_access.barrier() ;
263 cout << "test" << myrank << " OK" << endl ;