Back to index

salome-med  6.5.0
test_MPI_Access_Send_Recv_Length.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_Send_Recv_Length() {
00044 
00045   cout << "test_MPI_Access_Send_Recv_Length" << 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     ostringstream strstream ;
00056     strstream << "test_MPI_Access_Send_Recv_Length must be runned with 2 procs" << endl ;
00057     cout << strstream.str() << endl ;
00058     CPPUNIT_FAIL( strstream.str() ) ;
00059   }
00060 
00061   cout << "test_MPI_Access_Send_Recv_Length" << myrank << endl ;
00062 
00063   ParaMEDMEM::CommInterface interface ;
00064 
00065   ParaMEDMEM::MPIProcessorGroup* group = new ParaMEDMEM::MPIProcessorGroup(interface) ;
00066 
00067   ParaMEDMEM::MPIAccess mpi_access( group ) ;
00068 
00069   if ( myrank >= 2 ) {
00070     mpi_access.barrier() ;
00071     delete group ;
00072     return ;
00073   }
00074 
00075   int target = 1 - myrank ;
00076   int RequestId[10] ;
00077   int sendbuf[9000] ;
00078   int recvbuf[9000] ;
00079   bool recvbufok ;
00080   int sts ;
00081   int i , j ;
00082   for ( i = 0 ; i < 9000 ; i++ ) {
00083      sendbuf[i] = i ;
00084   }
00085   for ( i = 0 ; i < 10 ; i++ ) {
00086      if ( myrank == 0 ) {
00087        sts = mpi_access.send( sendbuf, 1000*i, MPI_INT, target, RequestId[i] ) ;
00088        cout << "test" << myrank << " Send RequestId " << RequestId[i]
00089             << " tag " << mpi_access.sendMPITag(target) << endl ;
00090      }
00091      else {
00092        sts = MPI_SUCCESS ;
00093        RequestId[i] = -1 ;
00094        int outcount = 0 ;
00095        if ( i != 0 ) {
00096          sts = mpi_access.recv( recvbuf,1000*i+1,MPI_INT,target, RequestId[i],
00097                                 &outcount ) ;
00098        }
00099        //int source, tag, error, outcount ;
00100        //mpi_access.Status( RequestId[i], source, tag, error, outcount, true) ;
00101        cout << "test" << myrank << " Recv RequestId " << RequestId[i]
00102             << " tag " << mpi_access.recvMPITag(target)
00103             << " outcount " << outcount << endl ;
00104        recvbufok = true ;
00105        for ( j = 0 ; j < outcount ; j++ ) {
00106           if ( recvbuf[j] != j ) {
00107             cout << "test" << myrank << " recvbuf[ " << j << " ] = " << recvbuf[j]
00108                  << endl ;
00109             recvbufok = false ;
00110             break ;
00111           }
00112        }
00113        if ( (outcount != 1000*i) | !recvbufok ) {
00114          ostringstream strstream ;
00115          strstream << "==========================================================="
00116                    << endl << "test" << myrank << " outcount " << outcount
00117                    << " recvbuf " << recvbuf << " KO"
00118                    << "==========================================================="
00119                    << endl ;
00120          cout << strstream.str() << endl ;
00121          CPPUNIT_FAIL( strstream.str() ) ;
00122        }
00123      }
00124      char msgerr[MPI_MAX_ERROR_STRING] ;
00125      int lenerr ;
00126      mpi_access.errorString(sts, msgerr, &lenerr) ;
00127      cout << "test" << myrank << " lenerr " << lenerr << " "
00128           << msgerr << endl ;
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      mpi_access.check() ;
00140   }
00141   int flag ;
00142   mpi_access.testAll(10,RequestId,flag) ;
00143   if ( !flag ) {
00144     ostringstream strstream ;
00145     strstream << "test" << myrank << " flag " << flag << " KO" << endl ;
00146     cout << strstream.str() << endl ;
00147     CPPUNIT_FAIL( strstream.str() ) ;
00148   }
00149   mpi_access.waitAll(10,RequestId) ;
00150   mpi_access.check() ;
00151 
00152   if ( myrank == 0 ) {
00153     int sendrequests[10] ;
00154     int sendreqsize = mpi_access.sendRequestIds( target , 10 , sendrequests ) ;
00155     if ( sendreqsize != 0 ) {
00156       ostringstream strstream ;
00157       strstream << "=========================================================" << endl
00158                 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
00159                 << "=========================================================" << endl ;
00160       cout << strstream.str() << endl ;
00161       CPPUNIT_FAIL( strstream.str() ) ;
00162     }
00163   }
00164   else {
00165     int recvrequests[10] ;
00166     int recvreqsize = mpi_access.sendRequestIds( target , 10 , recvrequests ) ;
00167     if ( recvreqsize != 0 ) {
00168       ostringstream strstream ;
00169       strstream << "=========================================================" << endl
00170                 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
00171                 << "=========================================================" << endl ;
00172       cout << strstream.str() << endl ;
00173       CPPUNIT_FAIL( strstream.str() ) ;
00174     }
00175   }
00176 
00177   mpi_access.barrier() ;
00178 
00179   delete group ;
00180 
00181 //  MPI_Finalize();
00182 
00183   cout << "test" << myrank << " OK" << endl ;
00184 
00185   return ;
00186 }
00187 
00188 
00189 
00190