1 // Copyright (C) 2007-2013 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
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() {
45 cout << "test_MPI_Access_ISend_IRecv" << endl ;
47 // MPI_Init(&argc, &argv) ;
51 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
52 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
55 cout << "test_MPI_Access_ISend_IRecv must be runned with 2 procs" << endl ;
56 CPPUNIT_FAIL("test_MPI_Access_ISend_IRecv must be runned with 2 procs") ;
59 cout << "test_MPI_Access_ISend_IRecv" << myrank << endl ;
61 ParaMEDMEM::CommInterface interface ;
63 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
65 ParaMEDMEM::MPIAccess mpi_access( group ) ;
70 mpi_access.barrier() ;
75 int target = 1 - myrank ;
76 int SendRequestId[maxreq] ;
77 int RecvRequestId[maxreq] ;
82 for ( i = 0 ; i < maxreq ; i++ ) {
85 sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, SendRequestId[i]) ;
86 cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
87 << " tag " << mpi_access.sendMPITag(target) << endl ;
90 sts = mpi_access.IRecv(&recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
91 cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
92 << " tag " << mpi_access.recvMPITag(target) << endl ;
95 for (j = 0 ; j <= i ; j++) {
98 mpi_access.test( SendRequestId[j], flag ) ;
101 mpi_access.test( RecvRequestId[j], flag ) ;
104 int target,source, tag, error, outcount ;
106 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
108 cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
109 << ") : target " << target << " tag " << tag << " error " << error
110 << " flag " << flag << endl ;
113 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
115 cout << "test" << myrank << " Test(Recv RequestId "
116 << RecvRequestId[j] << ") : source " << source << " tag " << tag
117 << " error " << error << " outcount " << outcount
118 << " flag " << flag << endl ;
119 if ( (outcount != 1) | (recvbuf[j] != j) ) {
120 ostringstream strstream ;
121 strstream << "==========================================================="
122 << endl << "test" << myrank << " outcount "
123 << outcount << " recvbuf " << recvbuf[j] << " KO" << endl
124 << "==========================================================="
126 cout << strstream.str() << endl ;
127 CPPUNIT_FAIL( strstream.str() ) ;
130 // cout << "==========================================================="
131 // << endl << "test" << myrank << " outcount " << outcount
132 // << " RequestId " << RecvRequestId[j] << " recvbuf "
133 // << recvbuf[j] << " OK" << endl
134 // << "==========================================================="
140 char msgerr[MPI_MAX_ERROR_STRING] ;
142 mpi_access.errorString(sts, msgerr, &lenerr) ;
143 cout << "test" << myrank << " lenerr " << lenerr << " "
146 if ( sts != MPI_SUCCESS ) {
147 ostringstream strstream ;
148 strstream << "==========================================================="
149 << "test" << myrank << " KO"
150 << "==========================================================="
152 cout << strstream.str() << endl ;
153 CPPUNIT_FAIL( strstream.str() ) ;
159 mpi_access.waitAll(maxreq, SendRequestId) ;
160 mpi_access.deleteRequests(maxreq, SendRequestId) ;
163 mpi_access.waitAll(maxreq, RecvRequestId) ;
164 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
169 int sendrequests[maxreq] ;
170 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
172 if ( sendreqsize != 0 ) {
173 ostringstream strstream ;
174 strstream << "=========================================================" << endl
175 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
176 << "=========================================================" << endl ;
177 cout << strstream.str() << endl ;
178 for ( i = 0 ; i < sendreqsize ; i++ ) {
179 cout << "test" << myrank << " sendrequests[ " << i << " ] = "
180 << sendrequests[i] << endl ;
182 CPPUNIT_FAIL( strstream.str() ) ;
185 cout << "=========================================================" << endl
186 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
187 << "=========================================================" << endl ;
191 int recvrequests[maxreq] ;
192 int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
193 if ( recvreqsize != 0 ) {
194 ostringstream strstream ;
195 strstream << "=========================================================" << endl
196 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
197 << "=========================================================" << endl ;
198 cout << strstream.str() << endl ;
199 CPPUNIT_FAIL( strstream.str() ) ;
202 cout << "=========================================================" << endl
203 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
204 << "=========================================================" << endl ;
208 mpi_access.barrier() ;
214 cout << "test" << myrank << " OK" << endl ;