1 // Copyright (C) 2007-2015 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 ParaMEDMEM;
43 void MPIAccessTest::test_MPI_Access_Probe() {
45 cout << "test_MPI_Access_Probe" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 cout << "test_MPI_Access_Probe must be runned with 2 procs" << endl ;
56 CPPUNIT_FAIL("test_MPI_Access_Probe must be runned with 2 procs") ;
59 cout << "test_MPI_Access_Probe" << myrank << endl ;
61 ParaMEDMEM::CommInterface interface ;
63 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
65 ParaMEDMEM::MPIAccess mpi_access( group ) ;
68 mpi_access.barrier() ;
73 int target = 1 - myrank ;
77 for ( i = 0 ; i < 10 ; i++ ) {
79 sts = mpi_access.send(&i,1,MPI_INT,target, RequestId[i]) ;
80 cout << "test" << myrank << " Send RequestId " << RequestId[i]
84 int source, tag, outcount ;
85 MPI_Datatype datatype ;
86 sts = mpi_access.probe(target, source, tag, datatype, outcount ) ;
87 cout << "test" << myrank << " Probe target " << target << " source " << source
88 << " tag " << tag << " outcount " << outcount << endl ;
90 sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
92 if ( (outcount != 1) | (recvbuf != i) ) {
93 ostringstream strstream ;
94 strstream << "==========================================================="
95 << "test" << myrank << " outcount " << outcount
96 << " recvbuf " << recvbuf << " KO"
97 << "==========================================================="
99 cout << strstream.str() << endl ;
100 CPPUNIT_FAIL( strstream.str() ) ;
103 char msgerr[MPI_MAX_ERROR_STRING] ;
105 mpi_access.errorString(sts, msgerr, &lenerr) ;
106 cout << "test" << myrank << " lenerr " << lenerr << " "
109 if ( sts != MPI_SUCCESS ) {
110 ostringstream strstream ;
111 strstream << "==========================================================="
112 << "test" << myrank << " KO"
113 << "==========================================================="
115 cout << strstream.str() << endl ;
116 CPPUNIT_FAIL( strstream.str() ) ;
121 mpi_access.testAll(10,RequestId,flag) ;
123 ostringstream strstream ;
124 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
125 cout << strstream.str() << endl ;
126 CPPUNIT_FAIL( strstream.str() ) ;
128 mpi_access.waitAll(10,RequestId) ;
131 mpi_access.barrier() ;
137 cout << "test" << myrank << " OK" << endl ;