From a461f3044c44ef7a4cd6a4a318a62d4f6148d837 Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Tue, 23 Jul 2013 17:07:48 +0000
Subject: [PATCH] petsc : zeroMatrix() : do not call MatAssembly on empty
 matrix, it destroys preallocation on petsc 3.4

---
 Solver/linearSystemPETSc.hpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Solver/linearSystemPETSc.hpp b/Solver/linearSystemPETSc.hpp
index fdc8809d6e..0e42d65d9a 100644
--- a/Solver/linearSystemPETSc.hpp
+++ b/Solver/linearSystemPETSc.hpp
@@ -280,8 +280,12 @@ void linearSystemPETSc<scalar>::zeroMatrix()
     }
   }
   if (_isAllocated && _entriesPreAllocated) {
-    _try(MatAssemblyBegin(_a, MAT_FINAL_ASSEMBLY));
-    _try(MatAssemblyEnd(_a, MAT_FINAL_ASSEMBLY));
+    PetscBool assembled;
+    _try(MatAssembled(_a, &assembled));
+    if (!assembled) {
+      _try(MatAssemblyBegin(_a, MAT_FINAL_ASSEMBLY));
+      _try(MatAssemblyEnd(_a, MAT_FINAL_ASSEMBLY));
+    }
     _try(MatZeroEntries(_a));
     _matrixModified = true;
   }
-- 
GitLab