1 // Copyright (C) 2007-2021 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_SendRecv() {
45 debugStream << "MPIAccessTest::test_MPI_Access_SendRecv" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 cerr << "MPIAccessTest::test_MPI_Access_SendRecv must be run with 2 procs" << endl ;
56 //CPPUNIT_FAIL("test_MPI_Access_SendRecv must be run with 2 procs") ;
60 debugStream << "MPIAccessTest::test_MPI_Access_SendRecv" << 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] ;
79 for ( i = 0 ; i < 10 ; i++ ) {
84 sts = mpi_access.sendRecv(&i,1,MPI_INT,target, sendRequestId[i],
85 &recvbuf,1,MPI_INT,target, recvRequestId[i],
89 sts = mpi_access.sendRecv(&i,1,MPI_INT,target, sendRequestId[i],
90 &recvbuf,1,MPI_INT,target, recvRequestId[i]) ;
91 // outcount = mpi_access.MPIOutCount( recvRequestId[i] ) ;
94 debugStream << "test" << myrank << " Send sendRequestId " << sendRequestId[i]
95 << " tag " << mpi_access.sendMPITag(target)
96 << " recvRequestId " << recvRequestId[i]
97 << " tag " << mpi_access.recvMPITag(target)
98 << " outcount " << outcount << " MPIOutCount "
99 << mpi_access.MPIOutCount( recvRequestId[i] ) << endl ;
100 if ( (outcount != 1) | (recvbuf != i) ) {
101 ostringstream strstream ;
102 strstream << "==========================================================="
103 << "test" << myrank << " outcount " << outcount
104 << " recvbuf " << recvbuf << " KO"
105 << "==========================================================="
107 debugStream << strstream.str() << endl ;
108 CPPUNIT_FAIL( strstream.str() ) ;
110 char msgerr[MPI_MAX_ERROR_STRING] ;
112 mpi_access.errorString(sts, msgerr, &lenerr) ;
113 debugStream << "test" << myrank << " lenerr " << lenerr << " "
116 if ( sts != MPI_SUCCESS ) {
117 ostringstream strstream ;
118 strstream << "==========================================================="
119 << "test" << myrank << " KO"
120 << "==========================================================="
122 debugStream << strstream.str() << endl ;
123 CPPUNIT_FAIL( strstream.str() ) ;
125 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
129 mpi_access.testAll(10,sendRequestId,flag) ;
131 ostringstream strstream ;
132 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
133 debugStream << strstream.str() << endl ;
134 CPPUNIT_FAIL( strstream.str() ) ;
136 mpi_access.waitAll(10,sendRequestId) ;
137 mpi_access.testAll(10,recvRequestId,flag) ;
139 ostringstream strstream ;
140 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
141 debugStream << strstream.str() << endl ;
142 CPPUNIT_FAIL( strstream.str() ) ;
144 mpi_access.waitAll(10,recvRequestId) ;
145 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
147 int sendrequests[10] ;
148 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
149 if ( sendreqsize != 0 ) {
150 ostringstream strstream ;
151 strstream << "=========================================================" << endl
152 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
153 << "=========================================================" << endl ;
154 debugStream << strstream.str() << endl ;
155 CPPUNIT_FAIL( strstream.str() ) ;
157 int recvrequests[10] ;
158 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
159 if ( recvreqsize != 0 ) {
160 ostringstream strstream ;
161 strstream << "=========================================================" << endl
162 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
163 << "=========================================================" << endl ;
164 debugStream << strstream.str() << endl ;
165 CPPUNIT_FAIL( strstream.str() ) ;
168 mpi_access.barrier() ;
174 debugStream << "test" << myrank << " OK" << endl ;