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
25 #include "MPIAccessTest.hxx"
26 #include <cppunit/TestAssert.h>
28 //#include "CommInterface.hxx"
29 //#include "ProcessorGroup.hxx"
30 //#include "MPIProcessorGroup.hxx"
31 #include "MPIAccess.hxx"
33 // use this define to enable lines, execution of which leads to Segmentation Fault
36 // use this define to enable CPPUNIT asserts and fails, showing bugs
37 #define ENABLE_FORCED_FAILURES
40 using namespace ParaMEDMEM;
42 void MPIAccessTest::test_MPI_Access_Probe() {
44 cout << "test_MPI_Access_Probe" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 cout << "test_MPI_Access_Probe must be runned with 2 procs" << endl ;
55 CPPUNIT_FAIL("test_MPI_Access_Probe must be runned with 2 procs") ;
58 cout << "test_MPI_Access_Probe" << myrank << endl ;
60 ParaMEDMEM::CommInterface interface ;
62 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
64 ParaMEDMEM::MPIAccess mpi_access( group ) ;
67 mpi_access.barrier() ;
72 int target = 1 - myrank ;
76 for ( i = 0 ; i < 10 ; i++ ) {
78 sts = mpi_access.send(&i,1,MPI_INT,target, RequestId[i]) ;
79 cout << "test" << myrank << " Send RequestId " << RequestId[i]
83 int source, tag, outcount ;
84 MPI_Datatype datatype ;
85 sts = mpi_access.probe(target, source, tag, datatype, outcount ) ;
86 cout << "test" << myrank << " Probe target " << target << " source " << source
87 << " tag " << tag << " outcount " << outcount << endl ;
89 sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
91 if ( (outcount != 1) | (recvbuf != i) ) {
92 ostringstream strstream ;
93 strstream << "==========================================================="
94 << "test" << myrank << " outcount " << outcount
95 << " recvbuf " << recvbuf << " KO"
96 << "==========================================================="
98 cout << strstream.str() << endl ;
99 CPPUNIT_FAIL( strstream.str() ) ;
102 char msgerr[MPI_MAX_ERROR_STRING] ;
104 mpi_access.errorString(sts, msgerr, &lenerr) ;
105 cout << "test" << myrank << " lenerr " << lenerr << " "
108 if ( sts != MPI_SUCCESS ) {
109 ostringstream strstream ;
110 strstream << "==========================================================="
111 << "test" << myrank << " KO"
112 << "==========================================================="
114 cout << strstream.str() << endl ;
115 CPPUNIT_FAIL( strstream.str() ) ;
120 mpi_access.testAll(10,RequestId,flag) ;
122 ostringstream strstream ;
123 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
124 cout << strstream.str() << endl ;
125 CPPUNIT_FAIL( strstream.str() ) ;
127 mpi_access.waitAll(10,RequestId) ;
130 mpi_access.barrier() ;
136 cout << "test" << myrank << " OK" << endl ;