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
27 #include "MPIAccessTest.hxx"
28 #include <cppunit/TestAssert.h>
30 //#include "CommInterface.hxx"
31 //#include "ProcessorGroup.hxx"
32 //#include "MPIProcessorGroup.hxx"
33 #include "MPIAccess.hxx"
35 // use this define to enable lines, execution of which leads to Segmentation Fault
38 // use this define to enable CPPUNIT asserts and fails, showing bugs
39 #define ENABLE_FORCED_FAILURES
42 using namespace ParaMEDMEM;
44 void MPIAccessTest::test_MPI_Access_ISend_IRecv_BottleNeck() {
46 cout << "test_MPI_Access_ISend_IRecv_BottleNeck" << endl ;
48 // MPI_Init(&argc, &argv) ;
52 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
53 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
56 ostringstream strstream ;
57 strstream << "test_MPI_Access_ISend_IRecv_BottleNeck must be runned with 2 procs"
59 cout << strstream.str() << endl ;
60 CPPUNIT_FAIL( strstream.str() ) ;
63 cout << "test_MPI_Access_ISend_IRecv_BottleNeck" << myrank << endl ;
65 ParaMEDMEM::CommInterface interface ;
67 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
69 ParaMEDMEM::MPIAccess mpi_access( group ) ;
74 mpi_access.barrier() ;
79 int target = 1 - myrank ;
80 int SendRequestId[maxreq] ;
81 int RecvRequestId[maxreq] ;
86 for ( i = 0 ; i < maxreq ; i++ ) {
89 sts = mpi_access.ISend(sendbuf,i,MPI_INT,target, SendRequestId[i]) ;
90 cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
91 << " tag " << mpi_access.sendMPITag(target) << endl ;
95 sts = mpi_access.IRecv(recvbuf,i,MPI_INT,target, RecvRequestId[i]) ;
96 cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
97 << " tag " << mpi_access.recvMPITag(target) << endl ;
98 int recvreqsize = mpi_access.recvRequestIdsSize() ;
99 int * recvrequests = new int[ recvreqsize ] ;
100 recvreqsize = mpi_access.recvRequestIds( target , recvreqsize , recvrequests ) ;
102 for (j = 0 ; j < recvreqsize ; j++) {
104 mpi_access.test( recvrequests[j], flag ) ;
106 int source, tag, error, outcount ;
107 mpi_access.status( recvrequests[j], source, tag, error, outcount,
109 cout << "test" << myrank << " Test(Recv RequestId "
110 << recvrequests[j] << ") : source " << source << " tag " << tag
111 << " error " << error << " outcount " << outcount
112 << " flag " << flag << " : DeleteRequest" << endl ;
113 mpi_access.deleteRequest( recvrequests[j] ) ;
116 // cout << "test" << myrank << " Test(Recv RequestId "
117 // << recvrequests[j] << ") flag " << flag << endl ;
120 delete [] recvrequests ;
122 if ( sts != MPI_SUCCESS ) {
123 char msgerr[MPI_MAX_ERROR_STRING] ;
125 mpi_access.errorString(sts, msgerr, &lenerr) ;
126 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() ) ;
143 int size = mpi_access.sendRequestIdsSize() ;
144 cout << "test" << myrank << " before WaitAll sendreqsize " << size << endl ;
145 mpi_access.waitAll(maxreq, SendRequestId) ;
146 size = mpi_access.sendRequestIdsSize() ;
147 cout << "test" << myrank << " after WaitAll sendreqsize " << size << endl ;
148 int * ArrayOfSendRequests = new int[ size ] ;
149 int nSendRequest = mpi_access.sendRequestIds( size , ArrayOfSendRequests ) ;
151 for ( i = 0 ; i < nSendRequest ; i++ ) {
152 mpi_access.deleteRequest( ArrayOfSendRequests[i] ) ;
154 delete [] ArrayOfSendRequests ;
157 int size = mpi_access.recvRequestIdsSize() ;
158 cout << "test" << myrank << " before WaitAll recvreqsize " << size << endl ;
159 mpi_access.waitAll(maxreq, RecvRequestId) ;
160 size = mpi_access.recvRequestIdsSize() ;
161 cout << "test" << myrank << " after WaitAll recvreqsize " << size << endl ;
162 int * ArrayOfRecvRequests = new int[ size ] ;
163 int nRecvRequest = mpi_access.recvRequestIds( size , ArrayOfRecvRequests ) ;
165 for ( i = 0 ; i < nRecvRequest ; i++ ) {
166 mpi_access.deleteRequest( ArrayOfRecvRequests[i] ) ;
168 delete [] ArrayOfRecvRequests ;
173 int sendrequests[maxreq] ;
174 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
176 if ( sendreqsize != 0 ) {
177 ostringstream strstream ;
178 strstream << "=========================================================" << endl
179 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
180 << "=========================================================" << endl ;
181 cout << strstream.str() << endl ;
182 for ( i = 0 ; i < sendreqsize ; i++ ) {
183 cout << "test" << myrank << " sendrequests[ " << i << " ] = "
184 << sendrequests[i] << endl ;
186 CPPUNIT_FAIL( strstream.str() ) ;
189 cout << "=========================================================" << endl
190 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
191 << "=========================================================" << endl ;
195 int recvrequests[maxreq] ;
196 int recvreqsize = mpi_access.recvRequestIds( target , maxreq , recvrequests ) ;
197 if ( recvreqsize != 0 ) {
198 ostringstream strstream ;
199 strstream << "=========================================================" << endl
200 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
201 << "=========================================================" << endl ;
202 cout << strstream.str() << endl ;
203 CPPUNIT_FAIL( strstream.str() ) ;
206 cout << "=========================================================" << endl
207 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
208 << "=========================================================" << endl ;
212 mpi_access.barrier() ;
218 cout << "test" << myrank << " OK" << endl ;