Back to index

salome-med  6.5.0
test_MPI_Access_Probe.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_Probe() {
00044 
00045   cout << "test_MPI_Access_Probe" << 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_Probe must be runned with 2 procs" << endl ;
00056     CPPUNIT_FAIL("test_MPI_Access_Probe must be runned with 2 procs") ;
00057   }
00058 
00059   cout << "test_MPI_Access_Probe" << 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 RequestId[10] ;
00075   int sts ;
00076   int i ;
00077   for ( i = 0 ; i < 10 ; i++ ) {
00078      if ( myrank == 0 ) {
00079        sts = mpi_access.send(&i,1,MPI_INT,target, RequestId[i]) ;
00080        cout << "test" << myrank << " Send RequestId " << RequestId[i]
00081             << endl ;
00082      }
00083      else {
00084        int source, tag, outcount ;
00085        MPI_Datatype datatype ;
00086        sts = mpi_access.probe(target, source, tag, datatype, outcount ) ;
00087        cout << "test" << myrank << " Probe target " << target << " source " << source
00088             << " tag " << tag << " outcount " << outcount << endl ;
00089        int recvbuf ;
00090        sts = mpi_access.recv(&recvbuf,outcount,datatype,source, RequestId[i],
00091                              &outcount) ;
00092        if ( (outcount != 1) | (recvbuf != i) ) {
00093          ostringstream strstream ;
00094          strstream << "==========================================================="
00095                    << "test" << myrank << " outcount " << outcount
00096                    << " recvbuf " << recvbuf << " KO"
00097                    << "==========================================================="
00098                    << endl ;
00099          cout << strstream.str() << endl ;
00100          CPPUNIT_FAIL( strstream.str() ) ;
00101        }
00102      }
00103      char msgerr[MPI_MAX_ERROR_STRING] ;
00104      int lenerr ;
00105      mpi_access.errorString(sts, msgerr, &lenerr) ;
00106      cout << "test" << myrank << " lenerr " << lenerr << " "
00107           << msgerr << endl ;
00108 
00109      if ( sts != MPI_SUCCESS ) {
00110        ostringstream strstream ;
00111        strstream << "==========================================================="
00112                  << "test" << myrank << " KO"
00113                  << "==========================================================="
00114                  << endl ;
00115        cout << strstream.str() << endl ;
00116        CPPUNIT_FAIL( strstream.str() ) ;
00117      }
00118      mpi_access.check() ;
00119   }
00120   int flag ;
00121   mpi_access.testAll(10,RequestId,flag) ;
00122   if ( !flag ) {
00123     ostringstream strstream ;
00124     strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
00125     cout << strstream.str() << endl ;
00126     CPPUNIT_FAIL( strstream.str() ) ;
00127   }
00128   mpi_access.waitAll(10,RequestId) ;
00129   mpi_access.check() ;
00130 
00131   mpi_access.barrier() ;
00132 
00133   delete group ;
00134 
00135 //  MPI_Finalize();
00136 
00137   cout << "test" << myrank << " OK" << endl ;
00138 
00139   return ;
00140 }
00141 
00142 
00143 
00144