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
00030 #ifndef PETSCTOOLS_HPP_
00031 #define PETSCTOOLS_HPP_
00032
00033 #include <string>
00034 #include <vector>
00035
00036 #ifndef SPECIAL_SERIAL
00037 #include <petsc.h>
00038 #include <petscvec.h>
00039 #include <petscmat.h>
00040 #endif //SPECIAL_SERIAL
00041
00042 #define EXIT_IF_PARALLEL if(!PetscTools::IsSequential()){TS_TRACE("This test does not pass in parallel yet.");return;}
00043 #define EXIT_IF_SEQUENTIAL if(PetscTools::IsSequential()){TS_TRACE("This test is not meant to be executed in sequential.");return;}
00044
00048 class PetscTools
00049 {
00050 private:
00052 static bool mPetscIsInitialised;
00053
00055 static unsigned mNumProcessors;
00056
00058 static unsigned mRank;
00059
00061 static inline void CheckCache()
00062 {
00063 if (mNumProcessors == 0)
00064 {
00065 ResetCache();
00066 }
00067 }
00068
00069 public:
00070
00074 static const unsigned MASTER_RANK=0;
00075
00080 static void ResetCache();
00081
00085 static bool IsSequential();
00086
00090 static unsigned GetNumProcs();
00091
00097 static unsigned GetMyRank();
00098
00104 static bool AmMaster();
00105
00110 static void Barrier();
00111
00112 #ifndef SPECIAL_SERIAL
00113
00118 static Vec CreateVec(int size);
00119
00127 static Vec CreateVec(int size, double value);
00128
00134 static Vec CreateVec(std::vector<double> data);
00135
00151 static void SetupMat(Mat& rMat, int numRows, int numColumns,
00152 MatType matType=(MatType) MATMPIAIJ,
00153 int numLocalRows=PETSC_DECIDE,
00154 int numLocalColumns=PETSC_DECIDE,
00155 int maxColsPerRowIfMatMpiAij=54 );
00156
00163 static void ReplicateException(bool flag);
00164
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
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
00223 #endif //SPECIAL_SERIAL
00224
00225 };
00226
00227 #endif