00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef DISTRIBUTEDVECTORFACTORY_HPP_
00030 #define DISTRIBUTEDVECTORFACTORY_HPP_
00031
00032 #include <boost/serialization/access.hpp>
00033 #include <petscvec.h>
00034
00035 #include "DistributedVector.hpp"
00036 #include "Exception.hpp"
00037 #include "PetscTools.hpp"
00038
00039
00040 #include <boost/serialization/export.hpp>
00041
00053 class DistributedVectorFactory
00054 {
00055 private:
00056
00058 unsigned mLo;
00060 unsigned mHi;
00062 unsigned mProblemSize;
00064 bool mPetscStatusKnown;
00065
00069 void CheckForPetsc();
00070
00076 void CalculateOwnership(Vec vec);
00077
00079 friend class boost::serialization::access;
00080
00087 template<class Archive>
00088 void serialize(Archive & archive, const unsigned int version)
00089 {
00090
00091 }
00092
00093
00094 public:
00100 DistributedVectorFactory(Vec vec);
00101
00108 DistributedVectorFactory(unsigned size, PetscInt local=PETSC_DECIDE);
00109
00115 Vec CreateVec();
00116
00122 Vec CreateVec(unsigned stride);
00123
00130 DistributedVector CreateDistributedVector(Vec vec);
00131
00137 bool IsGlobalIndexLocal(unsigned globalIndex);
00138
00142 unsigned GetLocalOwnership() const
00143 {
00144 return mHi - mLo;
00145 }
00146
00150 unsigned GetHigh() const
00151 {
00152 return mHi;
00153 }
00154
00158 unsigned GetLow() const
00159 {
00160 return mLo;
00161 }
00162
00166 unsigned GetProblemSize() const
00167 {
00168 return mProblemSize;
00169 }
00170
00171 };
00172
00173 BOOST_CLASS_EXPORT(DistributedVectorFactory);
00174
00175 namespace boost
00176 {
00177 namespace serialization
00178 {
00179
00180 template<class Archive>
00181 inline void save_construct_data(
00182 Archive & ar, const DistributedVectorFactory * t, const unsigned int file_version)
00183 {
00184 unsigned num_procs, lo, hi, size;
00185 hi = t->GetHigh();
00186 ar << hi;
00187 lo = t->GetLow();
00188 ar << lo;
00189 size = t->GetProblemSize();
00190 ar << size;
00191 num_procs = PetscTools::GetNumProcs();
00192 ar << num_procs;
00193 }
00194
00199 template<class Archive>
00200 inline void load_construct_data(
00201 Archive & ar, DistributedVectorFactory * t, const unsigned int file_version)
00202 {
00203 unsigned num_procs, lo, hi, size;
00204 ar >> hi;
00205 ar >> lo;
00206 ar >> size;
00207 ar >> num_procs;
00208 if (num_procs != PetscTools::GetNumProcs())
00209 {
00210 EXCEPTION("This archive was written for a different number of processors");
00211 }
00212 ::new(t)DistributedVectorFactory(size, hi-lo);
00213 }
00214
00215 }
00216 }
00217
00218 #endif