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_ISendRecv() {
45 debugStream << "test_MPI_Access_ISendRecv" << 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_ISendRecv must be runned with 2 procs" << endl ;
56 //CPPUNIT_FAIL("test_MPI_Access_ISendRecv must be runned with 2 procs") ;
60 debugStream << "test_MPI_Access_ISendRecv" << myrank << endl ;
62 MEDCoupling::CommInterface interface ;
64 MEDCoupling::MPIProcessorGroup* group = new MEDCoupling::MPIProcessorGroup(interface) ;
66 MEDCoupling::MPIAccess mpi_access( group ) ;
69 mpi_access.barrier() ;
74 int target = 1 - myrank ;
75 int SendRequestId[10] ;
76 int RecvRequestId[10] ;
81 for ( i = 0 ; i < 10 ; i++ ) {
83 sts = mpi_access.ISendRecv(&sendbuf[i],1,MPI_INT,target, SendRequestId[i],
84 &recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
85 debugStream << "test" << myrank << " Send sendRequestId " << SendRequestId[i]
86 << " tag " << mpi_access.sendMPITag(target)
87 << " recvRequestId " << RecvRequestId[i]
88 << " tag " << mpi_access.recvMPITag(target) << endl ;
89 char msgerr[MPI_MAX_ERROR_STRING] ;
91 mpi_access.errorString(sts, msgerr, &lenerr) ;
92 debugStream << "test" << myrank << " lenerr " << lenerr
93 << " " << msgerr << endl ;
95 if ( sts != MPI_SUCCESS ) {
96 ostringstream strstream ;
97 strstream << "==========================================================="
98 << "test" << myrank << " KO"
99 << "==========================================================="
101 debugStream << strstream.str() << endl ;
102 CPPUNIT_FAIL( strstream.str() ) ;
105 for (j = 0 ; j <= i ; j++) {
108 debugStream << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j]
110 mpi_access.test( SendRequestId[j], flag ) ;
112 int target, tag, error, outcount ;
113 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
115 debugStream << "test" << myrank << " Send RequestId " << SendRequestId[j]
116 << " target " << target << " tag " << tag << " error " << error
118 mpi_access.deleteRequest( SendRequestId[j] ) ;
121 debugStream << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j]
123 mpi_access.test( RecvRequestId[j], flag ) ;
125 int source, tag, error, outcount ;
126 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
128 debugStream << "test" << myrank << " Recv RequestId" << j << " "
129 << RecvRequestId[j] << " source " << source << " tag " << tag
130 << " error " << error << " outcount " << outcount << endl ;
131 if ( (outcount != 1) | (recvbuf[j] != j) ) {
132 ostringstream strstream ;
133 strstream << "==========================================================="
134 << "test" << myrank << " outcount "
135 << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO"
136 << "==========================================================="
138 debugStream << strstream.str() << endl ;
139 CPPUNIT_FAIL( strstream.str() ) ;
143 mpi_access.errorString(sts, msgerr, &lenerr) ;
144 debugStream << "test" << myrank << " lenerr " << lenerr << " "
146 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
150 mpi_access.testAll(10,SendRequestId,flag) ;
151 mpi_access.waitAll(10,SendRequestId) ;
152 mpi_access.deleteRequests(10,SendRequestId) ;
153 mpi_access.testAll(10,SendRequestId,flag) ;
155 ostringstream strstream ;
156 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
157 debugStream << strstream.str() << endl ;
158 CPPUNIT_FAIL( strstream.str() ) ;
161 mpi_access.testAll(10,RecvRequestId,flag) ;
162 mpi_access.waitAll(10,RecvRequestId) ;
163 mpi_access.deleteRequests(10,RecvRequestId) ;
164 mpi_access.testAll(10,RecvRequestId,flag) ;
166 ostringstream strstream ;
167 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
168 debugStream << strstream.str() << endl ;
169 CPPUNIT_FAIL( strstream.str() ) ;
171 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
173 int sendrequests[10] ;
174 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
175 if ( sendreqsize != 0 ) {
176 ostringstream strstream ;
177 strstream << "=========================================================" << endl
178 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
179 << "=========================================================" << endl ;
180 debugStream << strstream.str() << endl ;
181 CPPUNIT_FAIL( strstream.str() ) ;
184 debugStream << "=========================================================" << endl
185 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
186 << "=========================================================" << endl ;
188 int recvrequests[10] ;
189 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
190 if ( recvreqsize != 0 ) {
191 ostringstream strstream ;
192 strstream << "=========================================================" << endl
193 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
194 << "=========================================================" << endl ;
195 debugStream << strstream.str() << endl ;
196 CPPUNIT_FAIL( strstream.str() ) ;
199 debugStream << "=========================================================" << endl
200 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
201 << "=========================================================" << endl ;
204 mpi_access.barrier() ;
210 debugStream << "test" << myrank << " OK" << endl ;