Index: /issm/trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 13609)
@@ -84,8 +84,11 @@
 	FILE       *petscoptionsfid = NULL;
 	FILE       *output_fid = NULL;
-	extern int  my_rank;
+	int         my_rank2;
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
 
 	/*Open input file on cpu 0: */
-	if(my_rank==0) IOMODEL = pfopen(inputfilename ,"rb");
+	if(my_rank2==0) IOMODEL = pfopen(inputfilename ,"rb");
 
 	/*Initialize internal data: */
@@ -127,5 +130,5 @@
 	
 	/*Close input file descriptors: */
-	if(my_rank==0) pfclose(IOMODEL,inputfilename);
+	if(my_rank2==0) pfclose(IOMODEL,inputfilename);
 
 	/*Open output file once for all and add output file name and file descriptor to parameters*/
Index: /issm/trunk-jpl/src/c/classes/Patch.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Patch.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/classes/Patch.cpp	(revision 13609)
@@ -111,6 +111,6 @@
 	int         i;
 	int         count;
-	extern int  my_rank;
-	extern int  num_procs;
+	int         my_rank2;
+	int         num_procs2;
 	int         total_numrows;
 	int         node_numrows;
@@ -119,4 +119,8 @@
 	MPI_Status  status;
 	#endif
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
+	num_procs2=IssmComm::GetSize();
 
 	/*First, figure out total number of rows combining all the cpus: */
@@ -132,8 +136,8 @@
 
 	/*Now, allocate buffer to holds all the values, on node 0: */
-	if(my_rank==0)total_values=xNew<IssmDouble>(this->numcols*total_numrows);
+	if(my_rank2==0)total_values=xNew<IssmDouble>(this->numcols*total_numrows);
 
 	/*Start by copying node 0 values onto total_values: */
-	if(my_rank==0){
+	if(my_rank2==0){
 		count=0;
 		xMemCpy<IssmDouble>(total_values+count,this->values,this->numcols*this->numrows);
@@ -143,10 +147,10 @@
 	/*Now, ask other nodes to send their values: */
 	#ifdef _HAVE_MPI_
-	for (i=1;i<num_procs;i++){
-		if (my_rank==i){ 
+	for (i=1;i<num_procs2;i++){
+		if (my_rank2==i){ 
 			MPI_Send(&this->numrows,1,MPI_INT,0,1,IssmComm::GetComm());   
 			if (this->numrows)MPI_Send(this->values,this->numrows*this->numcols,MPI_DOUBLE,0,1,IssmComm::GetComm()); 
 		}
-		if (my_rank==0){
+		if (my_rank2==0){
 			MPI_Recv(&node_numrows,1,MPI_INT,i,1,IssmComm::GetComm(),&status); 
 			if (node_numrows)MPI_Recv(total_values+count,node_numrows*this->numcols,MPI_DOUBLE,i,1,IssmComm::GetComm(),&status);
@@ -158,5 +162,5 @@
 	/*Now, node 0 has total_values, of size total_numrows*this->numcols. Update the fields in the patch, to reflect this new 
 	 * reality. For other cpus, no point in keeping their data anymore: */
-	if(my_rank==0){
+	if(my_rank2==0){
 		this->numrows=total_numrows;
 		xDelete<IssmDouble>(this->values);
Index: /issm/trunk-jpl/src/c/classes/classes.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/classes.h	(revision 13608)
+++ /issm/trunk-jpl/src/c/classes/classes.h	(revision 13609)
@@ -5,4 +5,5 @@
 #ifndef ALL_CLASSES_H_
 #define ALL_CLASSES_H_
+
 
 /*Objects derived classes, which are used in our containers: */
Index: /issm/trunk-jpl/src/c/classes/objects/ExternalResults/GenericExternalResult.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/objects/ExternalResults/GenericExternalResult.h	(revision 13608)
+++ /issm/trunk-jpl/src/c/classes/objects/ExternalResults/GenericExternalResult.h	(revision 13609)
@@ -20,4 +20,5 @@
 #include "../../../io/io.h"
 #include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../classes/IssmComm.h"
 #include "./ExternalResult.h"
 /*}}}*/
@@ -109,11 +110,14 @@
 void WriteData(FILE* fid,bool io_gather){ /*{{{*/
 			
-	extern  int my_rank;
+	int     my_rank2;
 	int     type;
 	int     size;
 	IssmPDouble  passiveDouble;
 	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
+
 	/*return if now on cpu 0: */
-	if(my_rank)return;
+	if(my_rank2)return;
 
 	/*use generic part, same for all ResultTypes: */
@@ -201,10 +205,13 @@
 template <> inline void GenericExternalResult<char*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
 
-	extern  int my_rank;
+	int     my_rank2;
 	int     type;
 	int     length;
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
 
 	/*return if now on cpu 0: */
-	if(my_rank)return;
+	if(my_rank2)return;
 
 	/*use generic part, same for all ResultTypes: */
@@ -280,15 +287,17 @@
 template <> inline void GenericExternalResult<IssmPDouble*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
 	
-	extern  int my_rank;
+	int     my_rank2;
 	int     length;
 	int     type;
 	int     rows,cols;
 	char   *name    = NULL;
-	extern  int my_rank;
 	IssmPDouble passiveDouble;
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
 
 	if(io_gather){
 		/*we are gathering the data on cpu 0, don't write on other cpus: */
-		if(my_rank) return;
+		if(my_rank2) return;
 	}
 
Index: /issm/trunk-jpl/src/c/include/globals.h
===================================================================
--- /issm/trunk-jpl/src/c/include/globals.h	(revision 13608)
+++ /issm/trunk-jpl/src/c/include/globals.h	(revision 13609)
@@ -9,8 +9,9 @@
 #include "./types.h"
 #include "../classes/IssmComm.h"
+
 COMM IssmComm::comm;
 
-int my_rank=0;
-int num_procs=1;
+//int my_rank=0;
+//int num_procs=1;
 
 #endif
Index: /issm/trunk-jpl/src/c/io/PrintfFunction.cpp
===================================================================
--- /issm/trunk-jpl/src/c/io/PrintfFunction.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/io/PrintfFunction.cpp	(revision 13609)
@@ -15,8 +15,11 @@
 	char *buffer = NULL;
 	int   n,size = 100;
-	int         string_size;
-	extern int  my_rank;
+	int   string_size;
+	int   my_rank2;
 	//variable list of arguments
 	va_list args;
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
 
 	while(true){
@@ -43,5 +46,5 @@
 
 	/*Ok, if we are running in parallel, get node 0 to print*/
-	if(my_rank==0)_printString_(buffer);
+	if(my_rank2==0)_printString_(buffer);
 
 	/*Clean up and return*/
@@ -50,6 +53,10 @@
 }
 int PrintfFunction(const string & message){
-	extern int  my_rank;
-	if(my_rank==0){
+	int  my_rank2;
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
+
+	if(my_rank2==0){
 		printf("%s\n",message.c_str());
 	}
@@ -57,6 +64,10 @@
 }
 int PrintfFunction2(const string & message){
-	extern int  my_rank;
-	if(my_rank==0){
+	int  my_rank2;
+
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
+
+	if(my_rank2==0){
 		printf("%s",message.c_str());
 	}
Index: /issm/trunk-jpl/src/c/matlab/io/PrintfFunction.cpp
===================================================================
--- /issm/trunk-jpl/src/c/matlab/io/PrintfFunction.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/matlab/io/PrintfFunction.cpp	(revision 13609)
@@ -18,5 +18,8 @@
 	int   n,size = 100;
 	int         string_size;
-	extern int  my_rank;
+	int  my_rank2;
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
 
 	//variable list of arguments
@@ -50,5 +53,5 @@
 
 	/*Ok, if we are running in parallel, get node 0 to print*/
-	if(my_rank==0)_printString_(buffer);
+	if(my_rank2==0)_printString_(buffer);
 
 	/*Clean up and return*/
Index: /issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 13609)
@@ -18,5 +18,5 @@
 void OutputResultsx(Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,Results* results){
 
-	extern int  my_rank;
+	int         my_rank2;
 	FILE       *fid                     = NULL;
 	char       *outputfilename          = NULL;
@@ -29,4 +29,7 @@
 	/*retrieve parameters: */
 	parameters->FindParam(&dakota_analysis,QmuIsdakotaEnum);
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
 
 	if(dakota_analysis){
@@ -42,5 +45,5 @@
 	/*Results do not include the type of solution being run	. In parallel, we output results to a filename, 
 	 *therefore, we need to include the solutiontype into the filename: */
-	if(my_rank==0){
+	if(my_rank2==0){
 		parameters->FindParam(&solutiontype,SolutionTypeEnum);
 		EnumToStringx(&solutiontypestring,solutiontype);
@@ -60,10 +63,10 @@
 		if(io_gather){
 			/*Just open the file for output on cpu 0. We are gathering the data on cpu 0 from all other cpus: */
-			if(my_rank==0) fid=pfopen(outputfilename ,"wb");
+			if(my_rank2==0) fid=pfopen(outputfilename ,"wb");
 		}
 		else{
 			/*We are opening different  files for output on all cpus. Append the  rank to the filename, and open: */
 			parameters->FindParam(&fid,OutputFilePointerEnum);
-			sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank);
+			sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank2);
 			fid=pfopen(cpu_outputfilename ,"wb");
 		}
@@ -84,5 +87,5 @@
 	  if((step==1) && (time==0)){
 	  if(io_gather){
-	  if(my_rank==0) pfclose(fid,outputfilename);
+	  if(my_rank2==0) pfclose(fid,outputfilename);
 	  }
 	  else pfclose(fid,cpu_outputfilename);
Index: /issm/trunk-jpl/src/c/solutions/dakota_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/solutions/dakota_core.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/solutions/dakota_core.cpp	(revision 13609)
@@ -57,5 +57,5 @@
 	#ifdef _HAVE_DAKOTA_ //only works if dakota library has been compiled in.
 	
-	extern int         my_rank;
+	int                my_rank2;
 	char*              dakota_input_file  = NULL;
 	char*              dakota_output_file = NULL;
@@ -69,6 +69,9 @@
 	femmodel->parameters->FindParam(&dakota_output_file,QmuOutNameEnum);
 	femmodel->parameters->FindParam(&dakota_error_file,QmuErrNameEnum);
+	
+	/*recover my_rank2:*/
+	my_rank2=IssmComm::GetRank();
 
-	if(my_rank==0){
+	if(my_rank2==0){
 	
 		// Instantiate/initialize the parallel library and problem description
Index: /issm/trunk-jpl/src/c/solutions/issm.cpp
===================================================================
--- /issm/trunk-jpl/src/c/solutions/issm.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/solutions/issm.cpp	(revision 13609)
@@ -16,6 +16,6 @@
 
 	/*Hack for now: */
-	MPI_Comm_rank(comm_init,&my_rank);
-	MPI_Comm_size(comm_init,&num_procs);
+	//MPI_Comm_rank(comm_init,&my_rank);
+	//MPI_Comm_size(comm_init,&num_procs);
 
 	/*Initialize femmodel from arguments provided command line: */
Index: /issm/trunk-jpl/src/c/solutions/kriging.cpp
===================================================================
--- /issm/trunk-jpl/src/c/solutions/kriging.cpp	(revision 13608)
+++ /issm/trunk-jpl/src/c/solutions/kriging.cpp	(revision 13609)
@@ -8,4 +8,7 @@
 void ProcessArguments2(char** pbinfilename,char** poutbinfilename,char** plockfilename,char** prootpath,int argc,char **argv);
 void ProcessInputfile(IssmDouble **px,IssmDouble **py,IssmDouble **pdata,int *pnobs,IssmDouble **px_interp,IssmDouble **py_interp,int *pninterp,Options **poptions,FILE* fid);
+
+int my_rank;
+int num_procs;
 
 int main(int argc,char **argv){
@@ -21,4 +24,8 @@
 	char *outbinfilename = NULL;
 	char *rootpath       = NULL;
+
+	MPI_Comm comm;
+	extern int my_rank;
+	extern int num_procs;
 
 	/*Input*/
@@ -39,5 +46,8 @@
 
 	/*Initialize environment (MPI, PETSC, MUMPS, etc ...)*/
-	EnvironmentInit(argc,argv);
+	comm=EnvironmentInit(argc,argv);
+
+	MPI_Comm_size(comm,&num_procs);
+	MPI_Comm_rank(comm,&my_rank);
 
 	/*First process inputs*/
