-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDaetkPetscSys.cpp
123 lines (105 loc) · 2.25 KB
/
DaetkPetscSys.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "DaetkPetscSys.h"
#include <cstdio>
namespace Daetk
{
namespace Petsc
{
namespace cc
{
#include "petsc.h"
}
bool Sys::master(){return !rank;}
bool Sys::initialized=false;
int Sys::rank=0;
int Sys::size=0;
Err::Err(){}
Err::Err(int i)
{
// CHKERRQ(i);
}
int Err::operator=(int i)
{
using namespace cc;
int line=0;
if (i)
PetscError(PETSC_COMM_SELF,line,"unknown Daetk function","unknown file",i,PETSC_ERROR_INITIAL,"a funtion in the petsc library threw an error which the enclosing daetk function can't handle");
return i;
}
Sys::Sys():
commCreator(false)
{}
Sys::Sys(int& argc, char **argv,char* help, char* file)
{
using namespace cc;
using std::cerr;
using std::endl;
using std::flush;
using std::cout;
if (initialized)
{
PetscBool isInitialized;
Err ierr=PetscInitialized(&isInitialized);
assert(isInitialized);
commCreator = false;
ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
}
else
{
if (!help)
help = (char*)(PETSC_NULL);
if (!file)
file = (char*)(PETSC_NULL);
commCreator=true;
Err ierr;
initialized=true;
ierr = PetscInitialize(&argc,&argv,file,help);
ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
}
}
Sys::~Sys()
{
using namespace cc;
if (commCreator)
{
Err ierr;
PetscBool finalizedAlready(PETSC_FALSE);
ierr = cc::PetscFinalized(&finalizedAlready);
if (!finalizedAlready)
ierr = cc::PetscFinalize();
initialized=false;
}
}
void Sys::barrier()
{
using namespace cc;
Err ierr;
ierr = MPI_Barrier(PETSC_COMM_WORLD);
}
bool Sys::isInitialized()
{
return initialized;
}
void Sys::beginSequential(int ng)
{
using namespace cc;
ierr = PetscSequentialPhaseBegin(PETSC_COMM_WORLD,ng);
}
void Sys::endSequential(int ng)
{
using namespace cc;
ierr = PetscSequentialPhaseEnd(PETSC_COMM_WORLD,ng);
}
bool Sys::catchError(bool error)
{
using namespace cc;
int thisVal=error;
int result=error;
MPI_Allreduce(&thisVal,&result,1,MPI_INT,MPI_LOR,PETSC_COMM_WORLD);
return result;
}
int Sys::getRank(){return rank;}
int Sys::getSize(){return size;}
}//Petsc
}//Daetk