DistributedVectorFactory.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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 // Needs to be included last
00040 #include <boost/serialization/export.hpp>
00041 
00053  class DistributedVectorFactory
00054 {
00055 private:
00056     // Data global to all vectors created by this factory.
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         // Nothing to do - all done in load_construct_data
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 // Declare identifier for the serializer
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 } // namespace ...
00217 
00218 #endif /*DISTRIBUTEDVECTORFACTORY_HPP_*/

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5