1 // Copyright (C) 2007-2014 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, 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 "CommInterface.hxx"
30 //#include "ProcessorGroup.hxx"
31 //#include "MPIProcessorGroup.hxx"
32 #include "MPIAccessDEC.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_AllToAllvDECSynchronousPointToPoint() {
44 test_AllToAllvDEC( false ) ;
46 void MPIAccessDECTest::test_AllToAllvDECAsynchronousPointToPoint() {
47 test_AllToAllvDEC( 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_AllToAllvDEC" << myrank << " lenerr " << lenerr << " "
57 ostringstream strstream ;
58 strstream << "==========================================================="
59 << "test_AllToAllvDEC" << myrank << " KO"
60 << "==========================================================="
62 cout << strstream.str() << endl ;
63 CPPUNIT_FAIL( strstream.str() ) ;
68 void MPIAccessDECTest::test_AllToAllvDEC( bool Asynchronous ) {
70 cout << "test_AllToAllvDEC" << 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_AllToAllvDEC" << 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_AllToAllvDEC" << myrank << 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 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
111 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
114 #define datamsglength 10
117 int *sendcounts = new int[size] ;
118 int *sdispls = new int[size] ;
119 int *recvcounts = new int[size] ;
120 int *rdispls = new int[size] ;
121 for ( i = 0 ; i < size ; i++ ) {
122 sendcounts[i] = datamsglength-i;
123 sdispls[i] = i*datamsglength ;
124 recvcounts[i] = datamsglength-myrank;
125 rdispls[i] = i*datamsglength ;
127 int * recvbuf = new int[datamsglength*size] ;
130 for ( ireq = 0 ; ireq < maxreq ; ireq++ ) {
131 int * sendbuf = new int[datamsglength*size] ;
132 // int * sendbuf = (int *) malloc( sizeof(int)*datamsglength*size) ;
134 for ( j = 0 ; j < datamsglength*size ; j++ ) {
135 sendbuf[j] = myrank*1000000 + ireq*1000 + j ;
139 MyMPIAccessDEC->allToAllv( sendbuf, sendcounts , sdispls , MPI_INT ,
140 recvbuf, recvcounts , rdispls , MPI_INT ) ;
142 // cout << "test_AllToAllvDEC" << myrank << " recvbuf before CheckSent" ;
143 // for ( i = 0 ; i < datamsglength*size ; i++ ) {
144 // cout << " " << recvbuf[i] ;
148 // cout << "test_AllToAllvDEC" << myrank << " sendbuf " << sendbuf << endl ;
149 // MyMPIAccessDEC->CheckSent() ;
151 int nRecvReq = mpi_access->recvRequestIdsSize() ;
152 // cout << "test_AllToAllvDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests" << endl ;
153 int *ArrayOfRecvRequests = new int[nRecvReq] ;
154 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
155 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
156 mpi_access->deleteRequests( nReq , ArrayOfRecvRequests ) ;
157 delete [] ArrayOfRecvRequests ;
159 // cout << "test_AllToAllvDEC" << myrank << " recvbuf" ;
160 // for ( i = 0 ; i < datamsglength*size ; i++ ) {
161 // cout << " " << recvbuf[i] ;
166 // cout << "test_AllToAllvDEC" << myrank << " final CheckSent" << endl ;
167 // MyMPIAccessDEC->CheckSent() ;
169 int nSendReq = mpi_access->sendRequestIdsSize() ;
170 cout << "test_AllToAllvDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
173 int *ArrayOfSendRequests = new int[nSendReq] ;
174 int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
175 mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
176 delete [] ArrayOfSendRequests ;
179 int nRecvReq = mpi_access->recvRequestIdsSize() ;
181 ostringstream strstream ;
182 strstream << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq
183 << " RecvRequests # 0 Error" << endl ;
184 cout << strstream.str() << endl ;
185 CPPUNIT_FAIL( strstream.str() ) ;
188 cout << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq
189 << " RecvRequests = 0 OK" << endl ;
192 mpi_access->barrier() ;
196 delete MyMPIAccessDEC ;
197 delete [] sendcounts ;
199 delete [] recvcounts ;
205 cout << "test_AllToAllvDEC" << myrank << " OK" << endl ;