00001 #ifndef __TSOPT_MPI_GRIDPP
00002 #define __TSOPT_MPI_GRIDPP
00003
00004 #include "usempi.h"
00005 #include "gridpp.hh"
00006 #include "mpiserialdc.hh"
00007 #include "mpiseriallap.hh"
00008
00009 namespace TSOpt {
00010
00011 using RVL::Space;
00012 using RVL::StdSpace;
00013 using RVL::MPISerialDC;
00014 using RVL::MPISerialDCF;
00015 using RVL::MPISerialLAP;
00016 using RVL::LinearAlgebraPackage;
00017 using RVL::DataContainerFactory;
00018 using RVL::STRING_PAIR;
00019 using RVL::ConstContainer;
00020
00021 class MPIGridSpace: public StdSpace<ireal,ireal>,
00022 public ConstContainer<STRING_PAIR> {
00023
00024 private:
00025
00026 GridDCF f;
00027 MPISerialDCF mpif;
00028 MPISerialLAP<ireal> l;
00029 ostream & outfile;
00030
00031 protected:
00032
00033 Space<float> * clone() const { return new MPIGridSpace(*this); }
00034
00035 public:
00036
00037 MPIGridSpace(string hdr,
00038 string dtype="notype",
00039 bool _incore=false
00040 #ifdef IWAVE_USE_MPI
00041
00042 , MPI_Comm _comm=retrieveGlobalComm()
00043 #endif
00044 , ostream & _outfile = cerr)
00045 : StdSpace<ireal,ireal>(),
00046 ConstContainer<STRING_PAIR>(STRING_PAIR(dtype,hdr)),
00047 f(hdr,_incore,_outfile),
00048 mpif(f),
00049 l(f.getCellVol()
00050 , 0
00051 #ifdef IWAVE_USE_MPI
00052 , _comm
00053 #endif
00054 ),
00055 outfile(_outfile) {}
00056
00057 MPIGridSpace(MPIGridSpace const & sp)
00058 : StdSpace<ireal,ireal>(),
00059 ConstContainer<STRING_PAIR>(sp.get()),
00060 f(sp.f),
00061 mpif(f),
00062 l(sp.l),
00063 outfile(sp.outfile) {}
00064
00065 ~MPIGridSpace() {}
00066
00067 LinearAlgebraPackage<ireal> const & getLAP() const { return l; }
00068
00069 DataContainerFactory const & getDCF() const { return mpif; }
00070
00071 grid const & getGrid() const {
00072 if (retrieveGlobalRank()) {
00073 RVLException e;
00074 e<<"Error: MPIGridSpace::getGrid\n";
00075 e<<"should not be called on ranks other than 0\n";
00076 throw e;
00077 }
00078 return f.getGrid();
00079 }
00080
00081 bool isIncore() const { return f.isIncore(); }
00082
00083 ostream & write(ostream & str) const {
00084 str<<"MPIGridSpace: MPI-enabled StdSpace based on RSF grid data\n";
00085 str<<" - header file = "<<f.getFilename()<<"\n";
00086 return str;
00087 }
00088 };
00089 }
00090
00091 #endif
00092
00093