From 0fc5231d709c2a7364b15f5a8624ffc30bd6095b Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Fri, 10 Feb 2012 16:14:18 +0000
Subject: [PATCH] dg : dgSW3dLinearSystemColumn ok in parallel

---
 Solver/linearSystemPETSc.cpp | 12 +++++++-----
 Solver/linearSystemPETSc.h   |  3 ++-
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp
index 725abf46e3..80094e0b0d 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 24dcfe64df..49af677346 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
-- 
GitLab