Back to index

salome-med  6.5.0
test_AllToAllvDEC.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include <string>
00021 #include <vector>
00022 #include <map>
00023 #include <iostream>
00024 #include <mpi.h>
00025 
00026 #include "MPIAccessDECTest.hxx"
00027 #include <cppunit/TestAssert.h>
00028 
00029 //#include "CommInterface.hxx"
00030 //#include "ProcessorGroup.hxx"
00031 //#include "MPIProcessorGroup.hxx"
00032 #include "MPIAccessDEC.hxx"
00033 
00034 // use this define to enable lines, execution of which leads to Segmentation Fault
00035 #define ENABLE_FAULTS
00036 
00037 // use this define to enable CPPUNIT asserts and fails, showing bugs
00038 #define ENABLE_FORCED_FAILURES
00039 
00040 using namespace std;
00041 using namespace ParaMEDMEM;
00042 
00043 void MPIAccessDECTest::test_AllToAllvDECSynchronousPointToPoint() {
00044   test_AllToAllvDEC( false ) ;
00045 }
00046 void MPIAccessDECTest::test_AllToAllvDECAsynchronousPointToPoint() {
00047   test_AllToAllvDEC( true ) ;
00048 }
00049 
00050 static void chksts( int sts , int myrank , ParaMEDMEM::MPIAccess mpi_access ) {
00051   char msgerr[MPI_MAX_ERROR_STRING] ;
00052   int lenerr ;
00053   if ( sts != MPI_SUCCESS ) {
00054     mpi_access.errorString(sts, msgerr, &lenerr) ;
00055     cout << "test_AllToAllvDEC" << myrank << " lenerr " << lenerr << " "
00056          << msgerr << endl ;
00057     ostringstream strstream ;
00058     strstream << "==========================================================="
00059               << "test_AllToAllvDEC" << myrank << " KO"
00060               << "==========================================================="
00061               << endl ;
00062     cout << strstream.str() << endl ;
00063     CPPUNIT_FAIL( strstream.str() ) ;
00064   }
00065   return ;
00066 }
00067 
00068 void MPIAccessDECTest::test_AllToAllvDEC( bool Asynchronous ) {
00069 
00070   cout << "test_AllToAllvDEC" << endl ;
00071 
00072   //  MPI_Init(&argc, &argv) ; 
00073 
00074   int size ;
00075   int myrank ;
00076   MPI_Comm_size(MPI_COMM_WORLD,&size) ;
00077   MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
00078 
00079   if ( size < 2 || size > 11 ) {
00080     ostringstream strstream ;
00081     strstream << "usage :" << endl
00082               << "mpirun -np <nbprocs> test_AllToAllvDEC" << endl
00083               << " (nbprocs >=2)" << endl
00084               << "test must be runned with more than 1 proc and less than 12 procs"
00085               << endl ;
00086     cout << strstream.str() << endl ;
00087     CPPUNIT_FAIL( strstream.str() ) ;
00088   }
00089 
00090   //  int Asynchronous = atoi(argv[1]);
00091 
00092   cout << "test_AllToAllvDEC" << myrank << endl ;
00093 
00094   ParaMEDMEM::CommInterface interface ;
00095   std::set<int> sourceprocs;
00096   std::set<int> targetprocs;
00097   int i ;
00098   for ( i = 0 ; i < size/2 ; i++ ) {
00099     sourceprocs.insert(i);
00100   }
00101   for ( i = size/2 ; i < size ; i++ ) {
00102     targetprocs.insert(i);
00103   }
00104 
00105   ParaMEDMEM::MPIProcessorGroup* sourcegroup = new ParaMEDMEM::MPIProcessorGroup(interface,sourceprocs) ;
00106   ParaMEDMEM::MPIProcessorGroup* targetgroup = new ParaMEDMEM::MPIProcessorGroup(interface,targetprocs) ;
00107 
00108   MPIAccessDEC * MyMPIAccessDEC = new MPIAccessDEC( *sourcegroup , *targetgroup ,
00109                                                     Asynchronous ) ;
00110   
00111   MPIAccess * mpi_access = MyMPIAccessDEC->getMPIAccess() ;
00112 
00113 #define maxreq 100
00114 #define datamsglength 10
00115 
00116   //  int sts ;
00117   int *sendcounts = new int[size] ;
00118   int *sdispls = new int[size] ;
00119   int *recvcounts = new int[size] ;
00120   int *rdispls = new int[size] ;
00121   for ( i = 0 ; i < size ; i++ ) {
00122     sendcounts[i] = datamsglength-i;
00123     sdispls[i] = i*datamsglength ;
00124     recvcounts[i] = datamsglength-myrank;
00125     rdispls[i] = i*datamsglength ;
00126   }
00127   int * recvbuf = new int[datamsglength*size] ;
00128 
00129   int ireq ;
00130   for ( ireq = 0 ; ireq < maxreq ; ireq++ ) {
00131     int * sendbuf = new int[datamsglength*size] ;
00132     //    int * sendbuf = (int *) malloc( sizeof(int)*datamsglength*size) ;
00133     int j ;
00134     for ( j = 0 ; j < datamsglength*size ; j++ ) {
00135       sendbuf[j] = myrank*1000000 + ireq*1000 + j ;
00136       recvbuf[j] = -1 ;
00137     }
00138 
00139     MyMPIAccessDEC->allToAllv( sendbuf, sendcounts , sdispls , MPI_INT ,
00140                                recvbuf, recvcounts , rdispls , MPI_INT ) ;
00141 
00142     //    cout << "test_AllToAllvDEC" << myrank << " recvbuf before CheckSent" ;
00143     //    for ( i = 0 ; i < datamsglength*size ; i++ ) {
00144     //       cout << " " << recvbuf[i] ;
00145     //    }
00146     //    cout << endl ;
00147 
00148     //    cout << "test_AllToAllvDEC" << myrank << " sendbuf " << sendbuf << endl ;
00149     //    MyMPIAccessDEC->CheckSent() ;
00150 
00151     int nRecvReq = mpi_access->recvRequestIdsSize() ;
00152     //    cout << "test_AllToAllvDEC" << myrank << " WaitAllRecv " << nRecvReq << " Requests" << endl ;
00153     int *ArrayOfRecvRequests = new int[nRecvReq] ;
00154     int nReq = mpi_access->recvRequestIds( nRecvReq, ArrayOfRecvRequests ) ;
00155     mpi_access->waitAll( nReq , ArrayOfRecvRequests ) ;
00156     mpi_access->deleteRequests( nReq , ArrayOfRecvRequests ) ;
00157     delete [] ArrayOfRecvRequests ;
00158 
00159     //    cout << "test_AllToAllvDEC" << myrank << " recvbuf" ;
00160     //    for ( i = 0 ; i < datamsglength*size ; i++ ) {
00161     //       cout << " " << recvbuf[i] ;
00162     //    }
00163     //    cout << endl ;
00164   }
00165 
00166   //  cout << "test_AllToAllvDEC" << myrank << " final CheckSent" << endl ;
00167   //  MyMPIAccessDEC->CheckSent() ;
00168 
00169   int nSendReq = mpi_access->sendRequestIdsSize() ;
00170   cout << "test_AllToAllvDEC" << myrank << " final SendRequestIds " << nSendReq << " SendRequests"
00171        << endl ;
00172   if ( nSendReq ) {
00173     int *ArrayOfSendRequests = new int[nSendReq] ;
00174     int nReq = mpi_access->sendRequestIds( nSendReq, ArrayOfSendRequests ) ;
00175     mpi_access->waitAll( nReq , ArrayOfSendRequests ) ;
00176     delete [] ArrayOfSendRequests ;
00177   }
00178 
00179   int nRecvReq = mpi_access->recvRequestIdsSize() ;
00180   if ( nRecvReq ) {
00181     ostringstream strstream ;
00182     strstream << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq
00183               << " RecvRequests # 0 Error" << endl ;
00184     cout << strstream.str() << endl ;
00185     CPPUNIT_FAIL( strstream.str() ) ;
00186   }
00187   else {
00188     cout << "test_AllToAllvDEC" << myrank << " final RecvRequestIds " << nRecvReq
00189          << " RecvRequests = 0 OK" << endl ;
00190   }
00191 
00192   mpi_access->barrier() ;
00193 
00194   delete sourcegroup ;
00195   delete targetgroup ;
00196   delete MyMPIAccessDEC ;
00197   delete [] sendcounts ;
00198   delete [] sdispls ;
00199   delete [] recvcounts ;
00200   delete [] rdispls ;
00201   delete [] recvbuf ;
00202 
00203   //  MPI_Finalize();
00204 
00205   cout << "test_AllToAllvDEC" << myrank << " OK" << endl ;
00206 
00207   return ;
00208 }
00209 
00210 
00211 
00212