1 // Copyright (C) 2007-2012 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
26 #include "MPIAccessDECTest.hxx"
27 #include <cppunit/TestAssert.h>
28 #include "MPIAccessDEC.hxx"
30 // use this define to enable lines, execution of which leads to Segmentation Fault
33 // use this define to enable CPPUNIT asserts and fails, showing bugs
34 #define ENABLE_FORCED_FAILURES
37 using namespace ParaMEDMEM;
39 void MPIAccessDECTest::test_AllToAllDECSynchronousPointToPoint() {
40 test_AllToAllDEC( false ) ;
42 void MPIAccessDECTest::test_AllToAllDECAsynchronousPointToPoint() {
43 test_AllToAllDEC( true ) ;
46 static void chksts( int sts , int myrank , ParaMEDMEM::MPIAccess mpi_access ) {
47 char msgerr[MPI_MAX_ERROR_STRING] ;
49 if ( sts != MPI_SUCCESS ) {
50 mpi_access.errorString(sts, msgerr, &lenerr) ;
51 cout << "test" << myrank << " lenerr " << lenerr << " "
53 ostringstream strstream ;
54 strstream << "===========================================================" << endl
55 << "test_AllToAllDEC" << myrank << " KO" << endl
56 << "==========================================================="
58 cout << strstream.str() << endl ;
59 CPPUNIT_FAIL( strstream.str() ) ;
64 void MPIAccessDECTest::test_AllToAllDEC( bool Asynchronous ) {
66 cout << "test_AllToAllDEC" << endl ;
68 // MPI_Init(&argc, &argv) ;
72 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
73 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
75 if ( size < 2 || size > 11 ) {
76 ostringstream strstream ;
77 strstream << "usage :" << endl
78 << "mpirun -np <nbprocs> test_AllToAllDEC" << endl
79 << " (nbprocs >=2)" << endl
80 << "test must be runned with more than 1 proc and less than 12 procs"
82 cout << strstream.str() << endl ;
83 CPPUNIT_FAIL( strstream.str() ) ;
86 cout << "test_AllToAllDEC" << myrank << endl ;
88 ParaMEDMEM::CommInterface interface ;
89 std::set<int> sourceprocs;
90 std::set<int> targetprocs;
92 for ( i = 0 ; i < size/2 ; i++ ) {
93 sourceprocs.insert(i);
95 for ( i = size/2 ; i < size ; i++ ) {
96 targetprocs.insert(i);
99 ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ;
100 ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ;
102 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
105 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
108 #define datamsglength 10
111 int sendcount = datamsglength ;
112 int recvcount = datamsglength ;
113 int * recvbuf = new int[datamsglength*size] ;
116 for ( ireq = 0 ; ireq < maxreq ; ireq++ ) {
117 int * sendbuf = new int[datamsglength*size] ;
119 for ( j = 0 ; j < datamsglength*size ; j++ ) {
120 sendbuf[j] = myrank*1000000 + ireq*1000 + j ;
124 MyMPIAccessDEC->allToAll( sendbuf, sendcount , MPI_INT ,
125 recvbuf, recvcount , MPI_INT ) ;
127 int nRecvReq = mpi_access->recvRequestIdsSize() ;
128 int *ArrayOfRecvRequests = new int[nRecvReq] ;
129 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
130 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
131 mpi_access->deleteRequests( nReq , ArrayOfRecvRequests ) ;
132 delete [] ArrayOfRecvRequests ;
135 int nSendReq = mpi_access->sendRequestIdsSize() ;
136 cout << "test_AllToAllDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
139 int *ArrayOfSendRequests = new int[nSendReq] ;
140 int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
141 mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
142 delete [] ArrayOfSendRequests ;
145 int nRecvReq = mpi_access->recvRequestIdsSize() ;
147 ostringstream strstream ;
148 strstream << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq
149 << " RecvRequests # 0 Error" << endl ;
150 cout << strstream.str() << endl ;
151 CPPUNIT_FAIL( strstream.str() ) ;
154 cout << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq
155 << " RecvRequests = 0 OK" << endl ;
158 mpi_access->barrier() ;
162 delete MyMPIAccessDEC ;
167 cout << "test_AllToAllDEC" << myrank << " OK" << endl ;