PetscTools.hpp
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 PETSCTOOLS_HPP_
00030 #define PETSCTOOLS_HPP_
00031
00032 #include <string>
00033 #include <vector>
00034
00035 #ifndef SPECIAL_SERIAL
00036 #include <petsc.h>
00037 #include <petscvec.h>
00038 #include <petscmat.h>
00039 #endif //SPECIAL_SERIAL
00040
00041 #define EXIT_IF_PARALLEL if(!PetscTools::IsSequential()){TS_TRACE("This test does not pass in parallel yet.");return;}
00042 #define EXIT_IF_SEQUENTIAL if(PetscTools::IsSequential()){TS_TRACE("This test is not meant to be executed in sequential.");return;}
00043
00044
00045 #ifndef NDEBUG
00046
00047
00048 #endif
00049
00050
00054 class PetscTools
00055 {
00056 private:
00058 static bool mPetscIsInitialised;
00059
00061 static unsigned mNumProcessors;
00062
00064 static unsigned mMaxNumNonzerosIfMatMpiAij;
00065
00066 #ifdef DEBUG_BARRIERS
00067
00068 static unsigned mNumBarriers;
00069 #endif
00070
00072 static unsigned mRank;
00073
00075 static inline void CheckCache()
00076 {
00077 if (mNumProcessors == 0)
00078 {
00079 ResetCache();
00080 }
00081 }
00082
00083 public:
00084
00088 static const unsigned MASTER_RANK=0;
00089
00094 static void ResetCache();
00095
00099 static bool IsSequential();
00100
00104 static unsigned GetNumProcs();
00105
00111 static unsigned GetMyRank();
00112
00118 static bool AmMaster();
00119
00125 static bool AmTopMost();
00126
00133 static void Barrier(const std::string callerId="");
00134
00135 #ifndef SPECIAL_SERIAL
00136
00141 static Vec CreateVec(int size);
00142
00150 static Vec CreateVec(int size, double value);
00151
00157 static Vec CreateVec(std::vector<double> data);
00158
00170 static void SetupMat(Mat& rMat, int numRows, int numColumns,
00171 MatType matType=(MatType) MATMPIAIJ,
00172 int numLocalRows=PETSC_DECIDE,
00173 int numLocalColumns=PETSC_DECIDE);
00174
00181 static bool ReplicateBool(bool flag);
00182
00189 static void ReplicateException(bool flag);
00190
00197 static void DumpPetscObject(const Mat& rMat, const std::string& rOutputFileFullPath);
00198
00205 static void DumpPetscObject(const Vec& rVec, const std::string& rOutputFileFullPath);
00206
00213 static void ReadPetscObject(Mat& rMat, const std::string& rOutputFileFullPath);
00214
00221 static void ReadPetscObject(Vec& rVec, const std::string& rOutputFileFullPath);
00222
00231 static void SetMaxNumNonzerosIfMatMpiAij(unsigned maxColsPerRowIfMatMpiAij);
00232
00233 #endif //SPECIAL_SERIAL
00234
00235 };
00236
00237 #endif