1 // Copyright (C) 2007-2014 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_SendRecv() {
45 cout << "MPIAccessTest::test_MPI_Access_SendRecv" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 cout << "MPIAccessTest::test_MPI_Access_SendRecv must be runned with 2 procs" << endl ;
56 CPPUNIT_FAIL("test_MPI_Access_SendRecv must be runned with 2 procs") ;
59 cout << "MPIAccessTest::test_MPI_Access_SendRecv" << 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 ;
74 int sendRequestId[10] ;
75 int recvRequestId[10] ;
78 for ( i = 0 ; i < 10 ; i++ ) {
83 sts = mpi_access.sendRecv(&i,1,MPI_INT,target, sendRequestId[i],
84 &recvbuf,1,MPI_INT,target, recvRequestId[i],
88 sts = mpi_access.sendRecv(&i,1,MPI_INT,target, sendRequestId[i],
89 &recvbuf,1,MPI_INT,target, recvRequestId[i]) ;
90 // outcount = mpi_access.MPIOutCount( recvRequestId[i] ) ;
93 cout << "test" << myrank << " Send sendRequestId " << sendRequestId[i]
94 << " tag " << mpi_access.sendMPITag(target)
95 << " recvRequestId " << recvRequestId[i]
96 << " tag " << mpi_access.recvMPITag(target)
97 << " outcount " << outcount << " MPIOutCount "
98 << mpi_access.MPIOutCount( recvRequestId[i] ) << endl ;
99 if ( (outcount != 1) | (recvbuf != i) ) {
100 ostringstream strstream ;
101 strstream << "==========================================================="
102 << "test" << myrank << " outcount " << outcount
103 << " recvbuf " << recvbuf << " KO"
104 << "==========================================================="
106 cout << strstream.str() << endl ;
107 CPPUNIT_FAIL( strstream.str() ) ;
109 char msgerr[MPI_MAX_ERROR_STRING] ;
111 mpi_access.errorString(sts, msgerr, &lenerr) ;
112 cout << "test" << myrank << " lenerr " << lenerr << " "
115 if ( sts != MPI_SUCCESS ) {
116 ostringstream strstream ;
117 strstream << "==========================================================="
118 << "test" << myrank << " KO"
119 << "==========================================================="
121 cout << strstream.str() << endl ;
122 CPPUNIT_FAIL( strstream.str() ) ;
128 mpi_access.testAll(10,sendRequestId,flag) ;
130 ostringstream strstream ;
131 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
132 cout << strstream.str() << endl ;
133 CPPUNIT_FAIL( strstream.str() ) ;
135 mpi_access.waitAll(10,sendRequestId) ;
136 mpi_access.testAll(10,recvRequestId,flag) ;
138 ostringstream strstream ;
139 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
140 cout << strstream.str() << endl ;
141 CPPUNIT_FAIL( strstream.str() ) ;
143 mpi_access.waitAll(10,recvRequestId) ;
146 int sendrequests[10] ;
147 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
148 if ( sendreqsize != 0 ) {
149 ostringstream strstream ;
150 strstream << "=========================================================" << endl
151 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
152 << "=========================================================" << endl ;
153 cout << strstream.str() << endl ;
154 CPPUNIT_FAIL( strstream.str() ) ;
156 int recvrequests[10] ;
157 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
158 if ( recvreqsize != 0 ) {
159 ostringstream strstream ;
160 strstream << "=========================================================" << endl
161 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
162 << "=========================================================" << endl ;
163 cout << strstream.str() << endl ;
164 CPPUNIT_FAIL( strstream.str() ) ;
167 mpi_access.barrier() ;
173 cout << "test" << myrank << " OK" << endl ;