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_ISendRecv() {
45 cout << "test_MPI_Access_ISendRecv" << 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_ISendRecv must be runned with 2 procs" << endl ;
56 CPPUNIT_FAIL("test_MPI_Access_ISendRecv must be runned with 2 procs") ;
59 cout << "test_MPI_Access_ISendRecv" << myrank << endl ;
61 ParaMEDMEM::CommInterface interface ;
63 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
65 ParaMEDMEM::MPIAccess mpi_access( group ) ;
68 mpi_access.barrier() ;
73 int target = 1 - myrank ;
74 int SendRequestId[10] ;
75 int RecvRequestId[10] ;
80 for ( i = 0 ; i < 10 ; i++ ) {
82 sts = mpi_access.ISendRecv(&sendbuf[i],1,MPI_INT,target, SendRequestId[i],
83 &recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
84 cout << "test" << myrank << " Send sendRequestId " << SendRequestId[i]
85 << " tag " << mpi_access.sendMPITag(target)
86 << " recvRequestId " << RecvRequestId[i]
87 << " tag " << mpi_access.recvMPITag(target) << endl ;
88 char msgerr[MPI_MAX_ERROR_STRING] ;
90 mpi_access.errorString(sts, msgerr, &lenerr) ;
91 cout << "test" << myrank << " lenerr " << lenerr
92 << " " << msgerr << endl ;
94 if ( sts != MPI_SUCCESS ) {
95 ostringstream strstream ;
96 strstream << "==========================================================="
97 << "test" << myrank << " KO"
98 << "==========================================================="
100 cout << strstream.str() << endl ;
101 CPPUNIT_FAIL( strstream.str() ) ;
104 for (j = 0 ; j <= i ; j++) {
107 cout << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j]
109 mpi_access.test( SendRequestId[j], flag ) ;
111 int target, tag, error, outcount ;
112 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
114 cout << "test" << myrank << " Send RequestId " << SendRequestId[j]
115 << " target " << target << " tag " << tag << " error " << error
117 mpi_access.deleteRequest( SendRequestId[j] ) ;
120 cout << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j]
122 mpi_access.test( RecvRequestId[j], flag ) ;
124 int source, tag, error, outcount ;
125 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
127 cout << "test" << myrank << " Recv RequestId" << j << " "
128 << RecvRequestId[j] << " source " << source << " tag " << tag
129 << " error " << error << " outcount " << outcount << endl ;
130 if ( (outcount != 1) | (recvbuf[j] != j) ) {
131 ostringstream strstream ;
132 strstream << "==========================================================="
133 << "test" << myrank << " outcount "
134 << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO"
135 << "==========================================================="
137 cout << strstream.str() << endl ;
138 CPPUNIT_FAIL( strstream.str() ) ;
142 mpi_access.errorString(sts, msgerr, &lenerr) ;
143 cout << "test" << myrank << " lenerr " << lenerr << " "
149 mpi_access.testAll(10,SendRequestId,flag) ;
150 mpi_access.waitAll(10,SendRequestId) ;
151 mpi_access.deleteRequests(10,SendRequestId) ;
152 mpi_access.testAll(10,SendRequestId,flag) ;
154 ostringstream strstream ;
155 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
156 cout << strstream.str() << endl ;
157 CPPUNIT_FAIL( strstream.str() ) ;
160 mpi_access.testAll(10,RecvRequestId,flag) ;
161 mpi_access.waitAll(10,RecvRequestId) ;
162 mpi_access.deleteRequests(10,RecvRequestId) ;
163 mpi_access.testAll(10,RecvRequestId,flag) ;
165 ostringstream strstream ;
166 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
167 cout << strstream.str() << endl ;
168 CPPUNIT_FAIL( strstream.str() ) ;
172 int sendrequests[10] ;
173 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
174 if ( sendreqsize != 0 ) {
175 ostringstream strstream ;
176 strstream << "=========================================================" << endl
177 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
178 << "=========================================================" << endl ;
179 cout << strstream.str() << endl ;
180 CPPUNIT_FAIL( strstream.str() ) ;
183 cout << "=========================================================" << endl
184 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
185 << "=========================================================" << endl ;
187 int recvrequests[10] ;
188 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
189 if ( recvreqsize != 0 ) {
190 ostringstream strstream ;
191 strstream << "=========================================================" << endl
192 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
193 << "=========================================================" << endl ;
194 cout << strstream.str() << endl ;
195 CPPUNIT_FAIL( strstream.str() ) ;
198 cout << "=========================================================" << endl
199 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
200 << "=========================================================" << endl ;
203 mpi_access.barrier() ;
209 cout << "test" << myrank << " OK" << endl ;