1 // Copyright (C) 2007-2016 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 MEDCoupling;
43 void MPIAccessTest::test_MPI_Access_ISend_IRecv_Length() {
45 debugStream << "test_MPI_Access_ISend_IRecv_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_ISend_IRecv_Length must be runned with 2 procs" << endl ;
57 cerr << strstream.str() << endl ;
58 //CPPUNIT_FAIL( strstream.str() ) ;
62 debugStream << "test_MPI_Access_ISend_IRecv_Length" << myrank << endl ;
64 MEDCoupling::CommInterface interface ;
66 MEDCoupling::MPIProcessorGroup* group = new MEDCoupling::MPIProcessorGroup(interface) ;
68 MEDCoupling::MPIAccess mpi_access( group ) ;
73 mpi_access.barrier() ;
78 int target = 1 - myrank ;
79 int SendRequestId[maxreq] ;
80 int RecvRequestId[maxreq] ;
82 int sendbuf[1000*(maxreq-1)] ;
83 int recvbuf[maxreq][1000*(maxreq-1)] ;
85 for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) {
88 for ( i = 0 ; i < maxreq ; i++ ) {
90 sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ;
91 debugStream << "test" << myrank << " ISend RequestId " << SendRequestId[i]
92 << " tag " << mpi_access.sendMPITag(target) << endl ;
95 sts = mpi_access.IRecv( recvbuf[i], 1000*i, MPI_INT, target,
97 debugStream << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
98 << " tag " << mpi_access.recvMPITag(target) << endl ;
101 for (j = 0 ; j <= i ; j++) {
104 mpi_access.test( SendRequestId[j], flag ) ;
107 mpi_access.test( RecvRequestId[j], flag ) ;
110 int target,source, tag, error, outcount ;
112 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
114 debugStream << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
115 << ") : target " << target << " tag " << tag << " error " << error
116 << " flag " << flag << endl ;
119 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
121 debugStream << "test" << myrank << " Test(Recv RequestId "
122 << RecvRequestId[j] << ") : source " << source << " tag " << tag
123 << " error " << error << " outcount " << outcount
124 << " flag " << flag << endl ;
125 if ( outcount != 0 ) {
126 if ( (outcount != 1000*j) |
127 (recvbuf[j][outcount-1] != (outcount-1)) ) {
128 ostringstream strstream ;
129 strstream << "==========================================================="
130 << endl << "test" << myrank << " outcount "
131 << outcount << " recvbuf " << recvbuf[j][outcount-1] << " KO"
133 << "==========================================================="
135 debugStream << strstream.str() << endl ;
136 CPPUNIT_FAIL( strstream.str() ) ;
139 debugStream << "==========================================================="
140 << endl << "test" << myrank << " outcount " << outcount
141 << " RequestId " << RecvRequestId[j] << " recvbuf "
142 << recvbuf[j][outcount-1] << " OK" << endl
143 << "==========================================================="
148 debugStream << "==========================================================="
149 << endl << "test" << myrank << " outcount " << outcount
150 << " RequestId " << RecvRequestId[j] << " OK" << endl
151 << "==========================================================="
157 char msgerr[MPI_MAX_ERROR_STRING] ;
159 mpi_access.errorString(sts, msgerr, &lenerr) ;
160 debugStream << "test" << myrank << " lenerr " << lenerr << " "
163 if ( sts != MPI_SUCCESS ) {
164 ostringstream strstream ;
165 strstream << "==========================================================="
166 << "test" << myrank << " KO"
167 << "==========================================================="
169 debugStream << strstream.str() << endl ;
170 CPPUNIT_FAIL( strstream.str() ) ;
174 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
175 debugStream << "test" << myrank << " WaitAll" << endl ;
177 mpi_access.waitAll(maxreq, SendRequestId) ;
178 mpi_access.deleteRequests(maxreq, SendRequestId) ;
181 mpi_access.waitAll(maxreq, RecvRequestId) ;
182 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
184 if(MPI_ACCESS_VERBOSE) mpi_access.check() ;
187 int sendrequests[maxreq] ;
188 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
189 if ( sendreqsize != 0 ) {
190 ostringstream strstream ;
191 strstream << "=========================================================" << endl
192 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
193 << "=========================================================" << endl ;
194 debugStream << strstream.str() << endl ;
195 CPPUNIT_FAIL( strstream.str() ) ;
198 debugStream << "=========================================================" << endl
199 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
200 << "=========================================================" << endl ;
204 int recvrequests[maxreq] ;
205 int recvreqsize = mpi_access.recvRequestIds( target , maxreq , recvrequests ) ;
206 if ( recvreqsize != 0 ) {
207 ostringstream strstream ;
208 strstream << "=========================================================" << endl
209 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
210 << "=========================================================" << endl ;
211 debugStream << strstream.str() << endl ;
212 CPPUNIT_FAIL( strstream.str() ) ;
215 debugStream << "=========================================================" << endl
216 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
217 << "=========================================================" << endl ;
221 mpi_access.barrier() ;
227 debugStream << "test" << myrank << " OK" << endl ;