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
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_Send_Recv() {
45 cout << "test_MPI_Access_Send_Recv" << endl ;
49 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
50 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
53 cout << "test_MPI_Access_Send_Recv must be runned with 2 procs" << endl ;
54 CPPUNIT_FAIL("test_MPI_Access_Send_Recv must be runned with 2 procs") ;
57 cout << "test_MPI_Access_Send_Recv" << myrank << endl ;
59 ParaMEDMEM::CommInterface interface ;
61 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
63 ParaMEDMEM::MPIAccess mpi_access( group ) ;
66 mpi_access.barrier() ;
71 int target = 1 - myrank ;
75 for ( i = 0 ; i < 10 ; i++ ) {
77 sts = mpi_access.send(&i,1,MPI_INT,target, RequestId[i]) ;
78 cout << "test" << myrank << " Send RequestId " << RequestId[i]
79 << " tag " << mpi_access.sendMPITag(target) << endl ;
84 sts = mpi_access.recv(&recvbuf,1,MPI_INT,target, RequestId[i],&outcount) ;
85 //int source, tag, error, outcount ;
86 //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ;
87 cout << "test" << myrank << " Recv RequestId " << RequestId[i]
88 << " tag " << mpi_access.recvMPITag(target)
89 << " outcount " << outcount << endl ;
90 if ( (outcount != 1) | (recvbuf != i) ) {
91 ostringstream strstream ;
92 strstream << "==========================================================="
93 << "test" << myrank << " outcount " << outcount
94 << " recvbuf " << recvbuf << " KO"
95 << "==========================================================="
97 cout << strstream.str() << endl ;
98 CPPUNIT_FAIL( strstream.str() ) ;
101 char msgerr[MPI_MAX_ERROR_STRING] ;
103 mpi_access.errorString(sts, msgerr, &lenerr) ;
104 cout << "test" << myrank << " lenerr " << lenerr << " "
107 if ( sts != MPI_SUCCESS ) {
108 ostringstream strstream ;
109 strstream << "==========================================================="
110 << "test" << myrank << " KO"
111 << "==========================================================="
113 CPPUNIT_FAIL( strstream.str() ) ;
118 mpi_access.testAll(10,RequestId,flag) ;
120 ostringstream strstream ;
121 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
122 cout << strstream.str() << endl ;
123 CPPUNIT_FAIL( strstream.str() ) ;
125 mpi_access.waitAll(10,RequestId) ;
129 int sendrequests[10] ;
130 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
131 if ( sendreqsize != 0 ) {
132 ostringstream strstream ;
133 strstream << "=========================================================" << endl
134 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
135 << "=========================================================" << endl ;
136 cout << strstream.str() << endl ;
137 CPPUNIT_FAIL( strstream.str() ) ;
141 int recvrequests[10] ;
142 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
143 if ( recvreqsize != 0 ) {
144 ostringstream strstream ;
145 strstream << "=========================================================" << endl
146 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
147 << "=========================================================" << endl ;
148 cout << strstream.str() << endl ;
149 CPPUNIT_FAIL( strstream.str() ) ;
153 mpi_access.barrier() ;
159 cout << "test" << myrank << " OK" << endl ;