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>
27 #include "MPIAccessDEC.hxx"
29 // use this define to enable lines, execution of which leads to Segmentation Fault
32 // use this define to enable CPPUNIT asserts and fails, showing bugs
33 #define ENABLE_FORCED_FAILURES
36 using namespace ParaMEDMEM;
38 void MPIAccessDECTest::test_AllToAllDECSynchronousPointToPoint() {
39 test_AllToAllDEC( false ) ;
41 void MPIAccessDECTest::test_AllToAllDECAsynchronousPointToPoint() {
42 test_AllToAllDEC( true ) ;
45 static void chksts( int sts , int myrank , ParaMEDMEM::MPIAccess mpi_access ) {
46 char msgerr[MPI_MAX_ERROR_STRING] ;
48 if ( sts != MPI_SUCCESS ) {
49 mpi_access.errorString(sts, msgerr, &lenerr) ;
50 cout << "test" << myrank << " lenerr " << lenerr << " "
52 ostringstream strstream ;
53 strstream << "===========================================================" << endl
54 << "test_AllToAllDEC" << myrank << " KO" << endl
55 << "==========================================================="
57 cout << strstream.str() << endl ;
58 CPPUNIT_FAIL( strstream.str() ) ;
63 void MPIAccessDECTest::test_AllToAllDEC( bool Asynchronous ) {
65 cout << "test_AllToAllDEC" << endl ;
67 // MPI_Init(&argc, &argv) ;
71 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
72 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
74 if ( size < 2 || size > 11 ) {
75 ostringstream strstream ;
76 strstream << "usage :" << endl
77 << "mpirun -np <nbprocs> test_AllToAllDEC" << endl
78 << " (nbprocs >=2)" << endl
79 << "test must be runned with more than 1 proc and less than 12 procs"
81 cout << strstream.str() << endl ;
82 CPPUNIT_FAIL( strstream.str() ) ;
85 cout << "test_AllToAllDEC" << myrank << endl ;
87 ParaMEDMEM::CommInterface interface ;
88 std::set<int> sourceprocs;
89 std::set<int> targetprocs;
91 for ( i = 0 ; i < size/2 ; i++ ) {
92 sourceprocs.insert(i);
94 for ( i = size/2 ; i < size ; i++ ) {
95 targetprocs.insert(i);
98 ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ;
99 ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ;
101 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
104 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
107 #define datamsglength 10
110 int sendcount = datamsglength ;
111 int recvcount = datamsglength ;
112 int * recvbuf = new int[datamsglength*size] ;
115 for ( ireq = 0 ; ireq < maxreq ; ireq++ ) {
116 int * sendbuf = new int[datamsglength*size] ;
118 for ( j = 0 ; j < datamsglength*size ; j++ ) {
119 sendbuf[j] = myrank*1000000 + ireq*1000 + j ;
123 MyMPIAccessDEC->allToAll( sendbuf, sendcount , MPI_INT ,
124 recvbuf, recvcount , MPI_INT ) ;
126 int nRecvReq = mpi_access->recvRequestIdsSize() ;
127 int *ArrayOfRecvRequests = new int[nRecvReq] ;
128 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
129 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
130 mpi_access->deleteRequests( nReq , ArrayOfRecvRequests ) ;
131 delete [] ArrayOfRecvRequests ;
134 int nSendReq = mpi_access->sendRequestIdsSize() ;
135 cout << "test_AllToAllDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
138 int *ArrayOfSendRequests = new int[nSendReq] ;
139 int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
140 mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
141 delete [] ArrayOfSendRequests ;
144 int nRecvReq = mpi_access->recvRequestIdsSize() ;
146 ostringstream strstream ;
147 strstream << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq
148 << " RecvRequests # 0 Error" << endl ;
149 cout << strstream.str() << endl ;
150 CPPUNIT_FAIL( strstream.str() ) ;
153 cout << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq
154 << " RecvRequests = 0 OK" << endl ;
157 mpi_access->barrier() ;
161 delete MyMPIAccessDEC ;
166 cout << "test_AllToAllDEC" << myrank << " OK" << endl ;