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_Send_Recv_Length() {
45 cout << "test_MPI_Access_Send_Recv_Length" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 ostringstream strstream ;
56 strstream << "test_MPI_Access_Send_Recv_Length must be runned with 2 procs" << endl ;
57 cout << strstream.str() << endl ;
58 CPPUNIT_FAIL( strstream.str() ) ;
61 cout << "test_MPI_Access_Send_Recv_Length" << myrank << endl ;
63 ParaMEDMEM::CommInterface interface ;
65 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
67 ParaMEDMEM::MPIAccess mpi_access( group ) ;
70 mpi_access.barrier() ;
75 int target = 1 - myrank ;
82 for ( i = 0 ; i < 9000 ; i++ ) {
85 for ( i = 0 ; i < 10 ; i++ ) {
87 sts = mpi_access.send( sendbuf, 1000*i, MPI_INT, target, RequestId[i] ) ;
88 cout << "test" << myrank << " Send RequestId " << RequestId[i]
89 << " tag " << mpi_access.sendMPITag(target) << endl ;
96 sts = mpi_access.recv( recvbuf,1000*i+1,MPI_INT,target, RequestId[i],
99 //int source, tag, error, outcount ;
100 //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ;
101 cout << "test" << myrank << " Recv RequestId " << RequestId[i]
102 << " tag " << mpi_access.recvMPITag(target)
103 << " outcount " << outcount << endl ;
105 for ( j = 0 ; j < outcount ; j++ ) {
106 if ( recvbuf[j] != j ) {
107 cout << "test" << myrank << " recvbuf[ " << j << " ] = " << recvbuf[j]
113 if ( (outcount != 1000*i) | !recvbufok ) {
114 ostringstream strstream ;
115 strstream << "==========================================================="
116 << endl << "test" << myrank << " outcount " << outcount
117 << " recvbuf " << recvbuf << " KO"
118 << "==========================================================="
120 cout << strstream.str() << endl ;
121 CPPUNIT_FAIL( strstream.str() ) ;
124 char msgerr[MPI_MAX_ERROR_STRING] ;
126 mpi_access.errorString(sts, msgerr, &lenerr) ;
127 cout << "test" << myrank << " lenerr " << lenerr << " "
130 if ( sts != MPI_SUCCESS ) {
131 ostringstream strstream ;
132 strstream << "==========================================================="
133 << "test" << myrank << " KO"
134 << "==========================================================="
136 cout << strstream.str() << endl ;
137 CPPUNIT_FAIL( strstream.str() ) ;
142 mpi_access.testAll(10,RequestId,flag) ;
144 ostringstream strstream ;
145 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
146 cout << strstream.str() << endl ;
147 CPPUNIT_FAIL( strstream.str() ) ;
149 mpi_access.waitAll(10,RequestId) ;
153 int sendrequests[10] ;
154 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
155 if ( sendreqsize != 0 ) {
156 ostringstream strstream ;
157 strstream << "=========================================================" << endl
158 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
159 << "=========================================================" << endl ;
160 cout << strstream.str() << endl ;
161 CPPUNIT_FAIL( strstream.str() ) ;
165 int recvrequests[10] ;
166 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
167 if ( recvreqsize != 0 ) {
168 ostringstream strstream ;
169 strstream << "=========================================================" << endl
170 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
171 << "=========================================================" << endl ;
172 cout << strstream.str() << endl ;
173 CPPUNIT_FAIL( strstream.str() ) ;
177 mpi_access.barrier() ;
183 cout << "test" << myrank << " OK" << endl ;