Back to index

salome-med  6.5.0
test_MPI_Access_ISend_IRecv_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_ISend_IRecv_Length() {
00044 
00045   cout << "test_MPI_Access_ISend_IRecv_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_ISend_IRecv_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_ISend_IRecv_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 #define maxreq 10
00070 
00071   if ( myrank >= 2 ) {
00072     mpi_access.barrier() ;
00073     delete group ;
00074     return ;
00075   }
00076 
00077   int target = 1 - myrank ;
00078   int SendRequestId[maxreq] ;
00079   int RecvRequestId[maxreq] ;
00080   int sts ;
00081   int sendbuf[1000*(maxreq-1)] ;
00082   int recvbuf[maxreq-1][1000*(maxreq-1)] ;
00083   int i ;
00084   for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) {
00085     sendbuf[i] = i ;
00086   }
00087   for ( i = 0 ; i < maxreq ; i++ ) {
00088     if ( myrank == 0 ) {
00089       sts = mpi_access.ISend( sendbuf, 1000*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       sts = mpi_access.IRecv( recvbuf[i], 1000*i, MPI_INT, target,
00095                               RecvRequestId[i] ) ;
00096       cout << "test" << myrank << " IRecv RequestId " << RecvRequestId[i]
00097            << " tag " << mpi_access.recvMPITag(target) << endl ;
00098     }
00099     int j ;
00100     for (j = 0 ; j <= i ; j++) {
00101       int flag ;
00102       if ( myrank == 0 ) {
00103         mpi_access.test( SendRequestId[j], flag ) ;
00104       }
00105       else {
00106         mpi_access.test( RecvRequestId[j], flag ) ;
00107       }
00108       if ( flag ) {
00109         int target,source, tag, error, outcount ;
00110         if ( myrank == 0 ) {
00111           mpi_access.status( SendRequestId[j], target, tag, error, outcount,
00112                              true ) ;
00113           cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
00114                << ") : target " << target << " tag " << tag << " error " << error
00115                << " flag " << flag << endl ;
00116         }
00117         else {
00118           mpi_access.status( RecvRequestId[j], source, tag, error, outcount,
00119                              true ) ;
00120           cout << "test" << myrank << " Test(Recv RequestId "
00121                << RecvRequestId[j] << ") : source " << source << " tag " << tag
00122                << " error " << error << " outcount " << outcount
00123                << " flag " << flag << endl ;
00124           if ( outcount != 0 ) {
00125             if ( (outcount != 1000*j) |
00126                  (recvbuf[j][outcount-1] != (outcount-1)) ) {
00127               ostringstream strstream ;
00128               strstream << "==========================================================="
00129                         << endl << "test" << myrank << " outcount "
00130                         << outcount << " recvbuf " << recvbuf[j][outcount-1] << " KO"
00131                         << endl
00132                         << "==========================================================="
00133                         << endl ;
00134               cout << strstream.str() << endl ;
00135               CPPUNIT_FAIL( strstream.str() ) ;
00136             }
00137             else {
00138               cout << "==========================================================="
00139                    << endl << "test" << myrank << " outcount " << outcount
00140                    << " RequestId " << RecvRequestId[j] << " recvbuf "
00141                    << recvbuf[j][outcount-1] << " OK" << endl
00142                    << "==========================================================="
00143                    << endl ;
00144             }
00145           }
00146           else {
00147             cout << "==========================================================="
00148                  << endl << "test" << myrank << " outcount " << outcount
00149                  << " RequestId " << RecvRequestId[j] << " OK" << endl
00150                  << "==========================================================="
00151                  << endl ;
00152           }
00153         }
00154       }
00155     }
00156     char msgerr[MPI_MAX_ERROR_STRING] ;
00157     int lenerr ;
00158     mpi_access.errorString(sts, msgerr, &lenerr) ;
00159     cout << "test" << myrank << " lenerr " << lenerr << " "
00160          << msgerr << endl ;
00161 
00162     if ( sts != MPI_SUCCESS ) {
00163       ostringstream strstream ;
00164       strstream << "==========================================================="
00165                 << "test" << myrank << " KO"
00166                 << "==========================================================="
00167                 << endl ;
00168       cout << strstream.str() << endl ;
00169       CPPUNIT_FAIL( strstream.str() ) ;
00170     }
00171   }
00172 
00173   mpi_access.check() ;
00174   cout << "test" << myrank << " WaitAll" << endl ;
00175   if ( myrank == 0 ) {
00176     mpi_access.waitAll(maxreq, SendRequestId) ;
00177     mpi_access.deleteRequests(maxreq, SendRequestId) ;
00178   }
00179   else {
00180     mpi_access.waitAll(maxreq, RecvRequestId) ;
00181     mpi_access.deleteRequests(maxreq, RecvRequestId) ;
00182   }
00183   mpi_access.check() ;
00184 
00185   if ( myrank == 0 ) {
00186     int sendrequests[maxreq] ;
00187     int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
00188     sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
00189     if ( sendreqsize != 0 ) {
00190       ostringstream strstream ;
00191       strstream << "=========================================================" << endl
00192                 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
00193                 << "=========================================================" << endl ;
00194       cout << strstream.str() << endl ;
00195       CPPUNIT_FAIL( strstream.str() ) ;
00196     }
00197     else {
00198       cout << "=========================================================" << endl
00199            << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
00200            << "=========================================================" << endl ;
00201     }
00202   }
00203   else {
00204     int recvrequests[maxreq] ;
00205     int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
00206     if ( recvreqsize != 0 ) {
00207       ostringstream strstream ;
00208       strstream << "=========================================================" << endl
00209                 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
00210                 << "=========================================================" << endl ;
00211       cout << strstream.str() << endl ;
00212       CPPUNIT_FAIL( strstream.str() ) ;
00213     }
00214     else {
00215       cout << "=========================================================" << endl
00216            << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
00217            << "=========================================================" << endl ;
00218     }
00219   }
00220 
00221   mpi_access.barrier() ;
00222 
00223   delete group ;
00224 
00225   //  MPI_Finalize();
00226 
00227   cout << "test" << myrank << " OK" << endl ;
00228 
00229   return ;
00230 }
00231 
00232 
00233 
00234