Skip to content
Snippets Groups Projects
Commit 8342f113 authored by Van Dung Nguyen's avatar Van Dung Nguyen
Browse files

add PETSC_COMM_WORLD as defaut in linearSystemPETSc

parent 589f4a14
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
template <class scalar> template <class scalar>
class linearSystemPETSc : public linearSystem<scalar> { class linearSystemPETSc : public linearSystem<scalar> {
protected: protected:
MPI_Comm _comm;
int _blockSize; // for block Matrix int _blockSize; // for block Matrix
bool _isAllocated, _kspAllocated, _entriesPreAllocated; bool _isAllocated, _kspAllocated, _entriesPreAllocated;
Mat _a; Mat _a;
...@@ -55,7 +56,7 @@ class linearSystemPETSc : public linearSystem<scalar> { ...@@ -55,7 +56,7 @@ class linearSystemPETSc : public linearSystem<scalar> {
sparsityPattern _sparsity; sparsityPattern _sparsity;
void _kspCreate(); void _kspCreate();
public: public:
linearSystemPETSc(); linearSystemPETSc(MPI_Comm com = PETSC_COMM_WORLD);
virtual ~linearSystemPETSc(); virtual ~linearSystemPETSc();
void insertInSparsityPattern (int i, int j); void insertInSparsityPattern (int i, int j);
virtual bool isAllocated() const { return _isAllocated; } virtual bool isAllocated() const { return _isAllocated; }
......
...@@ -16,7 +16,7 @@ static void _try(int ierr) ...@@ -16,7 +16,7 @@ static void _try(int ierr)
template <class scalar> template <class scalar>
void linearSystemPETSc<scalar>::_kspCreate() void linearSystemPETSc<scalar>::_kspCreate()
{ {
_try(KSPCreate(PETSC_COMM_WORLD, &_ksp)); _try(KSPCreate(_comm, &_ksp));
PC pc; PC pc;
_try(KSPGetPC(_ksp, &pc)); _try(KSPGetPC(_ksp, &pc));
// set some default options // set some default options
...@@ -34,8 +34,9 @@ void linearSystemPETSc<scalar>::_kspCreate() ...@@ -34,8 +34,9 @@ void linearSystemPETSc<scalar>::_kspCreate()
} }
template <class scalar> template <class scalar>
linearSystemPETSc<scalar>::linearSystemPETSc() linearSystemPETSc<scalar>::linearSystemPETSc(MPI_Comm com)
{ {
_comm = com;
_isAllocated = false; _isAllocated = false;
_blockSize = 0; _blockSize = 0;
_kspAllocated = false; _kspAllocated = false;
...@@ -103,7 +104,7 @@ template <class scalar> ...@@ -103,7 +104,7 @@ template <class scalar>
void linearSystemPETSc<scalar>::allocate(int nbRows) void linearSystemPETSc<scalar>::allocate(int nbRows)
{ {
clear(); clear();
_try(MatCreate(PETSC_COMM_WORLD, &_a)); _try(MatCreate(_comm, &_a));
_try(MatSetSizes(_a, nbRows, nbRows, PETSC_DETERMINE, PETSC_DETERMINE)); _try(MatSetSizes(_a, nbRows, nbRows, PETSC_DETERMINE, PETSC_DETERMINE));
// override the default options with the ones from the option // override the default options with the ones from the option
// database (if any) // database (if any)
...@@ -117,7 +118,7 @@ void linearSystemPETSc<scalar>::allocate(int nbRows) ...@@ -117,7 +118,7 @@ void linearSystemPETSc<scalar>::allocate(int nbRows)
_localSize = _localRowEnd - _localRowStart; _localSize = _localRowEnd - _localRowStart;
_try(MatGetSize(_a, &_globalSize, &nbColumns)); _try(MatGetSize(_a, &_globalSize, &nbColumns));
// preallocation option must be set after other options // preallocation option must be set after other options
_try(VecCreate(PETSC_COMM_WORLD, &_x)); _try(VecCreate(_comm, &_x));
_try(VecSetSizes(_x, nbRows, PETSC_DETERMINE)); _try(VecSetSizes(_x, nbRows, PETSC_DETERMINE));
// override the default options with the ones from the option // override the default options with the ones from the option
// database (if any) // database (if any)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment