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_ISend_IRecv_Length() {
44 cout << "test_MPI_Access_ISend_IRecv_Length" << endl ;
46 // MPI_Init(&argc, &argv) ;
50 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
51 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
54 ostringstream strstream ;
55 strstream << "test_MPI_Access_ISend_IRecv_Length must be runned with 2 procs" << endl ;
56 cout << strstream.str() << endl ;
57 CPPUNIT_FAIL( strstream.str() ) ;
60 cout << "test_MPI_Access_ISend_IRecv_Length" << myrank << endl ;
62 ParaMEDMEM::CommInterface interface ;
64 ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
66 ParaMEDMEM::MPIAccess mpi_access( group ) ;
71 mpi_access.barrier() ;
76 int target = 1 - myrank ;
77 int SendRequestId[maxreq] ;
78 int RecvRequestId[maxreq] ;
80 int sendbuf[1000*(maxreq-1)] ;
81 int recvbuf[maxreq-1][1000*(maxreq-1)] ;
83 for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) {
86 for ( i = 0 ; i < maxreq ; i++ ) {
88 sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ;
89 cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
90 << " tag " << mpi_access.sendMPITag(target) << endl ;
93 sts = mpi_access.IRecv( recvbuf[i], 1000*i, MPI_INT, target,
95 cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
96 << " tag " << mpi_access.recvMPITag(target) << endl ;
99 for (j = 0 ; j <= i ; j++) {
102 mpi_access.test( SendRequestId[j], flag ) ;
105 mpi_access.test( RecvRequestId[j], flag ) ;
108 int target,source, tag, error, outcount ;
110 mpi_access.status( SendRequestId[j], target, tag, error, outcount,
112 cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
113 << ") : target " << target << " tag " << tag << " error " << error
114 << " flag " << flag << endl ;
117 mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
119 cout << "test" << myrank << " Test(Recv RequestId "
120 << RecvRequestId[j] << ") : source " << source << " tag " << tag
121 << " error " << error << " outcount " << outcount
122 << " flag " << flag << endl ;
123 if ( outcount != 0 ) {
124 if ( (outcount != 1000*j) |
125 (recvbuf[j][outcount-1] != (outcount-1)) ) {
126 ostringstream strstream ;
127 strstream << "==========================================================="
128 << endl << "test" << myrank << " outcount "
129 << outcount << " recvbuf " << recvbuf[j][outcount-1] << " KO"
131 << "==========================================================="
133 cout << strstream.str() << endl ;
134 CPPUNIT_FAIL( strstream.str() ) ;
137 cout << "==========================================================="
138 << endl << "test" << myrank << " outcount " << outcount
139 << " RequestId " << RecvRequestId[j] << " recvbuf "
140 << recvbuf[j][outcount-1] << " OK" << endl
141 << "==========================================================="
146 cout << "==========================================================="
147 << endl << "test" << myrank << " outcount " << outcount
148 << " RequestId " << RecvRequestId[j] << " OK" << endl
149 << "==========================================================="
155 char msgerr[MPI_MAX_ERROR_STRING] ;
157 mpi_access.errorString(sts, msgerr, &lenerr) ;
158 cout << "test" << myrank << " lenerr " << lenerr << " "
161 if ( sts != MPI_SUCCESS ) {
162 ostringstream strstream ;
163 strstream << "==========================================================="
164 << "test" << myrank << " KO"
165 << "==========================================================="
167 cout << strstream.str() << endl ;
168 CPPUNIT_FAIL( strstream.str() ) ;
173 cout << "test" << myrank << " WaitAll" << endl ;
175 mpi_access.waitAll(maxreq, SendRequestId) ;
176 mpi_access.deleteRequests(maxreq, SendRequestId) ;
179 mpi_access.waitAll(maxreq, RecvRequestId) ;
180 mpi_access.deleteRequests(maxreq, RecvRequestId) ;
185 int sendrequests[maxreq] ;
186 int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
187 sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
188 if ( sendreqsize != 0 ) {
189 ostringstream strstream ;
190 strstream << "=========================================================" << endl
191 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
192 << "=========================================================" << endl ;
193 cout << strstream.str() << endl ;
194 CPPUNIT_FAIL( strstream.str() ) ;
197 cout << "=========================================================" << endl
198 << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
199 << "=========================================================" << endl ;
203 int recvrequests[maxreq] ;
204 int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
205 if ( recvreqsize != 0 ) {
206 ostringstream strstream ;
207 strstream << "=========================================================" << endl
208 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
209 << "=========================================================" << endl ;
210 cout << strstream.str() << endl ;
211 CPPUNIT_FAIL( strstream.str() ) ;
214 cout << "=========================================================" << endl
215 << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
216 << "=========================================================" << endl ;
220 mpi_access.barrier() ;
226 cout << "test" << myrank << " OK" << endl ;