Back to index

salome-med  6.5.0
test_MPI_Access_ISend_IRecv_Length_1.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_1() {
00044 
00045   //  MPI_Init(&argc, &argv) ; 
00046 
00047   int size ;
00048   int myrank ;
00049   MPI_Comm_size(MPI_COMM_WORLD,&size) ;
00050   MPI_Comm_rank(MPI_COMM_WORLD,&myrank) ;
00051 
00052   if ( size < 2 ) {
00053     ostringstream strstream ;
00054     strstream << "test_MPI_Access_ISend_IRecv_Length_1 must be runned with 2 procs" << endl ;
00055     cout << strstream.str() << endl ;
00056     CPPUNIT_FAIL( strstream.str() ) ;
00057   }
00058 
00059   cout << "test_MPI_Access_ISend_IRecv_Length_1" << 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 #define maxreq 10
00068 
00069   if ( myrank >= 2 ) {
00070     mpi_access.barrier() ;
00071     delete group ;
00072     return ;
00073   }
00074 
00075   int target = 1 - myrank ;
00076   int SendRequestId[maxreq] ;
00077   int RecvRequestId[maxreq] ;
00078   int sts ;
00079   int sendbuf[1000*(maxreq-1)] ;
00080   int recvbuf[maxreq-1][1000*(maxreq-1)] ;
00081   int maxirecv = 1 ;
00082   int i ;
00083   RecvRequestId[0] = -1 ;
00084   for ( i = 0 ; i < 1000*(maxreq-1) ; i++ ) {
00085     sendbuf[i] = i ;
00086   }
00087   for ( i = 0 ; i < maxreq ; i++ ) {
00088     sts = MPI_SUCCESS ;
00089     if ( myrank == 0 ) {
00090       sts = mpi_access.ISend( sendbuf, 1000*i, MPI_INT, target, SendRequestId[i] ) ;
00091       cout << "test" << myrank << " ISend RequestId " << SendRequestId[i]
00092            << " tag " << mpi_access.sendMPITag(target) << endl ;
00093     }
00094     int j ;
00095     for (j = 1 ; j <= i ; j++) {
00096       int source ;
00097       MPI_Datatype datatype ;
00098       int outcount ;
00099       int flag ;
00100       if ( myrank == 0 ) {
00101         mpi_access.test( SendRequestId[j], flag ) ;
00102       }
00103       else {
00104         int MPITag ;
00105         sts = mpi_access.IProbe( target , source, MPITag, datatype,
00106                                  outcount, flag) ;
00107         char msgerr[MPI_MAX_ERROR_STRING] ;
00108         int lenerr ;
00109         mpi_access.errorString(sts, msgerr, &lenerr) ;
00110         cout << "test" << myrank << " IProbe lenerr " << lenerr << " "
00111              << msgerr << endl ;
00112         if ( sts != MPI_SUCCESS ) {
00113           ostringstream strstream ;
00114           strstream << "==========================================================="
00115                     << "test" << myrank << " IProbe KO"
00116                     << "==========================================================="
00117                     << endl ;
00118           cout << strstream.str() << endl ;
00119           CPPUNIT_FAIL( strstream.str() ) ;
00120         }
00121         cout << "test" << myrank << " IProbe i/j " << i << "/" << j
00122              << " MPITag " << MPITag << " datatype " << datatype
00123              << " outcount " << outcount << " flag " << flag << endl ;
00124       }
00125       if ( flag ) {
00126         if ( myrank == 0 ) {
00127           int target, tag, error, outcount ;
00128           mpi_access.status( SendRequestId[j], target, tag, error, outcount,
00129                              true ) ;
00130           cout << "test" << myrank << " Test(Send RequestId " << SendRequestId[j]
00131                << ") : target " << target << " tag " << tag << " error " << error
00132                << " flag " << flag << endl ;
00133         }
00134         else {
00135           sts = mpi_access.IRecv( recvbuf[maxirecv], outcount, datatype, source,
00136                                   RecvRequestId[maxirecv] ) ;
00137           cout << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId "
00138                << RecvRequestId[maxirecv] << " source " << source
00139                << " outcount " << outcount << " tag "
00140                << mpi_access.recvMPITag(target) << endl ;
00141           maxirecv = maxirecv + 1 ;
00142         }
00143       }
00144       else if ( myrank == 1 && i == maxreq-1 && j >= maxirecv ) {
00145         sts = mpi_access.IRecv( recvbuf[j], 1000*j, MPI_INT, target,
00146                                 RecvRequestId[j] ) ;
00147         cout << "test" << myrank << " maxirecv " << maxirecv << " IRecv RequestId "
00148              << RecvRequestId[j] << " target " << target << " length " << 1000*j
00149              << " tag " << mpi_access.recvMPITag(target) << endl ;
00150         maxirecv = maxirecv + 1 ;
00151       }
00152     }
00153     char msgerr[MPI_MAX_ERROR_STRING] ;
00154     int lenerr ;
00155     mpi_access.errorString(sts, msgerr, &lenerr) ;
00156     cout << "test" << myrank << " lenerr " << lenerr << " "
00157          << msgerr << endl ;
00158 
00159     if ( sts != MPI_SUCCESS ) {
00160       ostringstream strstream ;
00161       strstream << "==========================================================="
00162                 << endl << "test" << myrank << " KO" << endl 
00163                 << "==========================================================="
00164                 << endl ;
00165       cout << strstream.str() << endl ;
00166       CPPUNIT_FAIL( strstream.str() ) ;
00167     }
00168   }
00169 
00170   mpi_access.check() ;
00171   int flag ;
00172   if ( myrank == 0 ) {
00173     mpi_access.testAll( maxreq, SendRequestId, flag ) ;
00174     cout << "test" << myrank << " TestAll SendRequest flag " << flag << endl ;
00175   }
00176   else {
00177     int i ;
00178     int source ;
00179     int outcount ;
00180     int flag ;
00181     if ( maxirecv != maxreq ) {
00182       ostringstream strstream ;
00183       strstream << "==========================================================="
00184                 << endl << "test" << myrank << " KO" << " maxirecv " << maxirecv
00185                 << " != maxreq " << maxreq << endl 
00186                 << "==========================================================="
00187                 << endl ;
00188       cout << strstream.str() << endl ;
00189       CPPUNIT_FAIL( strstream.str() ) ;
00190     }
00191     while ( maxirecv > 0 ) {
00192       for ( i = 1 ; i < maxreq ; i++ ) {
00193         cout << "test" << myrank << " IProbe : " << endl ;
00194         sts = mpi_access.test( RecvRequestId[i] , flag ) ;
00195         char msgerr[MPI_MAX_ERROR_STRING] ;
00196         int lenerr ;
00197         mpi_access.errorString(sts, msgerr, &lenerr) ;
00198         cout << "test" << myrank << " flag " << flag << " lenerr "
00199              << lenerr << " " << msgerr << " maxirecv " << maxirecv << endl ;
00200         if ( sts != MPI_SUCCESS ) {
00201           ostringstream strstream ;
00202           strstream << "==========================================================="
00203                     << "test" << myrank << " KO"
00204                     << "==========================================================="
00205                     << endl ;
00206           cout << strstream.str() << endl ;
00207           CPPUNIT_FAIL( strstream.str() ) ;
00208         }
00209         cout << "test" << myrank << " Test flag " << flag << endl ;
00210         if ( flag ) {
00211           int tag, error ;
00212           mpi_access.status( RecvRequestId[i] , source , tag , error ,
00213                              outcount ) ;
00214           if ( i != 0 ) {
00215             if ( outcount != 1000*i |
00216                  (recvbuf[i][outcount-1] != (outcount-1)) ) {
00217               ostringstream strstream ;
00218               strstream << "========================================================"
00219                         << endl << "test" << myrank << " outcount " << outcount
00220                         << " KO" << " i " << i
00221                         << " recvbuf " << recvbuf[i][outcount-1] << endl
00222                         << "========================================================"
00223                         << endl ;
00224               cout << strstream.str() << endl ;
00225               CPPUNIT_FAIL( strstream.str() ) ;
00226             }
00227           }
00228           else if ( outcount != 0 ) {
00229             ostringstream strstream ;
00230             strstream << "========================================================"
00231                       << endl << "test" << myrank << " outcount " << outcount
00232                       << " KO" << " i " << i << endl
00233                       << "========================================================"
00234                       << endl ;
00235             cout << strstream.str() << endl ;
00236             CPPUNIT_FAIL( strstream.str() ) ;
00237           }
00238           maxirecv = maxirecv - 1 ;
00239         }
00240       }
00241     }
00242     mpi_access.testAll( maxreq, RecvRequestId, flag ) ;
00243     cout << "test" << myrank << " TestAll RecvRequest flag " << flag << endl ;
00244   }
00245   mpi_access.check() ;
00246   cout << "test" << myrank << " WaitAll :" << endl ;
00247   if ( myrank == 0 ) {
00248     mpi_access.waitAll( maxreq, SendRequestId ) ;
00249     mpi_access.deleteRequests( maxreq, SendRequestId ) ;
00250   }
00251   else {
00252     mpi_access.waitAll( maxreq, RecvRequestId ) ;
00253     mpi_access.deleteRequests( maxreq, RecvRequestId ) ;
00254   }
00255 
00256   if ( myrank == 0 ) {
00257     int sendrequests[maxreq] ;
00258     int sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
00259     sendreqsize = mpi_access.sendRequestIds( target , maxreq , sendrequests ) ;
00260     if ( sendreqsize != 0 ) {
00261       ostringstream strstream ;
00262       strstream << "=========================================================" << endl
00263                 << "test" << myrank << " sendreqsize " << sendreqsize << " KO" << endl
00264                 << "=========================================================" << endl ;
00265       cout << strstream.str() << endl ;
00266       CPPUNIT_FAIL( strstream.str() ) ;
00267     }
00268     else {
00269       cout << "=========================================================" << endl
00270            << "test" << myrank << " sendreqsize " << sendreqsize << " OK" << endl
00271            << "=========================================================" << endl ;
00272     }
00273   }
00274   else {
00275     int recvrequests[maxreq] ;
00276     int recvreqsize = mpi_access.sendRequestIds( target , maxreq , recvrequests ) ;
00277     if ( recvreqsize != 0 ) {
00278       ostringstream strstream ;
00279       strstream << "=========================================================" << endl
00280                 << "test" << myrank << " recvreqsize " << recvreqsize << " KO" << endl
00281                 << "=========================================================" << endl ;
00282       cout << strstream.str() << endl ;
00283       CPPUNIT_FAIL( strstream.str() ) ;
00284     }
00285     else {
00286       cout << "=========================================================" << endl
00287            << "test" << myrank << " recvreqsize " << recvreqsize << " OK" << endl
00288            << "=========================================================" << endl ;
00289     }
00290   }
00291 
00292   mpi_access.barrier() ;
00293 
00294   delete group ;
00295 
00296   //  MPI_Finalize();
00297 
00298   cout << "test" << myrank << " OK" << endl ;
00299 
00300   return ;
00301 }
00302 
00303 
00304 
00305