diff --git a/Solver/eigenSolver.cpp b/Solver/eigenSolver.cpp
index 76728f89db617a25147b7547d9d60797a60c1d4c..9be0b06d07cd8b9f087d15d90f5a38407313ef5c 100644
--- a/Solver/eigenSolver.cpp
+++ b/Solver/eigenSolver.cpp
@@ -9,6 +9,9 @@
 #if defined(HAVE_SLEPC)
 
 #include <slepceps.h>
+#if SLEPC_VERSION_RELEASE != 0 && (SLEPC_VERSION_MAJOR < 3  || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR < 2))
+#define EPSDestroy(e) EPSDestroy(*(e))
+#endif
 
 void eigenSolver::_try(int ierr) const
 {
@@ -80,7 +83,11 @@ bool eigenSolver::solve(int numEigenValues, std::string which)
     _try(EPSSetWhichEigenpairs(eps, EPS_LARGEST_MAGNITUDE));
 
   // print info
+  #if (SLEPC_VERSION_RELEASE == 0 || (SLEPC_VERSION_MAJOR > 3 || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR >= 4)))
+  EPSType type;
+  #else
   const EPSType type;
+  #endif
   _try(EPSGetType(eps, &type));
   Msg::Debug("SLEPc solution method: %s", type);
 
@@ -110,7 +117,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which)
     Msg::Error("SLEPc diverged after %d iterations", its);
   else if(reason == EPS_DIVERGED_BREAKDOWN)
     Msg::Error("SLEPc generic breakdown in method");
-#if !(PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
+#if (SLEPC_VERSION_MAJOR < 3 || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR < 2))
   else if(reason == EPS_DIVERGED_NONSYMMETRIC)
     Msg::Error("The operator is nonsymmetric");
 #endif
@@ -159,20 +166,11 @@ bool eigenSolver::solve(int numEigenValues, std::string which)
       }
        _eigenVectors.push_back(ev);
     }
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
     _try(VecDestroy(&xr));
     _try(VecDestroy(&xi));
-#else
-    _try(VecDestroy(xr));
-    _try(VecDestroy(xi));
-#endif
   }
 
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
   _try(EPSDestroy(&eps));
-#else
-  _try(EPSDestroy(eps));
-#endif
 
   if(reason == EPS_CONVERGED_TOL){
     Msg::Debug("SLEPc done");
diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp
index 4449e515312872d5a543cf477d76ccb9541a3538..8f27fba74a373f1ab10c371488eb89e826862b54 100644
--- a/Solver/linearSystemPETSc.cpp
+++ b/Solver/linearSystemPETSc.cpp
@@ -29,7 +29,6 @@ void linearSystemPETScBlockDouble::_kspCreate()
 
 linearSystemPETScBlockDouble::~linearSystemPETScBlockDouble()
 {
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
   if (_isAllocated) {
     MatDestroy(&_a);
     VecDestroy(&_b);
@@ -38,16 +37,6 @@ linearSystemPETScBlockDouble::~linearSystemPETScBlockDouble()
   if (_kspAllocated) {
     KSPDestroy(&_ksp);
   }
-#else
-  if (_isAllocated) {
-    MatDestroy(_a);
-    VecDestroy(_b);
-    VecDestroy(_x);
-  }
-  if (_kspAllocated) {
-    KSPDestroy(_ksp);
-  }
-#endif
 }
 
 void linearSystemPETScBlockDouble::addToMatrix(int row, int col,
@@ -202,15 +191,9 @@ bool linearSystemPETScBlockDouble::isAllocated() const
 void linearSystemPETScBlockDouble::clear()
 {
   if(_isAllocated){
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
     MatDestroy(&_a);
     VecDestroy(&_x);
     VecDestroy(&_b);
-#else
-    MatDestroy(_a);
-    VecDestroy(_x);
-    VecDestroy(_b);
-#endif
   }
   _isAllocated = false;
 }
@@ -265,7 +248,7 @@ void linearSystemPETScBlockDouble::preAllocateEntries()
   if (!_isAllocated) Msg::Fatal("system must be allocated first");
   if (_sparsity.getNbRows() == 0) {
     PetscInt prealloc = 300;
-    PetscTruth set;
+    PetscBool set;
     PetscOptionsGetInt(PETSC_NULL, "-petsc_prealloc", &prealloc, &set);
     if (_blockSize == 0) {
       MatSeqAIJSetPreallocation(_a, prealloc, PETSC_NULL);
@@ -351,13 +334,8 @@ void linearSystemPETScBlockDouble::printMatlab(const char *filename) const
   PetscViewer viewer;
   PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer);
   PetscViewerSetFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
-  printf("export mat to %s\n", filename);
   MatView(_a, viewer);
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
   PetscViewerDestroy(&viewer);
-#else
-  PetscViewerDestroy(viewer);
-#endif
   return;
 }
 
diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h
index 8dafd26108b663988a885be3055783e374c4ab1c..c38597cd0287dbec86aca20d70f8167317d2e270 100644
--- a/Solver/linearSystemPETSc.h
+++ b/Solver/linearSystemPETSc.h
@@ -41,6 +41,7 @@
 #include "fullMatrix.h"
 #include <vector>
 #if defined(HAVE_PETSC)
+
 #ifndef SWIG
 #include "petsc.h"
 #include "petscksp.h"
@@ -50,6 +51,17 @@ typedef struct _p_Vec* Vec;
 typedef struct _p_KSP* KSP;
 #endif
 
+//support old PETSc version, try to avoid using PETSC_VERSION somewhere else
+#if PETSC_VERSION_RELEASE != 0 && (PETSC_VERSION_MAJOR < 3  || (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR < 2))
+#define KSPDestroy(k) KSPDestroy(*(k))
+#define MatDestroy(m) MatDestroy(*(m))
+#define VecDestroy(v) VecDestroy(*(v))
+#define PetscViewerDestroy(v) PetscViewerDestroy(*(v))
+#define PetscBool PetscTruth
+#define PetscOptionsGetBool PetscOptionsGetTruth
+#endif
+
+
 template <class scalar>
 class linearSystemPETSc : public linearSystem<scalar> {
   protected:
diff --git a/Solver/linearSystemPETSc.hpp b/Solver/linearSystemPETSc.hpp
index f723536b5a694d415ef846159ac03bf97fa67b3b..fdc8809d6ee961334271d5473a5777e10f40dc9e 100644
--- a/Solver/linearSystemPETSc.hpp
+++ b/Solver/linearSystemPETSc.hpp
@@ -3,10 +3,6 @@
 #include <petscksp.h>
 #include "linearSystemPETSc.h"
 
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
-#define PetscTruth PetscBool
-#define PetscOptionsGetTruth PetscOptionsGetBool
-#endif
 
 static void  _try(int ierr)
 {
@@ -58,11 +54,7 @@ linearSystemPETSc<scalar>::~linearSystemPETSc()
 {
   clear();
   if(_kspAllocated)
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
     _try(KSPDestroy(&_ksp));
-#else
-    _try(KSPDestroy(_ksp));
-#endif
 }
 
 template <class scalar>
@@ -80,7 +72,7 @@ void linearSystemPETSc<scalar>::preAllocateEntries()
   if (!_isAllocated) Msg::Fatal("system must be allocated first");
   if (_sparsity.getNbRows() == 0) {
     PetscInt prealloc = 300;
-    PetscTruth set;
+    PetscBool set;
     PetscOptionsGetInt(PETSC_NULL, "-petsc_prealloc", &prealloc, &set);
     if (_blockSize == 0) {
       _try(MatSeqAIJSetPreallocation(_a, prealloc, PETSC_NULL));
@@ -195,15 +187,9 @@ template <class scalar>
 void linearSystemPETSc<scalar>::clear()
 {
   if(_isAllocated){
-#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
     _try(MatDestroy(&_a));
     _try(VecDestroy(&_x));
     _try(VecDestroy(&_b));
-#else
-    _try(MatDestroy(_a));
-    _try(VecDestroy(_x));
-    _try(VecDestroy(_b));
-#endif
   }
   _isAllocated = false;
 }
@@ -379,7 +365,7 @@ std::vector<int> linearSystemPETSc<scalar>::getRowPointers()
   const PetscInt *rows;
   const PetscInt *columns;
   PetscInt n;
-  PetscTruth done;
+  PetscBool done;
   _try(MatGetRowIJ(_a,0,PETSC_FALSE,PETSC_FALSE,&n,&rows,&columns,&done));        //case done == PETSC_FALSE should be handled
   std::vector<int> rowPointers; // Maybe I should reserve or resize (SAM)
   for (int i = 0; i <= n; i++)
@@ -396,7 +382,7 @@ std::vector<int> linearSystemPETSc<scalar>::getColumnsIndices()
   const PetscInt *rows;
   const PetscInt *columns;
   PetscInt n;
-  PetscTruth done;
+  PetscBool done;
   _try(MatGetRowIJ(_a,0,PETSC_FALSE,PETSC_FALSE,&n,&rows,&columns,&done));        //case done == PETSC_FALSE should be handled
   MatInfo info;
   _try(MatGetInfo(_a,MAT_LOCAL,&info));