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_Send_Recv_Length() {
44 cout << "test_MPI_Access_Send_Recv_Length" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 ostringstream strstream ;
55 strstream << "test_MPI_Access_Send_Recv_Length must be runned with 2 procs" << endl ;
56 cout << strstream.str() << endl ;
57 CPPUNIT_FAIL( strstream.str() ) ;
60 cout << "test_MPI_Access_Send_Recv_Length" << myrank << endl ;
62 ParaMEDMEM::CommInterface interface ;
64 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
66 ParaMEDMEM::MPIAccess mpi_access( group ) ;
69 mpi_access.barrier() ;
74 int target = 1 - myrank ;
81 for ( i = 0 ; i < 9000 ; i++ ) {
84 for ( i = 0 ; i < 10 ; i++ ) {
86 sts = mpi_access.send( sendbuf, 1000*i, MPI_INT, target, RequestId[i] ) ;
87 cout << "test" << myrank << " Send RequestId " << RequestId[i]
88 << " tag " << mpi_access.sendMPITag(target) << endl ;
95 sts = mpi_access.recv( recvbuf,1000*i+1,MPI_INT,target, RequestId[i],
98 //int source, tag, error, outcount ;
99 //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ;
100 cout << "test" << myrank << " Recv RequestId " << RequestId[i]
101 << " tag " << mpi_access.recvMPITag(target)
102 << " outcount " << outcount << endl ;
104 for ( j = 0 ; j < outcount ; j++ ) {
105 if ( recvbuf[j] != j ) {
106 cout << "test" << myrank << " recvbuf[ " << j << " ] = " << recvbuf[j]
112 if ( (outcount != 1000*i) | !recvbufok ) {
113 ostringstream strstream ;
114 strstream << "==========================================================="
115 << endl << "test" << myrank << " outcount " << outcount
116 << " recvbuf " << recvbuf << " KO"
117 << "==========================================================="
119 cout << strstream.str() << endl ;
120 CPPUNIT_FAIL( strstream.str() ) ;
123 char msgerr[MPI_MAX_ERROR_STRING] ;
125 mpi_access.errorString(sts, msgerr, &lenerr) ;
126 cout << "test" << myrank << " lenerr " << lenerr << " "
129 if ( sts != MPI_SUCCESS ) {
130 ostringstream strstream ;
131 strstream << "==========================================================="
132 << "test" << myrank << " KO"
133 << "==========================================================="
135 cout << strstream.str() << endl ;
136 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) ;
152 int sendrequests[10] ;
153 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
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() ) ;
164 int recvrequests[10] ;
165 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
166 if ( recvreqsize != 0 ) {
167 ostringstream strstream ;
168 strstream << "=========================================================" << endl
169 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
170 << "=========================================================" << endl ;
171 cout << strstream.str() << endl ;
172 CPPUNIT_FAIL( strstream.str() ) ;
176 mpi_access.barrier() ;
182 cout << "test" << myrank << " OK" << endl ;