Index: ../trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/FemModel.cpp	(revision 13735)
+++ ../trunk-jpl/src/c/classes/FemModel.cpp	(revision 13736)
@@ -26,6 +26,7 @@
 	int* analyses=NULL;
 	int  numanalyses;
 	int  solution_type;
+	int  ierr;
 
 	/*File names*/
 	char *lockfilename   = NULL;
@@ -37,6 +38,10 @@
 	/*First things first, store the communicator, and set it as a global variable: */
 	this->comm=incomm;
 	this->SetStaticComm();
+	
+	/*Now, initialize PETSC: */
+	PETSC_COMM_WORLD=this->comm;
+	ierr=PetscInitialize(&argc,&argv,(char*)0,"");  if(ierr) _error_("Could not initialize Petsc");
 
 	/*Start profiler: */
 	this->profiler=new Profiler();
@@ -121,6 +126,11 @@
 
 	/*Now delete: */
 	delete profiler;
+	
+	/*Finalize PETSC for this model: */
+	_pprintLine_("closing Petsc");
+	PetscFinalize(); 
+
 }
 /*}}}*/
 
Index: ../trunk-jpl/src/c/solutions/EnvironmentFinalize.cpp
===================================================================
--- ../trunk-jpl/src/c/solutions/EnvironmentFinalize.cpp	(revision 13735)
+++ ../trunk-jpl/src/c/solutions/EnvironmentFinalize.cpp	(revision 13736)
@@ -12,13 +12,18 @@
 
 void EnvironmentFinalize(void){
 
-	#ifdef _HAVE_PETSC_
-	_pprintLine_("closing MPI and Petsc");
-	PetscFinalize(); 
-	#else
+	int my_rank=0;
 	#ifdef _HAVE_MPI_
-	_pprintLine_("closing MPI");
+	/*Make sure we are all here!)*/
+	MPI_Barrier(MPI_COMM_WORLD);
+	
+	/*Print closing statement: */
+	#ifdef _HAVE_MPI_
+	MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
+	#endif
+	if(!my_rank) printf("closing MPI\n");
+
+	/*Finalize: */
 	MPI_Finalize();
 	#endif
-	#endif
 }
Index: ../trunk-jpl/src/c/solutions/EnvironmentInit.cpp
===================================================================
--- ../trunk-jpl/src/c/solutions/EnvironmentInit.cpp	(revision 13735)
+++ ../trunk-jpl/src/c/solutions/EnvironmentInit.cpp	(revision 13736)
@@ -15,12 +15,8 @@
 	/*Output*/
 	COMM comm = 0;
 
-	/*Initialize environments: Petsc, MPI, etc...: */
-	#if defined (_HAVE_PETSC_)
-	int ierr=PetscInitialize(&argc,&argv,(char*)0,"");  
-	if(ierr) _error_("Could not initialize Petsc");
-	comm = MPI_COMM_WORLD;
-	#elif defined(_HAVE_MPI_)
+	/*Initialize MPI environment: */
+	#if defined(_HAVE_MPI_)
 	MPI_Init(&argc,&argv);
 	comm = MPI_COMM_WORLD;
 	#else
