Back to index

salome-med  6.5.0
MPIAccessDEC.hxx
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 #ifndef __MPIACCESSDEC_HXX__
00021 #define __MPIACCESSDEC_HXX__
00022 
00023 #include "MPIAccess.hxx"
00024 #include "DEC.hxx"
00025 #include "LinearTimeInterpolator.hxx"
00026 
00027 #include <map>
00028 #include <iostream>
00029 
00030 namespace ParaMEDMEM
00031 {
00032   class MPIAccessDEC
00033   {
00034   public:  
00035     MPIAccessDEC( const ProcessorGroup& local_group, const ProcessorGroup& distant_group,
00036                   bool Asynchronous = true );
00037     virtual ~MPIAccessDEC();
00038     MPIAccess * getMPIAccess() { return _MPI_access; }
00039     const MPI_Comm* getComm() { return _MPI_union_group->getComm(); }
00040     void asynchronous( bool Asynchronous = true ) { _asynchronous = Asynchronous; }
00041     void setTimeInterpolator( TimeInterpolationMethod anInterp , double InterpPrecision=0 ,
00042                               int n_step_before=1, int nStepAfter=1 );
00043 
00044     void setTime( double t ) { _t = t; _dt = -1; }
00045     void setTime( double t , double dt ) { _t = t; _dt = dt; }
00046     bool outOfTime( int target ) { return (*_out_of_time)[target]; }
00047 
00048     int send( void* sendbuf, int sendcount , MPI_Datatype sendtype , int target );
00049     int recv( void* recvbuf, int recvcount , MPI_Datatype recvtype , int target );
00050     int recv( void* recvbuf, int recvcount , MPI_Datatype recvtype , int target ,
00051               int &RecvRequestId , bool Asynchronous=false );
00052     int sendRecv( void* sendbuf, int sendcount , MPI_Datatype sendtype ,
00053                   void* recvbuf, int recvcount , MPI_Datatype recvtype , int target );
00054 
00055     int allToAll( void* sendbuf, int sendcount, MPI_Datatype sendtype ,
00056                   void* recvbuf, int recvcount, MPI_Datatype recvtype );
00057     int allToAllv( void* sendbuf, int* sendcounts, int* sdispls, MPI_Datatype sendtype ,
00058                    void* recvbuf, int* recvcounts, int* rdispls, MPI_Datatype recvtype );
00059 
00060     int allToAllTime( void* sendbuf, int sendcount , MPI_Datatype sendtype ,
00061                       void* recvbuf, int recvcount , MPI_Datatype recvtype );
00062     int allToAllvTime( void* sendbuf, int* sendcounts, int* sdispls,
00063                        MPI_Datatype sendtype ,
00064                        void* recvbuf, int* recvcounts, int* rdispls,
00065                        MPI_Datatype recvtype );
00066     int checkTime( int recvcount , MPI_Datatype recvtype , int target , bool UntilEnd );
00067     int checkSent(bool WithWait=false);
00068     int checkFinalSent() { return checkSent( true ); }
00069     int checkFinalRecv();
00070   protected:
00071     int send( void* sendbuf, int sendcount , int sendoffset , MPI_Datatype sendtype ,
00072               int target, int &SendRequestId );
00073     int recv( void* recvbuf, int recvcount , int recvoffset , MPI_Datatype recvtype ,
00074               int target, int &RecvRequestId );
00075     int sendRecv( void* sendbuf, int sendcount , int sendoffset ,
00076                   MPI_Datatype sendtype , 
00077                   void* recvbuf, int recvcount , int recvoffset ,
00078                   MPI_Datatype recvtype , int target ,
00079                   int &SendRequestId ,int &RecvRequestId );
00080   private :
00081     bool _asynchronous;
00082     MPIProcessorGroup* _MPI_union_group;
00083 
00084     TimeInterpolator* _time_interpolator;
00085     int _n_step_before;
00086     int _n_step_after;
00087 
00088     int _my_rank;
00089     int _group_size;
00090     MPIAccess* _MPI_access;
00091 
00092     // Current time and deltatime of current process
00093     double _t;
00094     double _dt;
00095 
00096     // TimeMessages from each target _TimeMessages[target][Step] : TimeMessage
00097     std::vector< std::vector< TimeMessage > > *_time_messages;
00098     // Corresponding DataMessages from each target _DataMessages[target][~TimeStep]
00099     std::vector< bool >* _out_of_time;
00100     std::vector< int >* _data_messages_recv_count;
00101     std::vector< MPI_Datatype >* _data_messages_type;
00102     std::vector< std::vector< void * > >* _data_messages;
00103 
00104     typedef struct
00105     {
00106       void * SendBuffer;
00107       int Counter;
00108       MPI_Datatype DataType; }
00109       SendBuffStruct;
00110     std::map< int ,  SendBuffStruct * > *_map_of_send_buffers;
00111   };
00112 
00113   inline int MPIAccessDEC::send( void* sendbuf, int sendcount , MPI_Datatype sendtype , int target )
00114   {
00115     int SendRequestId;
00116     int sts;
00117     if ( _asynchronous )
00118       {
00119         sts = _MPI_access->ISend( sendbuf , sendcount , sendtype , target ,
00120                                   SendRequestId );
00121       }
00122     else
00123       {
00124         sts = _MPI_access->send( sendbuf , sendcount , sendtype , target ,
00125                                  SendRequestId );
00126         if ( sts == MPI_SUCCESS )
00127           free( sendbuf );
00128       }
00129     return sts;
00130   }
00131 
00132   inline int MPIAccessDEC::recv( void* recvbuf, int recvcount , MPI_Datatype recvtype , int target )
00133   {
00134     int RecvRequestId;
00135     int sts;
00136     if ( _asynchronous )
00137       sts = _MPI_access->IRecv( recvbuf , recvcount , recvtype , target , RecvRequestId );
00138     else
00139       sts = _MPI_access->recv( recvbuf , recvcount , recvtype , target ,  RecvRequestId );
00140     return sts;
00141   }
00142 
00143   inline int MPIAccessDEC::recv( void* recvbuf, int recvcount , MPI_Datatype recvtype ,
00144                                  int target ,  int &RecvRequestId , bool Asynchronous )
00145   {
00146     int sts;
00147     if ( Asynchronous )
00148       sts = _MPI_access->IRecv( recvbuf , recvcount , recvtype , target ,
00149                                 RecvRequestId );
00150     else
00151       sts = _MPI_access->recv( recvbuf , recvcount , recvtype , target ,
00152                                RecvRequestId );
00153     return sts;
00154   }
00155   
00156   inline int MPIAccessDEC::sendRecv( void* sendbuf, int sendcount , MPI_Datatype sendtype ,
00157                                      void* recvbuf, int recvcount , MPI_Datatype recvtype ,
00158                                      int target )
00159   {
00160     int SendRequestId;
00161     int RecvRequestId;
00162     int sts;
00163     if ( _asynchronous )
00164       sts = _MPI_access->ISendRecv( sendbuf , sendcount , sendtype , target ,
00165                                     SendRequestId ,
00166                                     recvbuf , recvcount , recvtype , target ,
00167                                     RecvRequestId );
00168     else
00169       sts = _MPI_access->sendRecv( sendbuf , sendcount , sendtype , target ,
00170                                    SendRequestId ,
00171                                    recvbuf , recvcount , recvtype , target ,
00172                                    RecvRequestId );
00173     return sts;
00174   }
00175 
00176   std::ostream & operator<< (std::ostream &,const TimeInterpolationMethod &);
00177 }
00178 
00179 #endif