1 // Copyright (C) 2007-2015 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
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_Cyclic_Send_Recv() {
44 cout << "test_MPI_Access_Cyclic_Send_Recv" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 cout << "test_MPI_Access_Send_Recv must be runned with 3 procs" << endl ;
55 CPPUNIT_FAIL("test_MPI_Access_Send_Recv must be runned with 3 procs") ;
58 cout << "test_MPI_Access_Cyclic_Send_Recv" << 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 alltarget[3] = {1 , 2 , 0 } ;
73 int allsource[3] = {2 , 0 , 1 } ;
78 sts = mpi_access.send(&i,1,MPI_INT,alltarget[myrank], RequestId[i]) ;
79 cout << "test" << myrank << " Send RequestId " << RequestId[i]
80 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
82 for ( i = 0 ; i < 10 ; i++ ) {
87 sts = mpi_access.recv(&recvbuf,1,MPI_INT,allsource[myrank], RequestId[i],
91 sts = mpi_access.recv(&recvbuf,1,MPI_INT,allsource[myrank], RequestId[i]) ;
94 //int source, tag, error, outcount ;
95 //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ;
96 cout << "test" << myrank << " Recv RequestId " << RequestId[i]
97 << " tag " << mpi_access.recvMPITag(allsource[myrank])
98 << " outcount " << outcount << endl ;
99 if ( (outcount != 1) | (recvbuf != i) ) {
100 ostringstream strstream ;
101 strstream << "==========================================================="
102 << "test" << myrank << " outcount "
103 << outcount << " recvbuf " << recvbuf << " KO"
104 << "==========================================================="
106 cout << strstream.str() << endl ;
107 CPPUNIT_FAIL( strstream.str() ) ;
112 sts = mpi_access.send(&ii,1,MPI_INT,alltarget[myrank], RequestId[i]) ;
113 cout << "test" << myrank << " Send RequestId " << RequestId[i]
114 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
118 sts = mpi_access.send(&i,1,MPI_INT,alltarget[myrank], RequestId[i]) ;
119 cout << "test" << myrank << " Send RequestId " << RequestId[i]
120 << " tag " << mpi_access.sendMPITag(alltarget[myrank]) << endl ;
122 char msgerr[MPI_MAX_ERROR_STRING] ;
124 mpi_access.errorString(sts, msgerr, &lenerr) ;
125 cout << "test" << myrank << " lenerr " << lenerr
126 << " " << msgerr << endl ;
128 if ( sts != MPI_SUCCESS ) {
129 ostringstream strstream ;
130 strstream << "==========================================================="
131 << "test" << myrank << " KO"
132 << "==========================================================="
134 cout << strstream.str() << endl ;
135 CPPUNIT_FAIL( strstream.str() ) ;
141 mpi_access.testAll(10,RequestId,flag) ;
143 ostringstream strstream ;
144 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
145 cout << strstream.str() << endl ;
146 CPPUNIT_FAIL( strstream.str() ) ;
148 mpi_access.waitAll(10,RequestId) ;
151 int sendrequests[10] ;
152 int sendreqsize = mpi_access.sendRequestIds( alltarget[myrank] , 10 ,
154 if ( sendreqsize != 0 ) {
155 ostringstream strstream ;
156 strstream << "=========================================================" << endl
157 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
158 << "=========================================================" << endl ;
159 cout << strstream.str() << endl ;
160 CPPUNIT_FAIL( strstream.str() ) ;
162 int recvrequests[10] ;
163 int recvreqsize = mpi_access.sendRequestIds( allsource[myrank] , 10 ,
165 if ( recvreqsize != 0 ) {
166 ostringstream strstream ;
167 strstream << "=========================================================" << endl
168 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
169 << "=========================================================" << endl ;
170 cout << strstream.str() << endl ;
171 CPPUNIT_FAIL( strstream.str() ) ;
174 mpi_access.barrier() ;
180 cout << "test" << myrank << " OK" << endl ;