diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp index 725abf46e3aac12b30726e507a22588bbc045267..80094e0b0d5a13d47a30c6fa9c91bf064c6160af 100644 --- a/Solver/linearSystemPETSc.cpp +++ b/Solver/linearSystemPETSc.cpp @@ -16,7 +16,7 @@ template class linearSystemPETSc<std::complex<double> >; void linearSystemPETScBlockDouble::_kspCreate() { - KSPCreate(PETSC_COMM_WORLD, &_ksp); + KSPCreate(_sequential ? PETSC_COMM_SELF : PETSC_COMM_WORLD, &_ksp); if (this->_parameters.count("petscPrefix")) KSPAppendOptionsPrefix(_ksp, this->_parameters["petscPrefix"].c_str()); KSPSetFromOptions(_ksp); @@ -112,15 +112,16 @@ void linearSystemPETScBlockDouble::getFromSolution(int row, fullMatrix<double> & void linearSystemPETScBlockDouble::allocate(int nbRows) { + MPI_Comm comm = _sequential ? PETSC_COMM_SELF: PETSC_COMM_WORLD; if (this->_parameters.count("petscOptions")) PetscOptionsInsertString(this->_parameters["petscOptions"].c_str()); _blockSize = strtol (_parameters["blockSize"].c_str(), NULL, 10); if (_blockSize == 0) Msg::Error ("'blockSize' parameters must be set for linearSystemPETScBlock"); clear(); - MatCreate(PETSC_COMM_WORLD, &_a); + MatCreate(comm, &_a); MatSetSizes(_a,nbRows * _blockSize, nbRows * _blockSize, PETSC_DETERMINE, PETSC_DETERMINE); - if (Msg::GetCommSize() > 1) { + if (Msg::GetCommSize() > 1 && !_sequential) { MatSetType(_a, MATMPIBAIJ); } else { MatSetType(_a, MATSEQBAIJ); @@ -136,7 +137,7 @@ void linearSystemPETScBlockDouble::allocate(int nbRows) _localRowEnd /= _blockSize; // override the default options with the ones from the option // database (if any) - VecCreate(PETSC_COMM_WORLD, &_x); + VecCreate(comm, &_x); VecSetSizes(_x, nbRows * _blockSize, PETSC_DETERMINE); // override the default options with the ones from the option // database (if any) @@ -256,11 +257,12 @@ void linearSystemPETScBlockDouble::zeroSolution() } -linearSystemPETScBlockDouble::linearSystemPETScBlockDouble() +linearSystemPETScBlockDouble::linearSystemPETScBlockDouble(bool sequential) { _entriesPreAllocated = false; _isAllocated = false; _kspAllocated = false; + _sequential = sequential; } double linearSystemPETScBlockDouble::normInfRightHandSide() const diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h index 24dcfe64df2ad699d656a501ba97a8b59775ed29..49af677346be58175d5e4cf9fc3f8aceadf4df94 100644 --- a/Solver/linearSystemPETSc.h +++ b/Solver/linearSystemPETSc.h @@ -87,6 +87,7 @@ class linearSystemPETScBlockDouble : public linearSystem<fullMatrix<double> > { Vec _b, _x; KSP _ksp; int _blockSize, _localRowStart, _localRowEnd, _globalSize, _localSize; + bool _sequential; public: void _kspCreate(); virtual void addToMatrix(int row, int col, const fullMatrix<double> &val); @@ -105,7 +106,7 @@ class linearSystemPETScBlockDouble : public linearSystem<fullMatrix<double> > { void zeroSolution(); double normInfRightHandSide() const; void insertInSparsityPattern (int i, int j); - linearSystemPETScBlockDouble(); + linearSystemPETScBlockDouble(bool sequential = false); }; #else