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
31 #include "MPIAccessTest.hxx"
32 #include <cppunit/TestAssert.h>
34 //#include "CommInterface.hxx"
35 //#include "ProcessorGroup.hxx"
36 //#include "MPIProcessorGroup.hxx"
37 #include "MPIAccess.hxx"
39 // use this define to enable lines, execution of which leads to Segmentation Fault
42 // use this define to enable CPPUNIT asserts and fails, showing bugs
43 #define ENABLE_FORCED_FAILURES
46 using namespace MEDCoupling;
48 void MPIAccessTest::test_MPI_Access_IProbe() {
50 debugStream << "test_MPI_Access_IProbe" << endl ;
52 // MPI_Init(&argc, &argv) ;
56 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
57 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
60 ostringstream strstream ;
61 strstream << "test_MPI_Access_IProbe must be runned with 2 procs" << endl ;
62 cerr << strstream.str() << endl ;
63 //CPPUNIT_FAIL( strstream.str() ) ;
67 debugStream << "test_MPI_Access_IProbe" << myrank << endl ;
69 MEDCoupling::CommInterface interface ;
71 MEDCoupling::MPIProcessorGroup* group = new MEDCoupling::MPIProcessorGroup(interface) ;
73 MEDCoupling::MPIAccess mpi_access( group ) ;
76 mpi_access.barrier() ;
81 int target = 1 - myrank ;
86 for ( i = 0 ; i < 10 ; i++ ) {
89 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, RequestId[i]) ;
90 debugStream << "test" << myrank << " Send RequestId " << RequestId[i]
96 int source, tag, outcount ;
97 MPI_Datatype datatype ;
98 sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ;
100 debugStream << "test" << myrank << " " << i << " IProbe target " << target
101 << " source " << source << " tag " << tag
102 << " outcount " << outcount << " flag " << flag << endl ;
105 debugStream << "test" << myrank << " IProbe flag " << flag << endl ;
110 sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
112 if ( (outcount != 1) | (recvbuf != i) ) {
113 ostringstream strstream ;
114 strstream << "==========================================================="
115 << endl << "test" << myrank << " outcount " << outcount
116 << " recvbuf " << recvbuf << " KO" << endl
117 << "==========================================================="
119 debugStream << strstream.str() << endl ;
120 CPPUNIT_FAIL( strstream.str() ) ;
122 debugStream << "==========================================================="
123 << endl << "test" << myrank << " outcount " << outcount
124 << " recvbuf " << recvbuf << " OK" << endl
125 << "==========================================================="
130 char msgerr[MPI_MAX_ERROR_STRING] ;
132 mpi_access.errorString(sts, msgerr, &lenerr) ;
133 debugStream << "test" << myrank << " lenerr " << lenerr << " "
136 if ( sts != MPI_SUCCESS ) {
137 ostringstream strstream ;
138 strstream << "==========================================================="
139 << "test" << myrank << " KO"
140 << "==========================================================="
142 debugStream << strstream.str() << endl ;
143 CPPUNIT_FAIL( strstream.str() ) ;
145 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
148 mpi_access.testAll(10,RequestId,flag) ;
149 mpi_access.waitAll(10,RequestId) ;
150 mpi_access.deleteRequests(10,RequestId) ;
151 mpi_access.testAll(10,RequestId,flag) ;
153 ostringstream strstream ;
154 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
155 debugStream << strstream.str() << endl ;
156 CPPUNIT_FAIL( strstream.str() ) ;
158 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
160 mpi_access.barrier() ;
166 debugStream << "test" << myrank << " OK" << endl ;