Back to index

salome-med  6.5.0
test_MPI_Access_IProbe.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_IProbe() {
00045 
00046   cout << "test_MPI_Access_IProbe" << 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_IProbe must be runned with 2 procs" << endl ;
00058     cout << strstream.str() << endl ;
00059     CPPUNIT_FAIL( strstream.str() ) ;
00060   }
00061 
00062   cout << "test_MPI_Access_IProbe" << myrank << endl ;
00063 
00064   ParaMEDMEM::CommInterface interface ;
00065 
00066   ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
00067 
00068   ParaMEDMEM::MPIAccess mpi_access( group ) ;
00069 
00070   if ( myrank >= 2 ) {
00071     mpi_access.barrier() ;
00072     delete group ;
00073     return ;
00074   }
00075 
00076   int target = 1 - myrank ;
00077   int sendbuf[10] ;
00078   int RequestId[10] ;
00079   int sts ;
00080   int i ;
00081   for ( i = 0 ; i < 10 ; i++ ) {
00082      if ( myrank == 0 ) {
00083        sendbuf[i] = i ;
00084        sts = mpi_access.ISend(&sendbuf[i],1,MPI_INT,target, RequestId[i]) ;
00085        cout << "test" << myrank << " Send RequestId " << RequestId[i]
00086             << endl ;
00087      }
00088      else {
00089        int flag = false ;
00090        while ( !flag ) {
00091             int source, tag, outcount ;
00092             MPI_Datatype datatype ;
00093             sts = mpi_access.IProbe(target, source, tag, datatype, outcount, flag ) ;
00094             if ( flag ) {
00095               cout << "test" << myrank << " " << i << " IProbe target " << target
00096                    << " source " << source << " tag " << tag
00097                    << " outcount " << outcount << " flag " << flag << endl ;
00098             }
00099             else {
00100               cout << "test" << myrank << " IProbe flag " << flag << endl ;
00101               sleep( 1 ) ;
00102             }
00103             if ( flag ) {
00104               int recvbuf ;
00105               sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
00106                                     &outcount) ;
00107               if ( (outcount != 1) | (recvbuf != i) ) {
00108                 ostringstream strstream ;
00109                 strstream << "==========================================================="
00110                           << endl << "test" << myrank << " outcount " << outcount
00111                           << " recvbuf " << recvbuf << " KO" << endl
00112                           << "==========================================================="
00113                           << endl ;
00114                 cout << strstream.str() << endl ;
00115                 CPPUNIT_FAIL( strstream.str() ) ;
00116               }
00117               cout << "==========================================================="
00118                    << endl << "test" << myrank << " outcount " << outcount
00119                    << " recvbuf " << recvbuf << " OK" << endl
00120                    << "==========================================================="
00121                    << endl ;
00122             }
00123        }
00124      }
00125      char msgerr[MPI_MAX_ERROR_STRING] ;
00126      int lenerr ;
00127      mpi_access.errorString(sts, msgerr, &lenerr) ;
00128      cout << "test" << myrank << " lenerr " << lenerr << " "
00129           << msgerr << endl ;
00130 
00131      if ( sts != MPI_SUCCESS ) {
00132        ostringstream strstream ;
00133        strstream << "==========================================================="
00134                  << "test" << myrank << " KO"
00135                  << "==========================================================="
00136                  << endl ;
00137        cout << strstream.str() << endl ;
00138        CPPUNIT_FAIL( strstream.str() ) ;
00139      }
00140      mpi_access.check() ;
00141   }
00142   int flag ;
00143   mpi_access.testAll(10,RequestId,flag) ;
00144   mpi_access.waitAll(10,RequestId) ;
00145   mpi_access.deleteRequests(10,RequestId) ;
00146   mpi_access.testAll(10,RequestId,flag) ;
00147   if ( !flag ) {
00148     ostringstream strstream ;
00149     strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
00150     cout << strstream.str() << endl ;
00151     CPPUNIT_FAIL( strstream.str() ) ;
00152   }
00153   mpi_access.check() ;
00154 
00155   mpi_access.barrier() ;
00156 
00157   delete group ;
00158 
00159 //  MPI_Finalize();
00160 
00161   cout << "test" << myrank << " OK" << endl ;
00162 
00163   return ;
00164 }
00165 
00166 
00167 
00168