Back to index

salome-med  6.5.0
test_MPI_Access_ISendRecv.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 "MPIAccessTest.hxx"
00027 #include <cppunit/TestAssert.h>
00028 
00029 //#include "CommInterface.hxx"
00030 //#include "ProcessorGroup.hxx"
00031 //#include "MPIProcessorGroup.hxx"
00032 #include "MPIAccess.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 MPIAccessTest::test_MPI_Access_ISendRecv() {
00044 
00045   cout << "test_MPI_Access_ISendRecv" << endl ;
00046 
00047 //  MPI_Init(&argc, &argv) ; 
00048 
00049   int size ;
00050   int myrank ;
00051   MPI_Comm_size(MPI_COMM_WORLD,&size) ;
00052   MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
00053 
00054   if ( size < 2 ) {
00055     cout << "test_MPI_Access_ISendRecv must be runned with 2 procs" << endl ;
00056     CPPUNIT_FAIL("test_MPI_Access_ISendRecv must be runned with 2 procs") ;
00057   }
00058 
00059   cout << "test_MPI_Access_ISendRecv" << myrank << endl ;
00060 
00061   ParaMEDMEM::CommInterface interface ;
00062 
00063   ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
00064 
00065   ParaMEDMEM::MPIAccess mpi_access( group ) ;
00066 
00067   if ( myrank >= 2 ) {
00068     mpi_access.barrier() ;
00069     delete group ;
00070     return ;
00071   }
00072 
00073   int target = 1 - myrank ;
00074   int SendRequestId[10] ;
00075   int RecvRequestId[10] ;
00076   int sendbuf[10] ;
00077   int recvbuf[10] ;
00078   int sts ;
00079   int i ;
00080   for ( i = 0 ; i < 10 ; i++ ) {
00081      sendbuf[i] = i ;
00082      sts = mpi_access.ISendRecv(&sendbuf[i],1,MPI_INT,target, SendRequestId[i],
00083                                 &recvbuf[i],1,MPI_INT,target, RecvRequestId[i]) ;
00084      cout << "test" << myrank << " Send sendRequestId " << SendRequestId[i]
00085           << " tag " << mpi_access.sendMPITag(target)
00086           << " recvRequestId " << RecvRequestId[i]
00087           << " tag " << mpi_access.recvMPITag(target) << endl ;
00088      char msgerr[MPI_MAX_ERROR_STRING] ;
00089      int lenerr ;
00090      mpi_access.errorString(sts, msgerr, &lenerr) ;
00091      cout << "test" << myrank << " lenerr " << lenerr
00092           << " " << msgerr << endl ;
00093 
00094      if ( sts != MPI_SUCCESS ) {
00095        ostringstream strstream ;
00096        strstream << "==========================================================="
00097                  << "test" << myrank << " KO"
00098                  << "==========================================================="
00099                  << endl ;
00100        cout << strstream.str() << endl ;
00101        CPPUNIT_FAIL( strstream.str() ) ;
00102      }
00103      int j ;
00104      for (j = 0 ; j <= i ; j++) {
00105         int flag ;
00106         if ( j < i ) {
00107           cout << "test" << myrank << " " << j << " -> Test-Send("<< SendRequestId[j]
00108                << ")" << endl ;
00109           mpi_access.test( SendRequestId[j], flag ) ;
00110           if ( flag ) {
00111             int target, tag, error, outcount ;
00112               mpi_access.status( SendRequestId[j], target, tag, error, outcount,
00113                                  true ) ;
00114               cout << "test" << myrank << " Send RequestId " << SendRequestId[j]
00115                    << " target " << target << " tag " << tag << " error " << error
00116                    << endl ;
00117             mpi_access.deleteRequest( SendRequestId[j] ) ;
00118           }
00119         }
00120         cout << "test" << myrank << " " << j << " -> Test-Recv("<< SendRequestId[j]
00121              << ")" << endl ;
00122         mpi_access.test( RecvRequestId[j], flag ) ;
00123         if ( flag ) {
00124           int source, tag, error, outcount ;
00125           mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
00126                              true ) ;
00127           cout << "test" << myrank << " Recv RequestId" << j << " "
00128                << RecvRequestId[j] << " source " << source << " tag " << tag
00129                << " error " << error << " outcount " << outcount << endl ;
00130           if ( (outcount != 1) | (recvbuf[j] != j) ) {
00131              ostringstream strstream ;
00132              strstream << "==========================================================="
00133                        << "test" << myrank << " outcount "
00134                        << outcount << " recvbuf[ " << j << " ] " << recvbuf[j] << " KO"
00135                        << "==========================================================="
00136                        << endl ;
00137             cout << strstream.str() << endl ;
00138             CPPUNIT_FAIL( strstream.str() ) ;
00139           }
00140         }
00141      }
00142      mpi_access.errorString(sts, msgerr, &lenerr) ;
00143      cout << "test" << myrank << " lenerr " << lenerr << " "
00144           << msgerr << endl ;
00145      mpi_access.check() ;
00146   }
00147 
00148   int flag ;
00149   mpi_access.testAll(10,SendRequestId,flag) ;
00150   mpi_access.waitAll(10,SendRequestId) ;
00151   mpi_access.deleteRequests(10,SendRequestId) ;
00152   mpi_access.testAll(10,SendRequestId,flag) ;
00153   if ( !flag ) {
00154     ostringstream strstream ;
00155     strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
00156     cout << strstream.str() << endl ;
00157     CPPUNIT_FAIL( strstream.str() ) ;
00158   }
00159 
00160   mpi_access.testAll(10,RecvRequestId,flag) ;
00161   mpi_access.waitAll(10,RecvRequestId) ;
00162   mpi_access.deleteRequests(10,RecvRequestId) ;
00163   mpi_access.testAll(10,RecvRequestId,flag) ;
00164   if ( !flag ) {
00165     ostringstream strstream ;
00166     strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
00167     cout << strstream.str() << endl ;
00168     CPPUNIT_FAIL( strstream.str() ) ;
00169   }
00170   mpi_access.check() ;
00171 
00172   int sendrequests[10] ;
00173   int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
00174   if ( sendreqsize != 0 ) {
00175     ostringstream strstream ;
00176     strstream << "=========================================================" << endl
00177               << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
00178               << "=========================================================" << endl ;
00179     cout << strstream.str() << endl ;
00180     CPPUNIT_FAIL( strstream.str() ) ;
00181   }
00182   else {
00183     cout << "=========================================================" << endl
00184          << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
00185          << "=========================================================" << endl ;
00186   }
00187   int recvrequests[10] ;
00188   int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
00189   if ( recvreqsize != 0 ) {
00190     ostringstream strstream ;
00191     strstream << "=========================================================" << endl
00192               << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
00193               << "=========================================================" << endl ;
00194     cout << strstream.str() << endl ;
00195     CPPUNIT_FAIL( strstream.str() ) ;
00196   }
00197   else {
00198     cout << "=========================================================" << endl
00199          << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
00200          << "=========================================================" << endl ;
00201   }
00202 
00203   mpi_access.barrier() ;
00204 
00205   delete group ;
00206 
00207 //  MPI_Finalize();
00208 
00209   cout << "test" << myrank << " OK" << endl ;
00210 
00211   return ;
00212 }
00213 
00214 
00215 
00216