1 // Copyright (C) 2007-2015 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 "MPIAccessDECTest.hxx"
27 #include <cppunit/TestAssert.h>
29 //#include "CommInterface.hxx"
30 //#include "ProcessorGroup.hxx"
31 //#include "MPIProcessorGroup.hxx"
32 #include "MPIAccessDEC.hxx"
33 #include "LinearTimeInterpolator.hxx"
35 // use this define to enable lines, execution of which leads to Segmentation Fault
38 // use this define to enable CPPUNIT asserts and fails, showing bugs
39 #define ENABLE_FORCED_FAILURES
42 using namespace ParaMEDMEM;
44 void MPIAccessDECTest::test_AllToAllTimeDECSynchronousPointToPoint() {
45 test_AllToAllTimeDEC( false ) ;
47 void MPIAccessDECTest::test_AllToAllTimeDECAsynchronousPointToPoint() {
48 test_AllToAllTimeDEC( true ) ;
51 static void chksts( int sts , int myrank , ParaMEDMEM::MPIAccess * mpi_access ) {
52 char msgerr[MPI_MAX_ERROR_STRING] ;
54 if ( sts != MPI_SUCCESS ) {
55 mpi_access->errorString(sts, msgerr, &lenerr) ;
56 debugStream << "test_AllToAllTimeDEC" << myrank << " lenerr " << lenerr << " "
58 ostringstream strstream ;
59 strstream << "==========================================================="
60 << "test_AllToAllTimeDEC" << myrank << " KO"
61 << "==========================================================="
63 debugStream << strstream.str() << endl ;
64 CPPUNIT_FAIL( strstream.str() ) ;
69 void MPIAccessDECTest::test_AllToAllTimeDEC( bool Asynchronous ) {
71 debugStream << "test_AllToAllTimeDEC" << endl ;
73 // MPI_Init(&argc, &argv) ;
77 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
78 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
80 if ( size < 2 || size > 11 ) {
81 ostringstream strstream ;
82 strstream << "usage :" << endl
83 << "mpirun -np <nbprocs> test_AllToAllTimeDEC" << endl
84 << " (nbprocs >=2)" << endl
85 << "test must be runned with more than 1 proc and less than 12 procs"
87 cerr << strstream.str() << endl ;
88 CPPUNIT_FAIL( strstream.str() ) ;
91 // int Asynchronous = atoi(argv[1]);
93 debugStream << "test_AllToAllTimeDEC" << myrank << " Asynchronous " << Asynchronous << endl ;
95 ParaMEDMEM::CommInterface interface ;
96 std::set<int> sourceprocs;
97 std::set<int> targetprocs;
99 for ( i = 0 ; i < size/2 ; i++ ) {
100 sourceprocs.insert(i);
102 for ( i = size/2 ; i < size ; i++ ) {
103 targetprocs.insert(i);
106 ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ;
107 ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ;
109 // LinearTimeInterpolator * aLinearInterpDEC = new LinearTimeInterpolator( 0.5 ) ;
110 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
112 // Asynchronous , LinearInterp , 0.5 ) ;
113 MyMPIAccessDEC->setTimeInterpolator( LinearTimeInterp ) ;
114 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
116 debugStream << "test_AllToAllTimeDEC" << myrank << " Barrier :" << endl ;
117 mpi_access->barrier() ;
118 debugStream << "test_AllToAllTimeDEC" << myrank << " Barrier done" << endl ;
122 #define datamsglength 10
125 int sendcount = datamsglength ;
126 int recvcount = datamsglength ;
129 // double deltatime[maxproc] = {1.,2.1,3.2,4.3,5.4,6.5,7.6,8.7,9.8,10.9,11.} ;
130 double deltatime[maxproc] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.} ;
131 double maxtime = maxreq ;
132 double nextdeltatime = deltatime[myrank] ;
133 // MyMPIAccessDEC->InitTime( time , deltatime[myrank] , maxtime ) ;
134 // for ( time = 0 ; time <= maxtime ; time+=deltatime[myrank] ) {
135 for ( time = 0 ; time <= maxtime && nextdeltatime != 0 ; time+=nextdeltatime ) {
137 nextdeltatime = deltatime[myrank] ;
138 if ( time+nextdeltatime > maxtime ) {
141 // MyMPIAccessDEC->NextTime( nextdeltatime ) ;
143 MyMPIAccessDEC->setTime( time , nextdeltatime ) ;
144 debugStream << "test_AllToAllTimeDEC" << myrank << "=====TIME " << time << "=====DELTATIME "
145 << nextdeltatime << "=====MAXTIME " << maxtime << " ======" << endl ;
146 int * sendbuf = new int[datamsglength*size] ;
147 // int * sendbuf = (int *) malloc(sizeof(int)*datamsglength*size) ;
148 int * recvbuf = new int[datamsglength*size] ;
150 for ( j = 0 ; j < datamsglength*size ; j++ ) {
151 sendbuf[j] = myrank*1000000 + (j/datamsglength)*1000 + j ;
155 int sts = MyMPIAccessDEC->allToAllTime( sendbuf, sendcount , MPI_INT ,
156 recvbuf, recvcount , MPI_INT ) ;
157 chksts( sts , myrank , mpi_access ) ;
159 // debugStream << "test_AllToAllTimeDEC" << myrank << " recvbuf before CheckSent" ;
160 // for ( i = 0 ; i < datamsglength*size ; i++ ) {
161 // debugStream << " " << recvbuf[i] ;
163 // debugStream << endl ;
165 // debugStream << "test_AllToAllTimeDEC" << myrank << " sendbuf " << sendbuf << endl ;
166 // MyMPIAccessDEC->CheckSent() ;
168 int nRecvReq = mpi_access->recvRequestIdsSize() ;
169 if ( nRecvReq != 0 ) {
170 ostringstream strstream ;
171 strstream << "=============================================================" << endl
172 << "test_AllToAllTimeDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests # 0 ERROR"
173 << endl << "============================================================="
175 int *ArrayOfRecvRequests = new int[nRecvReq] ;
176 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
177 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
178 delete [] ArrayOfRecvRequests ;
179 debugStream << strstream.str() << endl ;
180 CPPUNIT_FAIL( strstream.str() ) ;
183 // debugStream << "test_AllToAllTimeDEC" << myrank << " recvbuf" << endl ;
184 bool badrecvbuf = false ;
185 for ( i = 0 ; i < datamsglength*size ; i++ ) {
186 if ( recvbuf[i] != (i/datamsglength)*1000000 + myrank*1000 +
187 myrank*datamsglength+(i%datamsglength) ) {
189 debugStream << "test_AllToAllTimeDEC" << myrank << " recvbuf[" << i << "] "
190 << recvbuf[i] << " # " << (i/datamsglength)*1000000 + myrank*1000 +
191 myrank*datamsglength+(i%datamsglength) << endl ;
193 else if ( badrecvbuf ) {
194 debugStream << "test_AllToAllTimeDEC" << myrank << " recvbuf[" << i << "] "
195 << recvbuf[i] << " == " << (i/datamsglength)*1000000 + myrank*1000 +
196 myrank*datamsglength+(i%datamsglength) << endl ;
200 ostringstream strstream ;
201 strstream << "==============================================================" << endl
202 << "test_AllToAllTimeDEC" << myrank << " badrecvbuf"
203 << endl << "============================================================="
205 debugStream << strstream.str() << endl ;
206 CPPUNIT_FAIL( strstream.str() ) ;
211 debugStream << "test_AllToAllTimeDEC" << myrank << " final CheckSent" << endl ;
212 sts = MyMPIAccessDEC->checkSent() ;
213 if ( sts != MPI_SUCCESS ) {
214 ostringstream strstream ;
215 strstream << "================================================================" << endl
216 << "test_AllToAllTimeDEC" << myrank << " final CheckSent ERROR"
217 << endl << "================================================================"
219 debugStream << strstream.str() << endl ;
220 CPPUNIT_FAIL( strstream.str() ) ;
223 int nSendReq = mpi_access->sendRequestIdsSize() ;
224 debugStream << "test_AllToAllTimeDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
227 int *ArrayOfSendRequests = new int[nSendReq] ;
228 int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
229 mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
230 delete [] ArrayOfSendRequests ;
233 int nRecvReq = mpi_access->recvRequestIdsSize() ;
235 ostringstream strstream ;
236 strstream << "===============================================================" << endl
237 << "test_AllToAllTimeDEC" << myrank << " RecvRequestIds " << nRecvReq
238 << " RecvRequests # 0 Error"
239 << endl << "==============================================================="
241 debugStream << strstream.str() << endl ;
242 CPPUNIT_FAIL( strstream.str() ) ;
245 debugStream << "test_AllToAllTimeDEC" << myrank << " RecvRequestIds " << nRecvReq
246 << " RecvRequests = 0 OK" << endl ;
249 debugStream << "test_AllToAllTimeDEC" << myrank << " Barrier :" << endl ;
250 mpi_access->barrier() ;
251 debugStream << "test_AllToAllTimeDEC" << myrank << " Barrier done" << endl ;
255 // delete aLinearInterpDEC ;
256 delete MyMPIAccessDEC ;
260 debugStream << "test_AllToAllTimeDEC" << myrank << " OK" << endl ;