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_Send_Recv() {
44 cout << "test_MPI_Access_Send_Recv" << endl ;
48 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
49 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
52 cout << "test_MPI_Access_Send_Recv must be runned with 2 procs" << endl ;
53 CPPUNIT_FAIL("test_MPI_Access_Send_Recv must be runned with 2 procs") ;
56 cout << "test_MPI_Access_Send_Recv" << myrank << endl ;
58 ParaMEDMEM::CommInterface interface ;
60 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
62 ParaMEDMEM::MPIAccess mpi_access( group ) ;
65 mpi_access.barrier() ;
70 int target = 1 - myrank ;
74 for ( i = 0 ; i < 10 ; i++ ) {
76 sts = mpi_access.send(&i,1,MPI_INT,target, RequestId[i]) ;
77 cout << "test" << myrank << " Send RequestId " << RequestId[i]
78 << " tag " << mpi_access.sendMPITag(target) << endl ;
83 sts = mpi_access.recv(&recvbuf,1,MPI_INT,target, RequestId[i],&outcount) ;
84 //int source, tag, error, outcount ;
85 //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ;
86 cout << "test" << myrank << " Recv RequestId " << RequestId[i]
87 << " tag " << mpi_access.recvMPITag(target)
88 << " outcount " << outcount << endl ;
89 if ( (outcount != 1) | (recvbuf != i) ) {
90 ostringstream strstream ;
91 strstream << "==========================================================="
92 << "test" << myrank << " outcount " << outcount
93 << " recvbuf " << recvbuf << " KO"
94 << "==========================================================="
96 cout << strstream.str() << endl ;
97 CPPUNIT_FAIL( strstream.str() ) ;
100 char msgerr[MPI_MAX_ERROR_STRING] ;
102 mpi_access.errorString(sts, msgerr, &lenerr) ;
103 cout << "test" << myrank << " lenerr " << lenerr << " "
106 if ( sts != MPI_SUCCESS ) {
107 ostringstream strstream ;
108 strstream << "==========================================================="
109 << "test" << myrank << " KO"
110 << "==========================================================="
112 CPPUNIT_FAIL( strstream.str() ) ;
117 mpi_access.testAll(10,RequestId,flag) ;
119 ostringstream strstream ;
120 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
121 cout << strstream.str() << endl ;
122 CPPUNIT_FAIL( strstream.str() ) ;
124 mpi_access.waitAll(10,RequestId) ;
128 int sendrequests[10] ;
129 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
130 if ( sendreqsize != 0 ) {
131 ostringstream strstream ;
132 strstream << "=========================================================" << endl
133 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
134 << "=========================================================" << endl ;
135 cout << strstream.str() << endl ;
136 CPPUNIT_FAIL( strstream.str() ) ;
140 int recvrequests[10] ;
141 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
142 if ( recvreqsize != 0 ) {
143 ostringstream strstream ;
144 strstream << "=========================================================" << endl
145 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
146 << "=========================================================" << endl ;
147 cout << strstream.str() << endl ;
148 CPPUNIT_FAIL( strstream.str() ) ;
152 mpi_access.barrier() ;
158 cout << "test" << myrank << " OK" << endl ;