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_SendRecv() {
44 cout << "MPIAccessTest::test_MPI_Access_SendRecv" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 cout << "MPIAccessTest::test_MPI_Access_SendRecv must be runned with 2 procs" << endl ;
55 CPPUNIT_FAIL("test_MPI_Access_SendRecv must be runned with 2 procs") ;
58 cout << "MPIAccessTest::test_MPI_Access_SendRecv" << 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 ;
73 int sendRequestId[10] ;
74 int recvRequestId[10] ;
77 for ( i = 0 ; i < 10 ; i++ ) {
82 sts = mpi_access.sendRecv(&i,1,MPI_INT,target, sendRequestId[i],
83 &recvbuf,1,MPI_INT,target, recvRequestId[i],
87 sts = mpi_access.sendRecv(&i,1,MPI_INT,target, sendRequestId[i],
88 &recvbuf,1,MPI_INT,target, recvRequestId[i]) ;
89 // outcount = mpi_access.MPIOutCount( recvRequestId[i] ) ;
92 cout << "test" << myrank << " Send sendRequestId " << sendRequestId[i]
93 << " tag " << mpi_access.sendMPITag(target)
94 << " recvRequestId " << recvRequestId[i]
95 << " tag " << mpi_access.recvMPITag(target)
96 << " outcount " << outcount << " MPIOutCount "
97 << mpi_access.MPIOutCount( recvRequestId[i] ) << endl ;
98 if ( (outcount != 1) | (recvbuf != i) ) {
99 ostringstream strstream ;
100 strstream << "==========================================================="
101 << "test" << myrank << " outcount " << outcount
102 << " recvbuf " << recvbuf << " KO"
103 << "==========================================================="
105 cout << strstream.str() << endl ;
106 CPPUNIT_FAIL( strstream.str() ) ;
108 char msgerr[MPI_MAX_ERROR_STRING] ;
110 mpi_access.errorString(sts, msgerr, &lenerr) ;
111 cout << "test" << myrank << " lenerr " << lenerr << " "
114 if ( sts != MPI_SUCCESS ) {
115 ostringstream strstream ;
116 strstream << "==========================================================="
117 << "test" << myrank << " KO"
118 << "==========================================================="
120 cout << strstream.str() << endl ;
121 CPPUNIT_FAIL( strstream.str() ) ;
127 mpi_access.testAll(10,sendRequestId,flag) ;
129 ostringstream strstream ;
130 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
131 cout << strstream.str() << endl ;
132 CPPUNIT_FAIL( strstream.str() ) ;
134 mpi_access.waitAll(10,sendRequestId) ;
135 mpi_access.testAll(10,recvRequestId,flag) ;
137 ostringstream strstream ;
138 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
139 cout << strstream.str() << endl ;
140 CPPUNIT_FAIL( strstream.str() ) ;
142 mpi_access.waitAll(10,recvRequestId) ;
145 int sendrequests[10] ;
146 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
147 if ( sendreqsize != 0 ) {
148 ostringstream strstream ;
149 strstream << "=========================================================" << endl
150 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
151 << "=========================================================" << endl ;
152 cout << strstream.str() << endl ;
153 CPPUNIT_FAIL( strstream.str() ) ;
155 int recvrequests[10] ;
156 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
157 if ( recvreqsize != 0 ) {
158 ostringstream strstream ;
159 strstream << "=========================================================" << endl
160 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
161 << "=========================================================" << endl ;
162 cout << strstream.str() << endl ;
163 CPPUNIT_FAIL( strstream.str() ) ;
166 mpi_access.barrier() ;
172 cout << "test" << myrank << " OK" << endl ;