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 "MPIAccessDECTest.hxx"
26 #include <cppunit/TestAssert.h>
28 //#include "CommInterface.hxx"
29 //#include "ProcessorGroup.hxx"
30 //#include "MPIProcessorGroup.hxx"
31 #include "MPIAccessDEC.hxx"
32 #include "LinearTimeInterpolator.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 MPIAccessDECTest::test_AllToAllTimeDECSynchronousPointToPoint() {
44 test_AllToAllTimeDEC( false ) ;
46 void MPIAccessDECTest::test_AllToAllTimeDECAsynchronousPointToPoint() {
47 test_AllToAllTimeDEC( true ) ;
50 static void chksts( int sts , int myrank , ParaMEDMEM::MPIAccess * mpi_access ) {
51 char msgerr[MPI_MAX_ERROR_STRING] ;
53 if ( sts != MPI_SUCCESS ) {
54 mpi_access->errorString(sts, msgerr, &lenerr) ;
55 cout << "test_AllToAllTimeDEC" << myrank << " lenerr " << lenerr << " "
57 ostringstream strstream ;
58 strstream << "==========================================================="
59 << "test_AllToAllTimeDEC" << myrank << " KO"
60 << "==========================================================="
62 cout << strstream.str() << endl ;
63 CPPUNIT_FAIL( strstream.str() ) ;
68 void MPIAccessDECTest::test_AllToAllTimeDEC( bool Asynchronous ) {
70 cout << "test_AllToAllTimeDEC" << endl ;
72 // MPI_Init(&argc, &argv) ;
76 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
77 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
79 if ( size < 2 || size > 11 ) {
80 ostringstream strstream ;
81 strstream << "usage :" << endl
82 << "mpirun -np <nbprocs> test_AllToAllTimeDEC" << endl
83 << " (nbprocs >=2)" << endl
84 << "test must be runned with more than 1 proc and less than 12 procs"
86 cout << strstream.str() << endl ;
87 CPPUNIT_FAIL( strstream.str() ) ;
90 // int Asynchronous = atoi(argv[1]);
92 cout << "test_AllToAllTimeDEC" << myrank << " Asynchronous " << Asynchronous << endl ;
94 ParaMEDMEM::CommInterface interface ;
95 std::set<int> sourceprocs;
96 std::set<int> targetprocs;
98 for ( i = 0 ; i < size/2 ; i++ ) {
99 sourceprocs.insert(i);
101 for ( i = size/2 ; i < size ; i++ ) {
102 targetprocs.insert(i);
105 ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ;
106 ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ;
108 // LinearTimeInterpolator * aLinearInterpDEC = new LinearTimeInterpolator( 0.5 ) ;
109 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
111 // Asynchronous , LinearInterp , 0.5 ) ;
112 MyMPIAccessDEC->setTimeInterpolator( LinearTimeInterp ) ;
113 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
115 cout << "test_AllToAllTimeDEC" << myrank << " Barrier :" << endl ;
116 mpi_access->barrier() ;
117 cout << "test_AllToAllTimeDEC" << myrank << " Barrier done" << endl ;
121 #define datamsglength 10
124 int sendcount = datamsglength ;
125 int recvcount = datamsglength ;
128 // double deltatime[maxproc] = {1.,2.1,3.2,4.3,5.4,6.5,7.6,8.7,9.8,10.9,11.} ;
129 double deltatime[maxproc] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.} ;
130 double maxtime = maxreq ;
131 double nextdeltatime = deltatime[myrank] ;
132 // MyMPIAccessDEC->InitTime( time , deltatime[myrank] , maxtime ) ;
133 // for ( time = 0 ; time <= maxtime ; time+=deltatime[myrank] ) {
134 for ( time = 0 ; time <= maxtime && nextdeltatime != 0 ; time+=nextdeltatime ) {
136 nextdeltatime = deltatime[myrank] ;
137 if ( time+nextdeltatime > maxtime ) {
140 // MyMPIAccessDEC->NextTime( nextdeltatime ) ;
142 MyMPIAccessDEC->setTime( time , nextdeltatime ) ;
143 cout << "test_AllToAllTimeDEC" << myrank << "=====TIME " << time << "=====DELTATIME "
144 << nextdeltatime << "=====MAXTIME " << maxtime << " ======" << endl ;
145 int * sendbuf = new int[datamsglength*size] ;
146 // int * sendbuf = (int *) malloc(sizeof(int)*datamsglength*size) ;
147 int * recvbuf = new int[datamsglength*size] ;
149 for ( j = 0 ; j < datamsglength*size ; j++ ) {
150 sendbuf[j] = myrank*1000000 + (j/datamsglength)*1000 + j ;
154 int sts = MyMPIAccessDEC->allToAllTime( sendbuf, sendcount , MPI_INT ,
155 recvbuf, recvcount , MPI_INT ) ;
156 chksts( sts , myrank , mpi_access ) ;
158 // cout << "test_AllToAllTimeDEC" << myrank << " recvbuf before CheckSent" ;
159 // for ( i = 0 ; i < datamsglength*size ; i++ ) {
160 // cout << " " << recvbuf[i] ;
164 // cout << "test_AllToAllTimeDEC" << myrank << " sendbuf " << sendbuf << endl ;
165 // MyMPIAccessDEC->CheckSent() ;
167 int nRecvReq = mpi_access->recvRequestIdsSize() ;
168 if ( nRecvReq != 0 ) {
169 ostringstream strstream ;
170 strstream << "=============================================================" << endl
171 << "test_AllToAllTimeDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests # 0 ERROR"
172 << endl << "============================================================="
174 int *ArrayOfRecvRequests = new int[nRecvReq] ;
175 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
176 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
177 delete [] ArrayOfRecvRequests ;
178 cout << strstream.str() << endl ;
179 CPPUNIT_FAIL( strstream.str() ) ;
182 // cout << "test_AllToAllTimeDEC" << myrank << " recvbuf" << endl ;
183 bool badrecvbuf = false ;
184 for ( i = 0 ; i < datamsglength*size ; i++ ) {
185 if ( recvbuf[i] != (i/datamsglength)*1000000 + myrank*1000 +
186 myrank*datamsglength+(i%datamsglength) ) {
188 cout << "test_AllToAllTimeDEC" << myrank << " recvbuf[" << i << "] "
189 << recvbuf[i] << " # " << (i/datamsglength)*1000000 + myrank*1000 +
190 myrank*datamsglength+(i%datamsglength) << endl ;
192 else if ( badrecvbuf ) {
193 cout << "test_AllToAllTimeDEC" << myrank << " recvbuf[" << i << "] "
194 << recvbuf[i] << " == " << (i/datamsglength)*1000000 + myrank*1000 +
195 myrank*datamsglength+(i%datamsglength) << endl ;
199 ostringstream strstream ;
200 strstream << "==============================================================" << endl
201 << "test_AllToAllTimeDEC" << myrank << " badrecvbuf"
202 << endl << "============================================================="
204 cout << strstream.str() << endl ;
205 CPPUNIT_FAIL( strstream.str() ) ;
210 cout << "test_AllToAllTimeDEC" << myrank << " final CheckSent" << endl ;
211 sts = MyMPIAccessDEC->checkSent() ;
212 if ( sts != MPI_SUCCESS ) {
213 ostringstream strstream ;
214 strstream << "================================================================" << endl
215 << "test_AllToAllTimeDEC" << myrank << " final CheckSent ERROR"
216 << endl << "================================================================"
218 cout << strstream.str() << endl ;
219 CPPUNIT_FAIL( strstream.str() ) ;
222 int nSendReq = mpi_access->sendRequestIdsSize() ;
223 cout << "test_AllToAllTimeDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
226 int *ArrayOfSendRequests = new int[nSendReq] ;
227 int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
228 mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
229 delete [] ArrayOfSendRequests ;
232 int nRecvReq = mpi_access->recvRequestIdsSize() ;
234 ostringstream strstream ;
235 strstream << "===============================================================" << endl
236 << "test_AllToAllTimeDEC" << myrank << " RecvRequestIds " << nRecvReq
237 << " RecvRequests # 0 Error"
238 << endl << "==============================================================="
240 cout << strstream.str() << endl ;
241 CPPUNIT_FAIL( strstream.str() ) ;
244 cout << "test_AllToAllTimeDEC" << myrank << " RecvRequestIds " << nRecvReq
245 << " RecvRequests = 0 OK" << endl ;
248 cout << "test_AllToAllTimeDEC" << myrank << " Barrier :" << endl ;
249 mpi_access->barrier() ;
250 cout << "test_AllToAllTimeDEC" << myrank << " Barrier done" << endl ;
254 // delete aLinearInterpDEC ;
255 delete MyMPIAccessDEC ;
259 cout << "test_AllToAllTimeDEC" << myrank << " OK" << endl ;