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>
28 //#include "CommInterface.hxx"
29 //#include "ProcessorGroup.hxx"
30 //#include "MPIProcessorGroup.hxx"
31 #include "MPIAccessDEC.hxx"
33 // use this define to enable lines, execution of which leads to Segmentation Fault
36 // use this define to enable CPPUNIT asserts and fails, showing bugs
37 #define ENABLE_FORCED_FAILURES
40 using namespace ParaMEDMEM;
42 void MPIAccessDECTest::test_AllToAllvDECSynchronousPointToPoint() {
43 test_AllToAllvDEC( false ) ;
45 void MPIAccessDECTest::test_AllToAllvDECAsynchronousPointToPoint() {
46 test_AllToAllvDEC( true ) ;
49 static void chksts( int sts , int myrank , ParaMEDMEM::MPIAccess mpi_access ) {
50 char msgerr[MPI_MAX_ERROR_STRING] ;
52 if ( sts != MPI_SUCCESS ) {
53 mpi_access.errorString(sts, msgerr, &lenerr) ;
54 cout << "test_AllToAllvDEC" << myrank << " lenerr " << lenerr << " "
56 ostringstream strstream ;
57 strstream << "==========================================================="
58 << "test_AllToAllvDEC" << myrank << " KO"
59 << "==========================================================="
61 cout << strstream.str() << endl ;
62 CPPUNIT_FAIL( strstream.str() ) ;
67 void MPIAccessDECTest::test_AllToAllvDEC( bool Asynchronous ) {
69 cout << "test_AllToAllvDEC" << endl ;
71 // MPI_Init(&argc, &argv) ;
75 MPI_Comm_size(MPI_COMM_WORLD,&size) ;
76 MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
78 if ( size < 2 || size > 11 ) {
79 ostringstream strstream ;
80 strstream << "usage :" << endl
81 << "mpirun -np <nbprocs> test_AllToAllvDEC" << endl
82 << " (nbprocs >=2)" << endl
83 << "test must be runned with more than 1 proc and less than 12 procs"
85 cout << strstream.str() << endl ;
86 CPPUNIT_FAIL( strstream.str() ) ;
89 // int Asynchronous = atoi(argv[1]);
91 cout << "test_AllToAllvDEC" << myrank << endl ;
93 ParaMEDMEM::CommInterface interface ;
94 std::set<int> sourceprocs;
95 std::set<int> targetprocs;
97 for ( i = 0 ; i < size/2 ; i++ ) {
98 sourceprocs.insert(i);
100 for ( i = size/2 ; i < size ; i++ ) {
101 targetprocs.insert(i);
104 ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ;
105 ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ;
107 MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
110 MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
113 #define datamsglength 10
116 int *sendcounts = new int[size] ;
117 int *sdispls = new int[size] ;
118 int *recvcounts = new int[size] ;
119 int *rdispls = new int[size] ;
120 for ( i = 0 ; i < size ; i++ ) {
121 sendcounts[i] = datamsglength-i;
122 sdispls[i] = i*datamsglength ;
123 recvcounts[i] = datamsglength-myrank;
124 rdispls[i] = i*datamsglength ;
126 int * recvbuf = new int[datamsglength*size] ;
129 for ( ireq = 0 ; ireq < maxreq ; ireq++ ) {
130 int * sendbuf = new int[datamsglength*size] ;
131 // int * sendbuf = (int *) malloc( sizeof(int)*datamsglength*size) ;
133 for ( j = 0 ; j < datamsglength*size ; j++ ) {
134 sendbuf[j] = myrank*1000000 + ireq*1000 + j ;
138 MyMPIAccessDEC->allToAllv( sendbuf, sendcounts , sdispls , MPI_INT ,
139 recvbuf, recvcounts , rdispls , MPI_INT ) ;
141 // cout << "test_AllToAllvDEC" << myrank << " recvbuf before CheckSent" ;
142 // for ( i = 0 ; i < datamsglength*size ; i++ ) {
143 // cout << " " << recvbuf[i] ;
147 // cout << "test_AllToAllvDEC" << myrank << " sendbuf " << sendbuf << endl ;
148 // MyMPIAccessDEC->CheckSent() ;
150 int nRecvReq = mpi_access->recvRequestIdsSize() ;
151 // cout << "test_AllToAllvDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests" << endl ;
152 int *ArrayOfRecvRequests = new int[nRecvReq] ;
153 int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
154 mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
155 mpi_access->deleteRequests( nReq , ArrayOfRecvRequests ) ;
156 delete [] ArrayOfRecvRequests ;
158 // cout << "test_AllToAllvDEC" << myrank << " recvbuf" ;
159 // for ( i = 0 ; i < datamsglength*size ; i++ ) {
160 // cout << " " << recvbuf[i] ;
165 // cout << "test_AllToAllvDEC" << myrank << " final CheckSent" << endl ;
166 // MyMPIAccessDEC->CheckSent() ;
168 int nSendReq = mpi_access->sendRequestIdsSize() ;
169 cout << "test_AllToAllvDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
172 int *ArrayOfSendRequests = new int[nSendReq] ;
173 int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
174 mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
175 delete [] ArrayOfSendRequests ;
178 int nRecvReq = mpi_access->recvRequestIdsSize() ;
180 ostringstream strstream ;
181 strstream << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq
182 << " RecvRequests # 0 Error" << endl ;
183 cout << strstream.str() << endl ;
184 CPPUNIT_FAIL( strstream.str() ) ;
187 cout << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq
188 << " RecvRequests = 0 OK" << endl ;
191 mpi_access->barrier() ;
195 delete MyMPIAccessDEC ;
196 delete [] sendcounts ;
198 delete [] recvcounts ;
204 cout << "test_AllToAllvDEC" << myrank << " OK" << endl ;