Back to index

salome-med  6.5.0
test_MPI_Access_ISend_IRecv_BottleNeck.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 <time.h>
00021 #include <string>
00022 #include <vector>
00023 #include <map>
00024 #include <iostream>
00025 #include <mpi.h>
00026 
00027 #include "MPIAccessTest.hxx"
00028 #include <cppunit/TestAssert.h>
00029 
00030 //#include "CommInterface.hxx"
00031 //#include "ProcessorGroup.hxx"
00032 //#include "MPIProcessorGroup.hxx"
00033 #include "MPIAccess.hxx"
00034 
00035 // use this define to enable lines, execution of which leads to Segmentation Fault
00036 #define ENABLE_FAULTS
00037 
00038 // use this define to enable CPPUNIT asserts and fails, showing bugs
00039 #define ENABLE_FORCED_FAILURES
00040 
00041 using namespace std;
00042 using namespace ParaMEDMEM;
00043 
00044 void MPIAccessTest::test_MPI_Access_ISend_IRecv_BottleNeck() {
00045 
00046   cout << "test_MPI_Access_ISend_IRecv_BottleNeck" << endl ;
00047 
00048 //  MPI_Init(&argc, &argv) ; 
00049 
00050   int size ;
00051   int myrank ;
00052   MPI_Comm_size(MPI_COMM_WORLD,&size) ;
00053   MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
00054 
00055   if ( size < 2 ) {
00056     ostringstream strstream ;
00057     strstream << "test_MPI_Access_ISend_IRecv_BottleNeck must be runned with 2 procs"
00058               << endl ;
00059     cout << strstream.str() << endl ;
00060     CPPUNIT_FAIL( strstream.str() ) ;
00061   }
00062 
00063   cout << "test_MPI_Access_ISend_IRecv_BottleNeck" << myrank << endl ;
00064 
00065   ParaMEDMEM::CommInterface interface ;
00066 
00067   ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
00068 
00069   ParaMEDMEM::MPIAccess mpi_access( group ) ;
00070 
00071 #define maxreq 10000
00072 
00073   if ( myrank >= 2 ) {
00074     mpi_access.barrier() ;
00075     delete group ;
00076     return ;
00077   }
00078 
00079   int target = 1 - myrank ;
00080   int SendRequestId[maxreq] ;
00081   int RecvRequestId[maxreq] ;
00082   int sts ;
00083   int sendbuf[maxreq] ;
00084   int recvbuf[maxreq] ;
00085   int i ;
00086   for ( i = 0 ; i < maxreq ; i++ ) {
00087      if ( myrank == 0 ) {
00088        sendbuf[i] = i ;
00089        sts = mpi_access.ISend(sendbuf,i,MPI_INT,target, SendRequestId[i]) ;
00090        cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
00091             << " tag " << mpi_access.sendMPITag(target) << endl ;
00092      }
00093      else {
00094        //sleep( 1 ) ;
00095        sts = mpi_access.IRecv(recvbuf,i,MPI_INT,target, RecvRequestId[i]) ;
00096        cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
00097             << " tag " << mpi_access.recvMPITag(target) << endl ;
00098        int recvreqsize = mpi_access.recvRequestIdsSize() ;
00099        int * recvrequests = new int[ recvreqsize ] ;
00100        recvreqsize = mpi_access.recvRequestIds( target , recvreqsize , recvrequests ) ;
00101        int j ;
00102        for (j = 0 ; j < recvreqsize ; j++) {
00103           int flag ;
00104           mpi_access.test( recvrequests[j], flag ) ;
00105           if ( flag ) {
00106             int source, tag, error, outcount ;
00107             mpi_access.status( recvrequests[j], source, tag, error, outcount,
00108                                true ) ;
00109             cout << "test" << myrank << " Test(Recv RequestId "
00110                  << recvrequests[j] << ") : source " << source << " tag " << tag
00111                  << " error " << error << " outcount " << outcount
00112                  << " flag " << flag << " : DeleteRequest" << endl ;
00113             mpi_access.deleteRequest( recvrequests[j] ) ;
00114           }
00115           else {
00116 //            cout << "test" << myrank << " Test(Recv RequestId "
00117 //                 << recvrequests[j] << ") flag " << flag << endl ;
00118           }
00119        }
00120        delete [] recvrequests ;
00121      }
00122      if ( sts != MPI_SUCCESS ) {
00123        char msgerr[MPI_MAX_ERROR_STRING] ;
00124        int lenerr ;
00125        mpi_access.errorString(sts, msgerr, &lenerr) ;
00126        cout << "test" << myrank << " lenerr " << lenerr << " "
00127             << msgerr << endl ;
00128      }
00129 
00130      if ( sts != MPI_SUCCESS ) {
00131        ostringstream strstream ;
00132        strstream << "==========================================================="
00133                  << "test" << myrank << " KO"
00134                  << "==========================================================="
00135                  << endl ;
00136        cout << strstream.str() << endl ;
00137        CPPUNIT_FAIL( strstream.str() ) ;
00138      }
00139   }
00140 
00141   mpi_access.check() ;
00142   if ( myrank == 0 ) {
00143     int size = mpi_access.sendRequestIdsSize() ;
00144     cout << "test" << myrank << " before WaitAll sendreqsize " << size << endl ;
00145     mpi_access.waitAll(maxreq, SendRequestId) ;
00146     size = mpi_access.sendRequestIdsSize() ;
00147     cout << "test" << myrank << " after WaitAll sendreqsize " << size << endl ;
00148     int * ArrayOfSendRequests = new int[ size ] ;
00149     int nSendRequest = mpi_access.sendRequestIds( size , ArrayOfSendRequests ) ;
00150     int i ;
00151     for ( i = 0 ; i < nSendRequest ; i++ ) {
00152        mpi_access.deleteRequest( ArrayOfSendRequests[i] ) ;
00153     }
00154     delete [] ArrayOfSendRequests ;
00155   }
00156   else {
00157     int size = mpi_access.recvRequestIdsSize() ;
00158     cout << "test" << myrank << " before WaitAll recvreqsize " << size << endl ;
00159     mpi_access.waitAll(maxreq, RecvRequestId) ;
00160     size = mpi_access.recvRequestIdsSize() ;
00161     cout << "test" << myrank << " after WaitAll recvreqsize " << size << endl ;
00162     int * ArrayOfRecvRequests = new int[ size ] ;
00163     int nRecvRequest = mpi_access.recvRequestIds( size , ArrayOfRecvRequests ) ;
00164     int i ;
00165     for ( i = 0 ; i < nRecvRequest ; i++ ) {
00166        mpi_access.deleteRequest( ArrayOfRecvRequests[i] ) ;
00167     }
00168     delete [] ArrayOfRecvRequests ;
00169   }
00170   mpi_access.check() ;
00171 
00172   if ( myrank == 0 ) {
00173     int sendrequests[maxreq] ;
00174     int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
00175     int i ;
00176     if ( sendreqsize != 0 ) {
00177       ostringstream strstream ;
00178       strstream << "=========================================================" << endl
00179                 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
00180                 << "=========================================================" << endl ;
00181       cout << strstream.str() << endl ;
00182       for ( i = 0 ; i < sendreqsize ; i++ ) {
00183          cout << "test" << myrank << " sendrequests[ " << i << " ] = "
00184               << sendrequests[i] << endl ;
00185       }
00186       CPPUNIT_FAIL( strstream.str() ) ;
00187     }
00188     else {
00189       cout << "=========================================================" << endl
00190            << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
00191            << "=========================================================" << endl ;
00192     }
00193   }
00194   else {
00195     int recvrequests[maxreq] ;
00196     int recvreqsize = mpi_access.recvRequestIds( target , maxreq , recvrequests ) ;
00197     if ( recvreqsize != 0 ) {
00198       ostringstream strstream ;
00199       strstream << "=========================================================" << endl
00200                 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
00201                 << "=========================================================" << endl ;
00202       cout << strstream.str() << endl ;
00203       CPPUNIT_FAIL( strstream.str() ) ;
00204     }
00205     else {
00206       cout << "=========================================================" << endl
00207            << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
00208            << "=========================================================" << endl ;
00209     }
00210   }
00211 
00212   mpi_access.barrier() ;
00213 
00214   delete group ;
00215 
00216 //  MPI_Finalize();
00217 
00218   cout << "test" << myrank << " OK" << endl ;
00219 
00220   return ;
00221 }
00222 
00223 
00224 
00225