Index: /issm/trunk/configs/linux64/linux64.sh.petsc2
===================================================================
--- /issm/trunk/configs/linux64/linux64.sh.petsc2	(revision 3222)
+++ /issm/trunk/configs/linux64/linux64.sh.petsc2	(revision 3223)
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-./configure --prefix=$ISSM_DIR --with-matlab-dir=$MATLAB_DIR --with-triangle-dir=$ISSM_DIR/externalpackages/triangle/install --with-metis-dir=$ISSM_DIR/externalpackages/metis/install --with-petsc-dir=$ISSM_DIR/externalpackages/petsc/install --with-mpi-include=$ISSM_DIR/externalpackages/mpich2/install/include  --with-mpi-lib="-L$ISSM_DIR/externalpackages/mpich2/install/lib/ -lmpich" --with-petsc-arch=$ISSM_ARCH --with-dakota-dir=$ISSM_DIR/externalpackages/dakota/install --with-blas-lapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/fblaslapack/$ISSM_ARCH --with-plapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/PLAPACKR32/$ISSM_ARCH --with-blacs-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/blacs-dev/$ISSM_ARCH --with-scalapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/SCALAPACK/$ISSM_ARCH --with-mumps-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/MUMPS_4.6.3/$ISSM_ARCH --with-fortran-lib="-L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/ -lgfortran" --with-graphics-lib=/usr/lib64/libX11.so --with-cxxoptflags="-march=opteron -O2"
+./configure --prefix=$ISSM_DIR --with-matlab-dir=$MATLAB_DIR --with-triangle-dir=$ISSM_DIR/externalpackages/triangle/install --with-metis-dir=$ISSM_DIR/externalpackages/metis/install --with-petsc-dir=$ISSM_DIR/externalpackages/petsc/install --with-mpi-include=$ISSM_DIR/externalpackages/mpich2/install/include  --with-mpi-lib="-L$ISSM_DIR/externalpackages/mpich2/install/lib/ -lmpich" --with-petsc-arch=$ISSM_ARCH --with-dakota-dir=$ISSM_DIR/externalpackages/dakota/install --with-blas-lapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/fblaslapack/$ISSM_ARCH --with-plapack-lib="-L$ISSM_DIR/externalpackages/petsc/install/externalpackages/PLAPACKR32-hg/$ISSM_ARCH -lPLAPACK" --with-plapack-include="-I$ISSM_DIR/externalpackages/petsc/install/externalpackages/PLAPACKR32-hg/$ISSM_ARCH/INCLUDE" --with-blacs-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/blacs-dev/$ISSM_ARCH --with-scalapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/SCALAPACK/$ISSM_ARCH --with-mumps-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/MUMPS_4.6.3/$ISSM_ARCH --with-fortran-lib="-L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/ -lgfortran" --with-graphics-lib=/usr/lib64/libX11.so --with-cxxoptflags="-march=opteron -O2" --with-numthreads=32 --with-petsc-version=2
Index: /issm/trunk/configs/linux64/linux64.sh.petsc3
===================================================================
--- /issm/trunk/configs/linux64/linux64.sh.petsc3	(revision 3223)
+++ /issm/trunk/configs/linux64/linux64.sh.petsc3	(revision 3223)
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+./configure --prefix=$ISSM_DIR --with-matlab-dir=$MATLAB_DIR --with-triangle-dir=$ISSM_DIR/externalpackages/triangle/install --with-metis-dir=$ISSM_DIR/externalpackages/metis/install --with-petsc-dir=$ISSM_DIR/externalpackages/petsc/install --with-petsc-version=3 --with-mpi-include=$ISSM_DIR/externalpackages/mpich2/install/include  --with-mpi-lib="-L$ISSM_DIR/externalpackages/mpich2/install/lib/ -lmpich" --with-petsc-arch=$ISSM_ARCH --with-dakota-dir=$ISSM_DIR/externalpackages/dakota/install --with-blas-lapack-dir=$ISSM_DIR/externalpackages/petsc/install/$ISSM_ARCH --with-plapack-lib="-L $ISSM_DIR/externalpackages/petsc/install/$ISSM_ARCH -lPLAPACK" --with-plapack-include="-I $ISSM_DIR/externalpackages/petsc/install/externalpackages/PLAPACKR32-hg/INCLUDE" --with-blacs-dir=$ISSM_DIR/externalpackages/petsc/install/$ISSM_ARCH --with-scalapack-dir=$ISSM_DIR/externalpackages/petsc/install/$ISSM_ARCH --with-mumps-dir=$ISSM_DIR/externalpackages/petsc/install/$ISSM_ARCH --with-fortran-lib="-L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/ -lgfortran" --with-graphics-lib=/usr/lib64/libX11.so --with-cxxoptflags="-march=opteron -O2" --with-numthreads=32
Index: /issm/trunk/m4/issm_options.m4
===================================================================
--- /issm/trunk/m4/issm_options.m4	(revision 3222)
+++ /issm/trunk/m4/issm_options.m4	(revision 3223)
@@ -286,5 +286,24 @@
 		fi
 	fi
-	
+
+	AC_ARG_WITH([petsc-version],
+			  AS_HELP_STRING([--with-petsc-version = VERSION],
+							 [petsc version -- 2 or 3]),
+			  [PETSC_VERSION=$withval],[PETSC_VERSION=""])
+
+	if test "$PARALLEL_VALUE" = "yes" ; then
+		if test "$PETSC_VERSION" = "" ; then
+			AC_MSG_ERROR([missing --with-petsc-version argument for parallel compilation!])
+		fi
+		if test "$PETSC_VERSION" = "2" ; then
+		AC_DEFINE([_PETSC_VERSION_],[2],[ Petsc version number])
+		fi
+
+		if test "$PETSC_VERSION" = "3" ; then
+		AC_DEFINE([_PETSC_VERSION_],[3],[ Petsc version number])
+		fi
+	fi
+	
+		
 	AC_ARG_WITH([petsc-arch],
 			  AS_HELP_STRING([--with-petsc-arch = DIR],
@@ -315,5 +334,5 @@
 			;;
 		esac
-								  
+	
 
 
@@ -481,20 +500,30 @@
 	
 	dnl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%plapack-beginning%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-	AC_ARG_WITH([plapack-dir],
-			  AS_HELP_STRING([--with-plapack-dir = DIR],
-							 [plapack root directory]),
-			  [PLAPACK_ROOT=$withval],[PLAPACK_ROOT=""])
-			  
-	AC_MSG_CHECKING(for Plapack headers and libraries in $PLAPACK_ROOT)
-	if test -d "$PLAPACK_ROOT"; then
-
-		dnl defaults
-		HAVE_PLAPACK=yes
-		PLAPACKINCL=-I"$PLAPACK_ROOT/INCLUDE"
-		PLAPACKLIB=-L"$PLAPACK_ROOT/ -lPLAPACK"
-
-		AC_DEFINE([_HAVE_PLAPACK_],[1],[with Plapack in ISSM src])
-		AC_SUBST([PLAPACKINCL])
-		AC_SUBST([PLAPACKLIB])
+	AC_ARG_WITH([plapack-lib],
+			  AS_HELP_STRING([--with-plapack-lib = lib],
+							 [plapack library]),
+			  [PLAPACK_LIB=$withval],[PLAPACK_LIB=""])
+	AC_MSG_CHECKING(for Plapack libraries)
+	
+	AC_ARG_WITH([plapack-include],
+			  AS_HELP_STRING([--with-plapack-include = include],
+							 [plapack include ]),
+			  [PLAPACK_INCLUDE=$withval],[PLAPACK_INCLUDE=""])
+	AC_MSG_CHECKING(for Plapack headers)
+	  
+	if test -n "$PLAPACK_LIB"; then
+		if test -n "$PLAPACK_INCLUDE"; then
+		
+			dnl defaults
+			HAVE_PLAPACK=yes
+			PLAPACKINCL="$PLAPACK_INCLUDE"
+			PLAPACKLIB="$PLAPACK_LIB"
+
+			AC_DEFINE([_HAVE_PLAPACK_],[1],[with Plapack in ISSM src])
+			AC_SUBST([PLAPACKINCL])
+			AC_SUBST([PLAPACKLIB])
+		else
+			HAVE_PLAPACK=no
+		fi
 	else
 		HAVE_PLAPACK=no
@@ -521,6 +550,9 @@
 		HAVE_MUMPS=yes
 		MUMPSINCL=-I"$MUMPS_ROOT/include"
-		dnl MUMPSLIB=-L"$MUMPS_ROOT/lib -ldmumps -lcmumps  -lmumps_common -lpord -lparmetis"
+		if test "$PETSC_VERSION" = "2" ; then
 		MUMPSLIB=-L"$MUMPS_ROOT/lib -ldmumps -lcmumps  -lpord "
+		else
+		MUMPSLIB=-L"$MUMPS_ROOT/lib -ldmumps -lcmumps  -lmumps_common -lpord -lparmetis"
+		fi
 
 		AC_DEFINE([_HAVE_MUMPS_],[1],[with Mumps in ISSM src])
Index: /issm/trunk/src/c/Reduceloadfromgtofx/Reduceloadfromgtofx.cpp
===================================================================
--- /issm/trunk/src/c/Reduceloadfromgtofx/Reduceloadfromgtofx.cpp	(revision 3222)
+++ /issm/trunk/src/c/Reduceloadfromgtofx/Reduceloadfromgtofx.cpp	(revision 3223)
@@ -2,4 +2,11 @@
  * \brief reduce loads from g set to f set 
  */
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
 
 #include "./Reduceloadfromgtofx.h"
@@ -36,5 +43,9 @@
 		
 			/*Create G_mn'*/
+			#if _PETSC_VERSION_ == 2
 			MatTranspose(G_mn,&tG_mn);  
+			#else
+			MatTranspose(G_mn,MAT_INITIAL_MATRIX,&tG_mn);  
+			#endif
 
 			/*Create G_mn' * pm*/
Index: /issm/trunk/src/c/Reducematrixfromgtofx/Reducematrixfromgton.cpp
===================================================================
--- /issm/trunk/src/c/Reducematrixfromgtofx/Reducematrixfromgton.cpp	(revision 3222)
+++ /issm/trunk/src/c/Reducematrixfromgtofx/Reducematrixfromgton.cpp	(revision 3223)
@@ -50,5 +50,9 @@
 			
 			//K_nn = K_nn + G_mn' * K_mn;
+			#if _PETSC_VERSION_ == 2
 			MatTranspose(Gmn,&tGmn);
+			#else
+			MatTranspose(Gmn,MAT_INITIAL_MATRIX,&tGmn);
+			#endif
 			MatMatMult(tGmn,Kmn,MAT_INITIAL_MATRIX,PETSC_DEFAULT,&tGmnKmn);
 			MatAXPY(Knn,a,tGmnKmn,DIFFERENT_NONZERO_PATTERN);
Index: /issm/trunk/src/c/Solverx/Solverx.cpp
===================================================================
--- /issm/trunk/src/c/Solverx/Solverx.cpp	(revision 3222)
+++ /issm/trunk/src/c/Solverx/Solverx.cpp	(revision 3223)
@@ -19,5 +19,6 @@
 	
 	/*Solver*/
-	KSP ksp=NULL;
+	KSP ksp=NULL; 
+	PC  pc=NULL;
 	int iteration_number;
 	PetscTruth flag;
@@ -39,4 +40,5 @@
 	PetscOptionsDetermineSolverType(&solver_type,solver_string);
 
+	#if _PETSC_VERSION_ == 2 
 	if (solver_type==MUMPSPACKAGE_LU){
 		/*Convert Kff to MATTAIJMUMPS: */
@@ -59,5 +61,5 @@
 		MatConvert(Kff,MATSUPERLU_DIST,MAT_REUSE_MATRIX,&Kff);
 	}
-
+	#endif
 
 	/*Prepare solver*/
@@ -65,4 +67,13 @@
 	KSPSetOperators(ksp,Kff,Kff,DIFFERENT_NONZERO_PATTERN);
 	KSPSetFromOptions(ksp);
+
+	#if _PETSC_VERSION_ == 3 
+	/*specific solver?: */
+	KSPGetPC(ksp,&pc);
+	if (solver_type==MUMPSPACKAGE_LU){
+		PCFactorSetMatSolverPackage(pc,MAT_SOLVER_MUMPS);
+	}
+	#endif
+
 
 	/*If initial guess for solution, use it, except if we are using the MUMPS direct solver, where any initial 
Index: /issm/trunk/src/c/toolkits/petsc/patches/PetscOptionsDetermineSolverType.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/PetscOptionsDetermineSolverType.cpp	(revision 3222)
+++ /issm/trunk/src/c/toolkits/petsc/patches/PetscOptionsDetermineSolverType.cpp	(revision 3223)
@@ -45,5 +45,9 @@
 
 	/*The list of options is going to be pairs of the type "-option option_value"*/
+	#if _PETSC_VERSION_ == 2
 	PetscToken *token=NULL;
+	#else
+	PetscToken token=NULL;
+	#endif
 	char* first=NULL;
 	char* second=NULL;
Index: /issm/trunk/src/c/toolkits/petsc/patches/PetscOptionsInsertMultipleString.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/PetscOptionsInsertMultipleString.cpp	(revision 3222)
+++ /issm/trunk/src/c/toolkits/petsc/patches/PetscOptionsInsertMultipleString.cpp	(revision 3223)
@@ -25,5 +25,9 @@
 
 	/*The list of options is going to be pairs of the type "-option option_value"*/
-	PetscToken *token=NULL;
+	#if _PETSC_VERSION_ == 2
+		PetscToken *token=NULL ;
+	#else
+		PetscToken token=NULL;
+	#endif
 	char* first=NULL;
 	char* second=NULL;
