1 // Copyright (C) 2007-2008 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
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 ParaMEDMEM;
43 void MPIAccessTest::test_MPI_Access_IProbe() {
45 cout << "test_MPI_Access_IProbe" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 ostringstream strstream ;
56 strstream << "test_MPI_Access_IProbe must be runned with 2 procs" << endl ;
57 cout << strstream.str() << endl ;
58 CPPUNIT_FAIL( strstream.str() ) ;
61 cout << "test_MPI_Access_IProbe" << myrank << endl ;
63 ParaMEDMEM::CommInterface interface ;
65 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
67 ParaMEDMEM::MPIAccess mpi_access( group ) ;
70 mpi_access.barrier() ;
75 int target = 1 - myrank ;
80 for ( i = 0 ; i < 10 ; i++ ) {
83 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, RequestId[i]) ;
84 cout << "test" << myrank << " Send RequestId " << RequestId[i]
90 int source, tag, outcount ;
91 MPI_Datatype datatype ;
92 sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ;
94 cout << "test" << myrank << " " << i << " IProbe target " << target
95 << " source " << source << " tag " << tag
96 << " outcount " << outcount << " flag " << flag << endl ;
99 cout << "test" << myrank << " IProbe flag " << flag << endl ;
104 sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
106 if ( (outcount != 1) | (recvbuf != i) ) {
107 ostringstream strstream ;
108 strstream << "==========================================================="
109 << endl << "test" << myrank << " outcount " << outcount
110 << " recvbuf " << recvbuf << " KO" << endl
111 << "==========================================================="
113 cout << strstream.str() << endl ;
114 CPPUNIT_FAIL( strstream.str() ) ;
116 cout << "==========================================================="
117 << endl << "test" << myrank << " outcount " << outcount
118 << " recvbuf " << recvbuf << " OK" << endl
119 << "==========================================================="
124 char msgerr[MPI_MAX_ERROR_STRING] ;
126 mpi_access.errorString(sts, msgerr, &lenerr) ;
127 cout << "test" << myrank << " lenerr " << lenerr << " "
130 if ( sts != MPI_SUCCESS ) {
131 ostringstream strstream ;
132 strstream << "==========================================================="
133 << "test" << myrank << " KO"
134 << "==========================================================="
136 cout << strstream.str() << endl ;
137 CPPUNIT_FAIL( strstream.str() ) ;
142 mpi_access.testAll(10,RequestId,flag) ;
143 mpi_access.waitAll(10,RequestId) ;
144 mpi_access.deleteRequests(10,RequestId) ;
145 mpi_access.testAll(10,RequestId,flag) ;
147 ostringstream strstream ;
148 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
149 cout << strstream.str() << endl ;
150 CPPUNIT_FAIL( strstream.str() ) ;
154 mpi_access.barrier() ;
160 cout << "test" << myrank << " OK" << endl ;