1 // Copyright (C) 2007-2024 CEA, EDF
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 "../ParaMEDMEM/MPIAccess/MPIAccessDEC.hxx"
31 // use this define to enable lines, execution of which leads to Segmentation Fault
34 // use this define to enable CPPUNIT asserts and fails, showing bugs
35 #define ENABLE_FORCED_FAILURES
38 using namespace MEDCoupling;
40 void MPIAccessDECTest::test_AllToAllDECSynchronousPointToPoint() {
41 test_AllToAllDEC( false ) ;
43 void MPIAccessDECTest::test_AllToAllDECAsynchronousPointToPoint() {
44 test_AllToAllDEC( true ) ;
47 static void chksts( int sts , int myrank , MEDCoupling::MPIAccess mpi_access ) {
48 char msgerr[MPI_MAX_ERROR_STRING] ;
50 if ( sts != MPI_SUCCESS ) {
51 mpi_access.errorString(sts, msgerr, &lenerr) ;
52 debugStream << "test" << myrank << " lenerr " << lenerr << " "
54 ostringstream strstream ;
55 strstream << "===========================================================" << endl
56 << "test_AllToAllDEC" << myrank << " KO" << endl
57 << "==========================================================="
59 debugStream << strstream.str() << endl ;
60 CPPUNIT_FAIL( strstream.str() ) ;
65 void MPIAccessDECTest::test_AllToAllDEC( bool Asynchronous ) {
67 debugStream << "test_AllToAllDEC" << endl ;
69 // MPI_Init(&argc, &argv) ;
73 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
74 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
76 if ( size < 2 || size > 11 ) {
77 ostringstream strstream ;
78 strstream << "usage :" << endl
79 << "mpirun -np <nbprocs> test_AllToAllDEC" << endl
80 << " (nbprocs >=2)" << endl
81 << "test must be run with more than 1 proc and less than 12 procs"
83 cerr << strstream.str() << endl ;
84 CPPUNIT_FAIL( strstream.str() ) ;
87 debugStream << "test_AllToAllDEC" << myrank << endl ;
89 MEDCoupling::CommInterface interface ;
90 std::set<int> sourceprocs;
91 std::set<int> targetprocs;
93 for ( i = 0 ; i < size/2 ; i++ ) {
94 sourceprocs.insert(i);
96 for ( i = size/2 ; i < size ; i++ ) {
97 targetprocs.insert(i);
100 MEDCoupling::MPIProcessorGroup* sourcegroup = new MEDCoupling::MPIProcessorGroup(interface,sourceprocs) ;
101 MEDCoupling::MPIProcessorGroup* targetgroup = new MEDCoupling::MPIProcessorGroup(interface,targetprocs) ;
103 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
106 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
109 #define datamsglength 10
112 int sendcount = datamsglength ;
113 int recvcount = datamsglength ;
114 int * recvbuf = new int[datamsglength*size] ;
117 for ( ireq = 0 ; ireq < maxreq ; ireq++ ) {
118 int * sendbuf = new int[datamsglength*size] ;
120 for ( j = 0 ; j < datamsglength*size ; j++ ) {
121 sendbuf[j] = myrank*1000000 + ireq*1000 + j ;
125 MyMPIAccessDEC->allToAll( sendbuf, sendcount , MPI_INT ,
126 recvbuf, recvcount , MPI_INT ) ;
128 int nRecvReq = mpi_access->recvRequestIdsSize() ;
129 int *ArrayOfRecvRequests = new int[nRecvReq] ;
130 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
131 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
132 mpi_access->deleteRequests( nReq , ArrayOfRecvRequests ) ;
133 delete [] ArrayOfRecvRequests ;
136 int nSendReq = mpi_access->sendRequestIdsSize() ;
137 debugStream << "test_AllToAllDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
140 int *ArrayOfSendRequests = new int[nSendReq] ;
141 int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
142 mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
143 delete [] ArrayOfSendRequests ;
146 int nRecvReq = mpi_access->recvRequestIdsSize() ;
148 ostringstream strstream ;
149 strstream << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq
150 << " RecvRequests # 0 Error" << endl ;
151 debugStream << strstream.str() << endl ;
152 CPPUNIT_FAIL( strstream.str() ) ;
155 debugStream << "test_AllToAllDEC" << myrank << " final RecvRequestIds " << nRecvReq
156 << " RecvRequests = 0 OK" << endl ;
159 mpi_access->barrier() ;
163 delete MyMPIAccessDEC ;
168 debugStream << "test_AllToAllDEC" << myrank << " OK" << endl ;