ESyS-Particle  4.0.1
mpibuf.h
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 #ifndef __MPIBUF_H
00014 #define __MPIBUF_H
00015 
00016 //--- MPI includes ---
00017 #include <mpi.h>
00018 
00019 //--- Project includes ---
00020 #include "Foundation/vec3.h"
00021 
00022 // --- STL includes ---
00023 #include <string>
00024 
00033 class AMPIBuffer
00034 {
00035  protected:
00036   MPI_Comm   m_comm; 
00037   MPI_Status m_status;
00038 
00039 public:
00040   AMPIBuffer(MPI_Comm comm){m_comm=comm;};
00041   virtual ~AMPIBuffer(){};
00042 
00043   virtual void clear()=0;
00044   virtual void append(int)=0;
00045   virtual void append(double)=0;
00046   virtual void append(const char*)=0;
00047   virtual void append(const Vec3 &) ;
00048   virtual int pop_int()=0;
00049   virtual double pop_double()=0;
00050   virtual void pop_doubles(double*,int)=0;
00051   virtual std::string pop_string()=0;
00052   virtual Vec3 pop_vector() ;
00053   const MPI_Status& status(){return m_status;};   
00054 };
00055 
00065 class AMPIBufferPP : public AMPIBuffer
00066 {
00067 public:
00068   AMPIBufferPP(MPI_Comm comm);
00069   virtual ~AMPIBufferPP(){};
00070   virtual void sendTo(int,int)=0;
00071   virtual void receiveFrom(int src=MPI_ANY_SOURCE,int tag=MPI_ANY_TAG)=0;
00072 };
00073 
00085 class CMPIBuffer : public AMPIBufferPP
00086 {
00087  private:
00088  
00089   char* m_buffer;
00090   int m_buffersize; 
00091   int m_position; 
00092   int m_int_increment,m_dbl_increment; 
00093   
00094 
00095  public:
00096   CMPIBuffer(MPI_Comm,int);
00097   virtual ~CMPIBuffer();
00098 
00099   virtual void clear(){m_position=0;};
00100   virtual void sendTo(int,int);
00101   virtual void receiveFrom(int src=MPI_ANY_SOURCE,int tag=MPI_ANY_TAG);
00102   virtual void append(int);
00103   virtual void append(double);
00104   virtual void append(const char*);
00105   bool append_checked(int);
00106   bool append_checked(double);
00107   virtual int pop_int();
00108   virtual double pop_double();
00109   virtual void pop_doubles(double*,int);
00110   virtual std::string pop_string();
00111 };
00112 
00113 #endif //__MPIBUF_H