1 // Copyright (C) 2007-2012 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
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 ParaMEDMEM;
48 void MPIAccessTest::test_MPI_Access_IProbe() {
50 cout << "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 cout << strstream.str() << endl ;
63 CPPUNIT_FAIL( strstream.str() ) ;
66 cout << "test_MPI_Access_IProbe" << myrank << endl ;
68 ParaMEDMEM::CommInterface interface ;
70 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
72 ParaMEDMEM::MPIAccess mpi_access( group ) ;
75 mpi_access.barrier() ;
80 int target = 1 - myrank ;
85 for ( i = 0 ; i < 10 ; i++ ) {
88 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, RequestId[i]) ;
89 cout << "test" << myrank << " Send RequestId " << RequestId[i]
95 int source, tag, outcount ;
96 MPI_Datatype datatype ;
97 sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ;
99 cout << "test" << myrank << " " << i << " IProbe target " << target
100 << " source " << source << " tag " << tag
101 << " outcount " << outcount << " flag " << flag << endl ;
104 cout << "test" << myrank << " IProbe flag " << flag << endl ;
109 sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
111 if ( (outcount != 1) | (recvbuf != i) ) {
112 ostringstream strstream ;
113 strstream << "==========================================================="
114 << endl << "test" << myrank << " outcount " << outcount
115 << " recvbuf " << recvbuf << " KO" << endl
116 << "==========================================================="
118 cout << strstream.str() << endl ;
119 CPPUNIT_FAIL( strstream.str() ) ;
121 cout << "==========================================================="
122 << endl << "test" << myrank << " outcount " << outcount
123 << " recvbuf " << recvbuf << " OK" << endl
124 << "==========================================================="
129 char msgerr[MPI_MAX_ERROR_STRING] ;
131 mpi_access.errorString(sts, msgerr, &lenerr) ;
132 cout << "test" << myrank << " lenerr " << lenerr << " "
135 if ( sts != MPI_SUCCESS ) {
136 ostringstream strstream ;
137 strstream << "==========================================================="
138 << "test" << myrank << " KO"
139 << "==========================================================="
141 cout << strstream.str() << endl ;
142 CPPUNIT_FAIL( strstream.str() ) ;
147 mpi_access.testAll(10,RequestId,flag) ;
148 mpi_access.waitAll(10,RequestId) ;
149 mpi_access.deleteRequests(10,RequestId) ;
150 mpi_access.testAll(10,RequestId,flag) ;
152 ostringstream strstream ;
153 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
154 cout << strstream.str() << endl ;
155 CPPUNIT_FAIL( strstream.str() ) ;
159 mpi_access.barrier() ;
165 cout << "test" << myrank << " OK" << endl ;