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
24 #include "MPIAccessTest.hxx"
25 #include <cppunit/TestAssert.h>
27 //#include "CommInterface.hxx"
28 //#include "ProcessorGroup.hxx"
29 //#include "MPIProcessorGroup.hxx"
30 #include "MPIAccess.hxx"
32 // use this define to enable lines, execution of which leads to Segmentation Fault
35 // use this define to enable CPPUNIT asserts and fails, showing bugs
36 #define ENABLE_FORCED_FAILURES
39 using namespace ParaMEDMEM;
41 void MPIAccessTest::test_MPI_Access_Cyclic_Send_Recv() {
43 cout << "test_MPI_Access_Cyclic_Send_Recv" << endl ;
45 // MPI_Init(&argc, &argv) ;
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 3 procs" << endl ;
54 CPPUNIT_FAIL("test_MPI_Access_Send_Recv must be runned with 3 procs") ;
57 cout << "test_MPI_Access_Cyclic_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 alltarget[3] = {1 , 2 , 0 } ;
72 int allsource[3] = {2 , 0 , 1 } ;
77 sts = mpi_access.send(&i,1,MPI_INT,alltarget[myrank], RequestId[i]) ;
78 cout << "test" << myrank << " Send RequestId " << RequestId[i]
79 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
81 for ( i = 0 ; i < 10 ; i++ ) {
86 sts = mpi_access.recv(&recvbuf,1,MPI_INT,allsource[myrank], RequestId[i],
90 sts = mpi_access.recv(&recvbuf,1,MPI_INT,allsource[myrank], RequestId[i]) ;
93 //int source, tag, error, outcount ;
94 //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ;
95 cout << "test" << myrank << " Recv RequestId " << RequestId[i]
96 << " tag " << mpi_access.recvMPITag(allsource[myrank])
97 << " outcount " << outcount << endl ;
98 if ( (outcount != 1) | (recvbuf != i) ) {
99 ostringstream strstream ;
100 strstream << "==========================================================="
101 << "test" << myrank << " outcount "
102 << outcount << " recvbuf " << recvbuf << " KO"
103 << "==========================================================="
105 cout << strstream.str() << endl ;
106 CPPUNIT_FAIL( strstream.str() ) ;
111 sts = mpi_access.send(&ii,1,MPI_INT,alltarget[myrank], RequestId[i]) ;
112 cout << "test" << myrank << " Send RequestId " << RequestId[i]
113 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
117 sts = mpi_access.send(&i,1,MPI_INT,alltarget[myrank], RequestId[i]) ;
118 cout << "test" << myrank << " Send RequestId " << RequestId[i]
119 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
121 char msgerr[MPI_MAX_ERROR_STRING] ;
123 mpi_access.errorString(sts, msgerr, &lenerr) ;
124 cout << "test" << myrank << " lenerr " << lenerr
125 << " " << msgerr << endl ;
127 if ( sts != MPI_SUCCESS ) {
128 ostringstream strstream ;
129 strstream << "==========================================================="
130 << "test" << myrank << " KO"
131 << "==========================================================="
133 cout << strstream.str() << endl ;
134 CPPUNIT_FAIL( strstream.str() ) ;
140 mpi_access.testAll(10,RequestId,flag) ;
142 ostringstream strstream ;
143 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
144 cout << strstream.str() << endl ;
145 CPPUNIT_FAIL( strstream.str() ) ;
147 mpi_access.waitAll(10,RequestId) ;
150 int sendrequests[10] ;
151 int sendreqsize = mpi_access.sendRequestIds( alltarget[myrank] , 10 ,
153 if ( sendreqsize != 0 ) {
154 ostringstream strstream ;
155 strstream << "=========================================================" << endl
156 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
157 << "=========================================================" << endl ;
158 cout << strstream.str() << endl ;
159 CPPUNIT_FAIL( strstream.str() ) ;
161 int recvrequests[10] ;
162 int recvreqsize = mpi_access.sendRequestIds( allsource[myrank] , 10 ,
164 if ( recvreqsize != 0 ) {
165 ostringstream strstream ;
166 strstream << "=========================================================" << endl
167 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
168 << "=========================================================" << endl ;
169 cout << strstream.str() << endl ;
170 CPPUNIT_FAIL( strstream.str() ) ;
173 mpi_access.barrier() ;
179 cout << "test" << myrank << " OK" << endl ;