Back to index

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