1 // Copyright (C) 2007-2008 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
25 #include "MPIAccessTest.hxx"
26 #include <cppunit/TestAssert.h>
28 //#include "CommInterface.hxx"
29 //#include "ProcessorGroup.hxx"
30 //#include "MPIProcessorGroup.hxx"
31 #include "MPIAccess.hxx"
33 // use this define to enable lines, execution of which leads to Segmentation Fault
36 // use this define to enable CPPUNIT asserts and fails, showing bugs
37 #define ENABLE_FORCED_FAILURES
40 using namespace ParaMEDMEM;
42 void MPIAccessTest::test_MPI_Access_ISendRecv() {
44 cout << "test_MPI_Access_ISendRecv" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 cout << "test_MPI_Access_ISendRecv must be runned with 2 procs" << endl ;
55 CPPUNIT_FAIL("test_MPI_Access_ISendRecv must be runned with 2 procs") ;
58 cout << "test_MPI_Access_ISendRecv" << myrank << endl ;
60 ParaMEDMEM::CommInterface interface ;
62 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
64 ParaMEDMEM::MPIAccess mpi_access( group ) ;
67 mpi_access.barrier() ;
72 int target = 1 - myrank ;
73 int SendRequestId[10] ;
74 int RecvRequestId[10] ;
79 for ( i = 0 ; i < 10 ; i++ ) {
81 sts = mpi_access.ISendRecv(&sendbuf[i],1,MPI_INT,target, SendRequestId[i],
82 &recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
83 cout << "test" << myrank << " Send sendRequestId " << SendRequestId[i]
84 << " tag " << mpi_access.sendMPITag(target)
85 << " recvRequestId " << RecvRequestId[i]
86 << " tag " << mpi_access.recvMPITag(target) << endl ;
87 char msgerr[MPI_MAX_ERROR_STRING] ;
89 mpi_access.errorString(sts, msgerr, &lenerr) ;
90 cout << "test" << myrank << " lenerr " << lenerr
91 << " " << msgerr << endl ;
93 if ( sts != MPI_SUCCESS ) {
94 ostringstream strstream ;
95 strstream << "==========================================================="
96 << "test" << myrank << " KO"
97 << "==========================================================="
99 cout << strstream.str() << endl ;
100 CPPUNIT_FAIL( strstream.str() ) ;
103 for (j = 0 ; j <= i ; j++) {
106 cout << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j]
108 mpi_access.test( SendRequestId[j], flag ) ;
110 int target, tag, error, outcount ;
111 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
113 cout << "test" << myrank << " Send RequestId " << SendRequestId[j]
114 << " target " << target << " tag " << tag << " error " << error
116 mpi_access.deleteRequest( SendRequestId[j] ) ;
119 cout << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j]
121 mpi_access.test( RecvRequestId[j], flag ) ;
123 int source, tag, error, outcount ;
124 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
126 cout << "test" << myrank << " Recv RequestId" << j << " "
127 << RecvRequestId[j] << " source " << source << " tag " << tag
128 << " error " << error << " outcount " << outcount << endl ;
129 if ( (outcount != 1) | (recvbuf[j] != j) ) {
130 ostringstream strstream ;
131 strstream << "==========================================================="
132 << "test" << myrank << " outcount "
133 << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO"
134 << "==========================================================="
136 cout << strstream.str() << endl ;
137 CPPUNIT_FAIL( strstream.str() ) ;
141 mpi_access.errorString(sts, msgerr, &lenerr) ;
142 cout << "test" << myrank << " lenerr " << lenerr << " "
148 mpi_access.testAll(10,SendRequestId,flag) ;
149 mpi_access.waitAll(10,SendRequestId) ;
150 mpi_access.deleteRequests(10,SendRequestId) ;
151 mpi_access.testAll(10,SendRequestId,flag) ;
153 ostringstream strstream ;
154 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
155 cout << strstream.str() << endl ;
156 CPPUNIT_FAIL( strstream.str() ) ;
159 mpi_access.testAll(10,RecvRequestId,flag) ;
160 mpi_access.waitAll(10,RecvRequestId) ;
161 mpi_access.deleteRequests(10,RecvRequestId) ;
162 mpi_access.testAll(10,RecvRequestId,flag) ;
164 ostringstream strstream ;
165 strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
166 cout << strstream.str() << endl ;
167 CPPUNIT_FAIL( strstream.str() ) ;
171 int sendrequests[10] ;
172 int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
173 if ( sendreqsize != 0 ) {
174 ostringstream strstream ;
175 strstream << "=========================================================" << endl
176 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
177 << "=========================================================" << endl ;
178 cout << strstream.str() << endl ;
179 CPPUNIT_FAIL( strstream.str() ) ;
182 cout << "=========================================================" << endl
183 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
184 << "=========================================================" << endl ;
186 int recvrequests[10] ;
187 int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
188 if ( recvreqsize != 0 ) {
189 ostringstream strstream ;
190 strstream << "=========================================================" << endl
191 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
192 << "=========================================================" << endl ;
193 cout << strstream.str() << endl ;
194 CPPUNIT_FAIL( strstream.str() ) ;
197 cout << "=========================================================" << endl
198 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
199 << "=========================================================" << endl ;
202 mpi_access.barrier() ;
208 cout << "test" << myrank << " OK" << endl ;