diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h index 49af677346be58175d5e4cf9fc3f8aceadf4df94..176d8c539004a97fd40a4f536c6d49b1309330c2 100644 --- a/Solver/linearSystemPETSc.h +++ b/Solver/linearSystemPETSc.h @@ -46,6 +46,7 @@ template <class scalar> class linearSystemPETSc : public linearSystem<scalar> { protected: + MPI_Comm _comm; int _blockSize; // for block Matrix bool _isAllocated, _kspAllocated, _entriesPreAllocated; Mat _a; @@ -55,7 +56,7 @@ class linearSystemPETSc : public linearSystem<scalar> { sparsityPattern _sparsity; void _kspCreate(); public: - linearSystemPETSc(); + linearSystemPETSc(MPI_Comm com = PETSC_COMM_WORLD); virtual ~linearSystemPETSc(); void insertInSparsityPattern (int i, int j); virtual bool isAllocated() const { return _isAllocated; } diff --git a/Solver/linearSystemPETSc.hpp b/Solver/linearSystemPETSc.hpp index e017cf133a9489d5cc431e575e37fc12fa8eb611..49d76db9308172ba394534730aeff0ee7a2b0ee5 100644 --- a/Solver/linearSystemPETSc.hpp +++ b/Solver/linearSystemPETSc.hpp @@ -16,7 +16,7 @@ static void _try(int ierr) template <class scalar> void linearSystemPETSc<scalar>::_kspCreate() { - _try(KSPCreate(PETSC_COMM_WORLD, &_ksp)); + _try(KSPCreate(_comm, &_ksp)); PC pc; _try(KSPGetPC(_ksp, &pc)); // set some default options @@ -34,8 +34,9 @@ void linearSystemPETSc<scalar>::_kspCreate() } template <class scalar> -linearSystemPETSc<scalar>::linearSystemPETSc() +linearSystemPETSc<scalar>::linearSystemPETSc(MPI_Comm com) { + _comm = com; _isAllocated = false; _blockSize = 0; _kspAllocated = false; @@ -103,7 +104,7 @@ template <class scalar> void linearSystemPETSc<scalar>::allocate(int nbRows) { clear(); - _try(MatCreate(PETSC_COMM_WORLD, &_a)); + _try(MatCreate(_comm, &_a)); _try(MatSetSizes(_a, nbRows, nbRows, PETSC_DETERMINE, PETSC_DETERMINE)); // override the default options with the ones from the option // database (if any) @@ -117,7 +118,7 @@ void linearSystemPETSc<scalar>::allocate(int nbRows) _localSize = _localRowEnd - _localRowStart; _try(MatGetSize(_a, &_globalSize, &nbColumns)); // preallocation option must be set after other options - _try(VecCreate(PETSC_COMM_WORLD, &_x)); + _try(VecCreate(_comm, &_x)); _try(VecSetSizes(_x, nbRows, PETSC_DETERMINE)); // override the default options with the ones from the option // database (if any)