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
27 #include "MPIAccessDECTest.hxx"
28 #include <cppunit/TestAssert.h>
30 //#include "CommInterface.hxx"
31 //#include "ProcessorGroup.hxx"
32 //#include "MPIProcessorGroup.hxx"
33 #include "MPIAccessDEC.hxx"
34 #include "LinearTimeInterpolator.hxx"
36 // use this define to enable lines, execution of which leads to Segmentation Fault
39 // use this define to enable CPPUNIT asserts and fails, showing bugs
40 #define ENABLE_FORCED_FAILURES
43 using namespace ParaMEDMEM;
45 void MPIAccessDECTest::test_AllToAllvTimeDoubleDECSynchronousPointToPoint() {
46 test_AllToAllvTimeDoubleDEC( false ) ;
48 void MPIAccessDECTest::test_AllToAllvTimeDoubleDECAsynchronousPointToPoint() {
49 test_AllToAllvTimeDoubleDEC( true ) ;
52 static void chksts( int sts , int myrank , ParaMEDMEM::MPIAccess * mpi_access ) {
53 char msgerr[MPI_MAX_ERROR_STRING] ;
55 if ( sts != MPI_SUCCESS ) {
56 mpi_access->errorString(sts, msgerr, &lenerr) ;
57 cout << "test" << myrank << " lenerr " << lenerr << " "
59 ostringstream strstream ;
60 strstream << "==========================================================="
61 << "test" << myrank << " KO"
62 << "==========================================================="
64 cout << strstream.str() << endl ;
65 CPPUNIT_FAIL( strstream.str() ) ;
70 void MPIAccessDECTest::test_AllToAllvTimeDoubleDEC( bool Asynchronous ) {
72 cout << "test_AllToAllvTimeDoubleDEC" << endl ;
74 // MPI_Init(&argc, &argv) ;
78 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
79 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
81 if ( size < 2 || size > 11 ) {
82 ostringstream strstream ;
83 strstream << "usage :" << endl
84 << "mpirun -np <nbprocs> test_AllToAllTimeDEC" << endl
85 << " (nbprocs >=2)" << endl
86 << "test must be runned with more than 1 proc and less than 12 procs"
88 cout << strstream.str() << endl ;
89 CPPUNIT_FAIL( strstream.str() ) ;
92 // int Asynchronous = atoi(argv[1]) ;
94 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " Asynchronous " << Asynchronous << endl ;
96 ParaMEDMEM::CommInterface interface ;
97 std::set<int> sourceprocs;
98 std::set<int> targetprocs;
100 for ( i = 0 ; i < size/2 ; i++ ) {
101 sourceprocs.insert(i);
103 for ( i = size/2 ; i < size ; i++ ) {
104 targetprocs.insert(i);
107 ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ;
108 ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ;
110 // TimeInterpolator * aLinearInterpDEC = new LinearTimeInterpolator( 0 ) ;
111 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
113 // Asynchronous , LinearInterp , 0.5 ) ;
114 MyMPIAccessDEC->setTimeInterpolator( LinearTimeInterp ) ;
115 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
117 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " Barrier :" << endl ;
118 mpi_access->barrier() ;
122 #define datamsglength 10
125 int *sendcounts = new int[size] ;
126 int *sdispls = new int[size] ;
127 int *recvcounts = new int[size] ;
128 int *rdispls = new int[size] ;
129 int *sendtimecounts = new int[size] ;
130 int *stimedispls = new int[size] ;
131 int *recvtimecounts = new int[size] ;
132 int *rtimedispls = new int[size] ;
133 for ( i = 0 ; i < size ; i++ ) {
134 sendcounts[i] = datamsglength-i ;
135 sdispls[i] = i*datamsglength ;
136 recvcounts[i] = datamsglength-myrank ;
137 rdispls[i] = i*datamsglength ;
138 sendtimecounts[i] = 1 ;
140 recvtimecounts[i] = 1 ;
144 double time[maxproc] ;
145 double deltatime[maxproc] = {1.,2.1,3.2,4.3,5.4,6.5,7.6,8.7,9.8,10.9,11.} ;
146 double maxtime[maxproc] ;
147 double nextdeltatime[maxproc] ;
148 for ( i = 0 ; i < size ; i++ ) {
150 maxtime[i] = maxreq ;
151 nextdeltatime[i] = deltatime[i] ;
153 time_t begintime = std::time(NULL) ;
154 for ( time[myrank] = 0 ; time[myrank] <= maxtime[myrank] && nextdeltatime[myrank] != 0 ;
155 time[myrank]+=nextdeltatime[myrank] ) {
156 //local and target times
158 for ( target = 0 ; target < size ; target++ ) {
159 nextdeltatime[target] = deltatime[target] ;
160 if ( time[target] != 0 ) {
161 if ( time[target]+nextdeltatime[target] > maxtime[target] ) {
162 nextdeltatime[target] = 0 ;
165 if ( target != myrank ) {
166 while ( time[myrank] >= time[target] ) {
167 time[target] += deltatime[target] ;
171 MyMPIAccessDEC->setTime( time[myrank] , nextdeltatime[myrank] ) ;
172 cout << "test" << myrank << "=====TIME " << time[myrank] << "=====DELTATIME "
173 << nextdeltatime[myrank] << "=====MAXTIME " << maxtime[myrank] << " ======"
175 double * sendbuf = new double[datamsglength*size] ;
176 // double * sendbuf = (double *) malloc(sizeof(double)*datamsglength*size) ;
177 double * recvbuf = new double[datamsglength*size] ;
179 //cout << "test_AllToAllvTimeDoubleDEC" << myrank << " sendbuf" ;
180 for ( target = 0 ; target < size ; target++ ) {
181 for ( j = 0 ; j < datamsglength ; j++ ) {
182 //sendbuf[j] = myrank*10000 + (j/datamsglength)*100 + j ;
183 sendbuf[target*datamsglength+j] = myrank*1000000 + target*10000 +
184 (time[myrank]/deltatime[myrank])*100 + j ;
185 //cout << " " << (int ) sendbuf[target*datamsglength+j] ;
186 recvbuf[target*datamsglength+j] = -1 ;
191 int sts = MyMPIAccessDEC->allToAllvTime( sendbuf, sendcounts , sdispls , MPI_DOUBLE ,
192 recvbuf, recvcounts , rdispls , MPI_DOUBLE ) ;
193 chksts( sts , myrank , mpi_access ) ;
195 // cout << "test_AllToAllvTimeDoubleDEC" << myrank << " recvbuf before CheckSent" ;
196 // for ( i = 0 ; i < datamsglength*size ; i++ ) {
197 // cout << " " << recvbuf[i] ;
201 int nRecvReq = mpi_access->recvRequestIdsSize() ;
202 if ( nRecvReq != 0 ) {
203 ostringstream strstream ;
204 strstream << "=============================================================" << endl
205 << "test_AllToAllvTimeDoubleDEC" << myrank << " WaitAllRecv "
206 << nRecvReq << " Requests # 0 ERROR"
207 << endl << "============================================================"
209 int *ArrayOfRecvRequests = new int[nRecvReq] ;
210 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
211 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
212 delete [] ArrayOfRecvRequests ;
213 cout << strstream.str() << endl ;
214 CPPUNIT_FAIL( strstream.str() ) ;
217 // cout << "test_AllToAllvTimeDoubleDEC" << myrank << " check of recvbuf" << endl ;
218 bool badrecvbuf = false ;
219 for ( target = 0 ; target < size ; target++ ) {
221 for ( j = 0 ; j < datamsglength ; j++ ) {
222 int index = target*datamsglength+j ;
223 if ( j < recvcounts[target] ) {
224 if ( fabs(recvbuf[index] - (target*1000000 + myrank*10000 +
225 (time[target]/deltatime[target])*100 + j)) > 101) {
227 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " target " << target << " time[target] "
228 << time[target] << " recvbuf[" << index << "] " << (int ) recvbuf[index]
229 << " # " << (int ) (target*1000000 +
230 myrank*10000 + (time[target]/deltatime[target])*100 + j)
233 else if ( badrecvbuf ) {
234 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " recvbuf[" << index << "] "
235 << recvbuf[index] << " ~= " << (int ) (target*1000000 +
236 myrank*10000 + (time[target]/deltatime[target])*100 + j) << endl ;
239 else if ( recvbuf[index] != -1 ) {
241 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " recvbuf[" << index << "] "
242 << recvbuf[index] << " # -1" << endl ;
247 ostringstream strstream ;
248 strstream << "==================================================================" << endl
249 << "test_AllToAllvTimeDoubleDEC" << myrank << " badrecvbuf"
250 << endl << "=================================================================="
252 cout << strstream.str() << endl ;
253 CPPUNIT_FAIL( strstream.str() ) ;
258 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " Barrier :" << endl ;
259 mpi_access->barrier() ;
261 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalSent" << endl ;
262 sts = MyMPIAccessDEC->checkFinalSent() ;
263 if ( sts != MPI_SUCCESS ) {
264 ostringstream strstream ;
265 strstream << "=================================================================" << endl
266 << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalSent ERROR"
267 << endl << "================================================================="
269 cout << strstream.str() << endl ;
270 CPPUNIT_FAIL( strstream.str() ) ;
273 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalRecv" << endl ;
274 sts = MyMPIAccessDEC->checkFinalRecv() ;
275 if ( sts != MPI_SUCCESS ) {
276 ostringstream strstream ;
277 strstream << "=================================================================" << endl
278 << "test_AllToAllvTimeDoubleDEC" << myrank << " CheckFinalRecv ERROR"
279 << endl << "================================================================"
281 cout << strstream.str() << endl ;
282 CPPUNIT_FAIL( strstream.str() ) ;
285 int nRecvReq = mpi_access->recvRequestIdsSize() ;
287 ostringstream strstream ;
288 strstream << "===============================================================" << endl
289 << "test_AllToAllvTimeDoubleDEC" << myrank << " RecvRequestIds " << nRecvReq
290 << " RecvRequests # 0 Error"
291 << endl << "==============================================================="
293 cout << strstream.str() << endl ;
294 CPPUNIT_FAIL( strstream.str() ) ;
297 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " RecvRequestIds " << nRecvReq
298 << " RecvRequests = 0 OK" << endl ;
301 time_t endtime = std::time(NULL) ;
302 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " begintime " << begintime << " endtime " << endtime
303 << " elapse " << endtime-begintime << " " << maxtime[myrank]/deltatime[myrank]
304 << " calls to AllToAll" << endl ;
306 cout << "test" << myrank << " Barrier :" << endl ;
307 mpi_access->barrier() ;
311 delete MyMPIAccessDEC ;
312 // delete aLinearInterpDEC ;
314 delete [] sendcounts ;
316 delete [] recvcounts ;
318 delete [] sendtimecounts ;
319 delete [] stimedispls ;
320 delete [] recvtimecounts ;
321 delete [] rtimedispls ;
325 endtime = std::time(NULL) ;
327 cout << "test_AllToAllvTimeDoubleDEC" << myrank << " OK begintime " << begintime << " endtime " << endtime
328 << " elapse " << endtime-begintime << " " << maxtime[myrank]/deltatime[myrank]
329 << " calls to AllToAll" << endl ;