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_ISend_IRecv_Length() {
45 cout << "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 cout << strstream.str() << endl ;
58 CPPUNIT_FAIL( strstream.str() ) ;
61 cout << "test_MPI_Access_ISend_IRecv_Length" << myrank << endl ;
63 ParaMEDMEM::CommInterface interface ;
65 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
67 ParaMEDMEM::MPIAccess mpi_access( group ) ;
72 mpi_access.barrier() ;
77 int target = 1 - myrank ;
78 int SendRequestId[maxreq] ;
79 int RecvRequestId[maxreq] ;
81 int sendbuf[1000*(maxreq-1)] ;
82 int recvbuf[maxreq-1][1000*(maxreq-1)] ;
84 for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) {
87 for ( i = 0 ; i < maxreq ; i++ ) {
89 sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ;
90 cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
91 << " tag " << mpi_access.sendMPITag(target) << endl ;
94 sts = mpi_access.IRecv( recvbuf[i], 1000*i, MPI_INT, target,
96 cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
97 << " tag " << mpi_access.recvMPITag(target) << endl ;
100 for (j = 0 ; j <= i ; j++) {
103 mpi_access.test( SendRequestId[j], flag ) ;
106 mpi_access.test( RecvRequestId[j], flag ) ;
109 int target,source, tag, error, outcount ;
111 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
113 cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
114 << ") : target " << target << " tag " << tag << " error " << error
115 << " flag " << flag << endl ;
118 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
120 cout << "test" << myrank << " Test(Recv RequestId "
121 << RecvRequestId[j] << ") : source " << source << " tag " << tag
122 << " error " << error << " outcount " << outcount
123 << " flag " << flag << endl ;
124 if ( outcount != 0 ) {
125 if ( (outcount != 1000*j) |
126 (recvbuf[j][outcount-1] != (outcount-1)) ) {
127 ostringstream strstream ;
128 strstream << "==========================================================="
129 << endl << "test" << myrank << " outcount "
130 << outcount << " recvbuf " << recvbuf[j][outcount-1] << " KO"
132 << "==========================================================="
134 cout << strstream.str() << endl ;
135 CPPUNIT_FAIL( strstream.str() ) ;
138 cout << "==========================================================="
139 << endl << "test" << myrank << " outcount " << outcount
140 << " RequestId " << RecvRequestId[j] << " recvbuf "
141 << recvbuf[j][outcount-1] << " OK" << endl
142 << "==========================================================="
147 cout << "==========================================================="
148 << endl << "test" << myrank << " outcount " << outcount
149 << " RequestId " << RecvRequestId[j] << " OK" << endl
150 << "==========================================================="
156 char msgerr[MPI_MAX_ERROR_STRING] ;
158 mpi_access.errorString(sts, msgerr, &lenerr) ;
159 cout << "test" << myrank << " lenerr " << lenerr << " "
162 if ( sts != MPI_SUCCESS ) {
163 ostringstream strstream ;
164 strstream << "==========================================================="
165 << "test" << myrank << " KO"
166 << "==========================================================="
168 cout << strstream.str() << endl ;
169 CPPUNIT_FAIL( strstream.str() ) ;
174 cout << "test" << myrank << " WaitAll" << endl ;
176 mpi_access.waitAll(maxreq, SendRequestId) ;
177 mpi_access.deleteRequests(maxreq, SendRequestId) ;
180 mpi_access.waitAll(maxreq, RecvRequestId) ;
181 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
186 int sendrequests[maxreq] ;
187 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
188 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 cout << strstream.str() << endl ;
195 CPPUNIT_FAIL( strstream.str() ) ;
198 cout << "=========================================================" << endl
199 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
200 << "=========================================================" << endl ;
204 int recvrequests[maxreq] ;
205 int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
206 if ( recvreqsize != 0 ) {
207 ostringstream strstream ;
208 strstream << "=========================================================" << endl
209 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
210 << "=========================================================" << endl ;
211 cout << strstream.str() << endl ;
212 CPPUNIT_FAIL( strstream.str() ) ;
215 cout << "=========================================================" << endl
216 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
217 << "=========================================================" << endl ;
221 mpi_access.barrier() ;
227 cout << "test" << myrank << " OK" << endl ;