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_Cyclic_ISend_IRecv() {
44 cout << "test_MPI_Access_Cyclic_ISend_IRecv" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 cout << "test_MPI_Access_Cyclic_ISend_IRecv must be runned with 3 procs" << endl ;
55 CPPUNIT_FAIL("test_MPI_Access_Cyclic_ISend_IRecv must be runned with 3 procs") ;
58 cout << "test_MPI_Access_Cyclic_ISend_IRecv" << myrank << endl ;
60 ParaMEDMEM::CommInterface interface ;
62 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
64 ParaMEDMEM::MPIAccess mpi_access( group ) ;
69 mpi_access.barrier() ;
74 int alltarget[3] = {1 , 2 , 0 } ;
75 int allsource[3] = {2 , 0 , 1 } ;
76 int SendRequestId[maxsend] ;
77 int RecvRequestId[maxsend] ;
78 int sendbuf[maxsend] ;
79 int recvbuf[maxsend] ;
84 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank],
86 cout << "test" << myrank << " Send RequestId " << SendRequestId[i]
87 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
89 for ( i = 0 ; i < maxsend ; i++ ) {
91 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,allsource[myrank],
93 cout << "test" << myrank << " Recv RequestId " << RecvRequestId[i]
94 << " tag " << mpi_access.recvMPITag(allsource[myrank]) << endl ;
95 char msgerr[MPI_MAX_ERROR_STRING] ;
97 mpi_access.errorString(sts, msgerr, &lenerr) ;
98 cout << "test" << myrank << " lenerr " << lenerr
99 << " " << msgerr << endl ;
101 if ( sts != MPI_SUCCESS ) {
102 ostringstream strstream ;
103 strstream << "==========================================================="
104 << "test" << myrank << " KO"
105 << "==========================================================="
107 cout << strstream.str() << endl ;
108 CPPUNIT_FAIL( strstream.str() ) ;
111 for (j = 0 ; j <= i ; j++) {
114 cout << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j]
116 mpi_access.test( SendRequestId[j], flag ) ;
118 int target, tag, error, outcount ;
119 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
121 cout << "test" << myrank << " Send RequestId " << SendRequestId[j]
122 << " target " << target << " tag " << tag << " error " << error
124 mpi_access.deleteRequest( SendRequestId[j] ) ;
127 cout << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j]
129 mpi_access.test( RecvRequestId[j], flag ) ;
131 int source, tag, error, outcount ;
132 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
134 cout << "test" << myrank << " Recv RequestId" << j << " "
135 << RecvRequestId[j] << " source " << source << " tag " << tag
136 << " error " << error << " outcount " << outcount << endl ;
137 if ( (outcount != 1) | (recvbuf[j] != j) ) {
138 ostringstream strstream ;
139 strstream << "====================================================="
140 << endl << "test" << myrank << " outcount "
141 << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO"
142 << endl << "====================================================="
144 cout << strstream.str() << endl ;
145 CPPUNIT_FAIL( strstream.str() ) ;
150 if ( i != maxsend-1 ) {
151 sendbuf[i+1] = i + 1 ;
152 sts = mpi_access.ISend(&sendbuf[i+1],1,MPI_INT,alltarget[myrank],
153 SendRequestId[i+1]) ;
154 cout << "test" << myrank << " Send RequestId " << SendRequestId[i+1]
155 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
160 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,alltarget[myrank],
162 cout << "test" << myrank << " Send RequestId " << SendRequestId[i]
163 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
165 mpi_access.errorString(sts, msgerr, &lenerr) ;
166 cout << "test" << myrank << " lenerr " << lenerr
167 << " " << msgerr << endl ;
169 if ( sts != MPI_SUCCESS ) {
170 ostringstream strstream ;
171 strstream << "==========================================================="
172 << "test" << myrank << " KO"
173 << "==========================================================="
175 cout << strstream.str() << endl ;
176 CPPUNIT_FAIL( strstream.str() ) ;
182 mpi_access.testAll(maxsend,SendRequestId,flag) ;
183 mpi_access.testAll(maxsend,RecvRequestId,flag) ;
184 mpi_access.waitAll(maxsend,SendRequestId) ;
185 mpi_access.deleteRequests(maxsend,SendRequestId) ;
186 mpi_access.waitAll(maxsend,RecvRequestId) ;
187 mpi_access.deleteRequests(maxsend,RecvRequestId) ;
189 mpi_access.testAll(maxsend,SendRequestId,flag) ;
191 ostringstream strstream ;
192 strstream << "=========================================================" << endl
193 << "test" << myrank << " TestAllSendflag " << flag << " KO" << endl
194 << "=========================================================" << endl ;
195 cout << strstream.str() << endl ;
196 CPPUNIT_FAIL( strstream.str() ) ;
199 cout << "=========================================================" << endl
200 << "test" << myrank << " TestAllSendflag " << flag << " OK" << endl
201 << "=========================================================" << endl ;
203 mpi_access.testAll(maxsend,RecvRequestId,flag) ;
205 ostringstream strstream ;
206 strstream << "=========================================================" << endl
207 << "test" << myrank << " TestAllRecvflag " << flag << " KO" << endl
208 << "=========================================================" << endl ;
209 cout << strstream.str() << endl ;
210 CPPUNIT_FAIL( strstream.str() ) ;
213 cout << "=========================================================" << endl
214 << "test" << myrank << " TestAllRecvflag " << flag << " OK" << endl
215 << "=========================================================" << endl ;
218 int sendrequests[maxsend] ;
219 int sendreqsize = mpi_access.sendRequestIds( alltarget[myrank] , maxsend ,
221 if ( sendreqsize != 0 ) {
222 ostringstream strstream ;
223 strstream << "=========================================================" << endl
224 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
225 << "=========================================================" << endl ;
226 cout << strstream.str() << endl ;
227 int source, tag, error, outcount ;
228 mpi_access.status(sendrequests[0], source, tag, error, outcount, true) ;
229 cout << "test" << myrank << " RequestId " << sendrequests[0]
230 << " source " << source << " tag " << tag << " error " << error
231 << " outcount " << outcount << endl ;
232 CPPUNIT_FAIL( strstream.str() ) ;
235 cout << "=========================================================" << endl
236 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
237 << "=========================================================" << endl ;
239 int recvrequests[maxsend] ;
240 int recvreqsize = mpi_access.sendRequestIds( allsource[myrank] , maxsend ,
242 if ( recvreqsize != 0 ) {
243 ostringstream strstream ;
244 strstream << "=========================================================" << endl
245 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
246 << "=========================================================" << endl ;
247 cout << strstream.str() << endl ;
248 CPPUNIT_FAIL( strstream.str() ) ;
251 cout << "=========================================================" << endl
252 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
253 << "=========================================================" << endl ;
256 mpi_access.barrier() ;
262 cout << "test" << myrank << " OK" << endl ;