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_ISend_IRecv() {
45 debugStream << "test_MPI_Access_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 cerr << "test_MPI_Access_ISend_IRecv must be runned with 2 procs" << endl ;
56 //CPPUNIT_FAIL("test_MPI_Access_ISend_IRecv must be runned with 2 procs") ;
60 debugStream << "test_MPI_Access_ISend_IRecv" << myrank << endl ;
62 MEDCoupling::CommInterface interface ;
64 MEDCoupling::MPIProcessorGroup* group = new MEDCoupling::MPIProcessorGroup(interface) ;
66 MEDCoupling::MPIAccess mpi_access( group ) ;
71 mpi_access.barrier() ;
76 int target = 1 - myrank ;
77 int SendRequestId[maxreq] ;
78 int RecvRequestId[maxreq] ;
83 for ( i = 0 ; i < maxreq ; i++ ) {
86 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, SendRequestId[i]) ;
87 debugStream << "test" << myrank << " ISend RequestId " << SendRequestId[i]
88 << " tag " << mpi_access.sendMPITag(target) << endl ;
91 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
92 debugStream << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
93 << " tag " << mpi_access.recvMPITag(target) << endl ;
96 for (j = 0 ; j <= i ; j++) {
99 mpi_access.test( SendRequestId[j], flag ) ;
102 mpi_access.test( RecvRequestId[j], flag ) ;
105 int target,source, tag, error, outcount ;
107 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
109 debugStream << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
110 << ") : target " << target << " tag " << tag << " error " << error
111 << " flag " << flag << endl ;
114 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
116 debugStream << "test" << myrank << " Test(Recv RequestId "
117 << RecvRequestId[j] << ") : source " << source << " tag " << tag
118 << " error " << error << " outcount " << outcount
119 << " flag " << flag << endl ;
120 if ( (outcount != 1) | (recvbuf[j] != j) ) {
121 ostringstream strstream ;
122 strstream << "==========================================================="
123 << endl << "test" << myrank << " outcount "
124 << outcount << " recvbuf " << recvbuf[j] << " KO" << endl
125 << "==========================================================="
127 debugStream << strstream.str() << endl ;
128 CPPUNIT_FAIL( strstream.str() ) ;
131 // debugStream << "==========================================================="
132 // << endl << "test" << myrank << " outcount " << outcount
133 // << " RequestId " << RecvRequestId[j] << " recvbuf "
134 // << recvbuf[j] << " OK" << endl
135 // << "==========================================================="
141 char msgerr[MPI_MAX_ERROR_STRING] ;
143 mpi_access.errorString(sts, msgerr, &lenerr) ;
144 debugStream << "test" << myrank << " lenerr " << lenerr << " "
147 if ( sts != MPI_SUCCESS ) {
148 ostringstream strstream ;
149 strstream << "==========================================================="
150 << "test" << myrank << " KO"
151 << "==========================================================="
153 debugStream << strstream.str() << endl ;
154 CPPUNIT_FAIL( strstream.str() ) ;
158 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
160 mpi_access.waitAll(maxreq, SendRequestId) ;
161 mpi_access.deleteRequests(maxreq, SendRequestId) ;
164 mpi_access.waitAll(maxreq, RecvRequestId) ;
165 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
167 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
170 int sendrequests[maxreq] ;
171 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
173 if ( sendreqsize != 0 ) {
174 ostringstream strstream ;
175 strstream << "=========================================================" << endl
176 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
177 << "=========================================================" << endl ;
178 debugStream << strstream.str() << endl ;
179 for ( i = 0 ; i < sendreqsize ; i++ ) {
180 debugStream << "test" << myrank << " sendrequests[ " << i << " ] = "
181 << sendrequests[i] << endl ;
183 CPPUNIT_FAIL( strstream.str() ) ;
186 debugStream << "=========================================================" << endl
187 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
188 << "=========================================================" << endl ;
192 int recvrequests[maxreq] ;
193 int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
194 if ( recvreqsize != 0 ) {
195 ostringstream strstream ;
196 strstream << "=========================================================" << endl
197 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
198 << "=========================================================" << endl ;
199 debugStream << strstream.str() << endl ;
200 CPPUNIT_FAIL( strstream.str() ) ;
203 debugStream << "=========================================================" << endl
204 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
205 << "=========================================================" << endl ;
209 mpi_access.barrier() ;
215 debugStream << "test" << myrank << " OK" << endl ;