Index: /issm/trunk-jpl/src/c/toolkits/petsc/patches/GetOwnershipBoundariesFromRange.cpp
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/petsc/patches/GetOwnershipBoundariesFromRange.cpp	(revision 13600)
+++ /issm/trunk-jpl/src/c/toolkits/petsc/patches/GetOwnershipBoundariesFromRange.cpp	(revision 13601)
@@ -17,7 +17,11 @@
 
 	/*externals :*/
-	extern int my_rank;
-	extern int num_procs;
+	int my_rank2;
+	int num_procs2;
 	
+	/*recover my_rank2 and num_procs2:*/
+	MPI_Comm_size(comm,&num_procs2);
+	MPI_Comm_rank(comm,&my_rank2);
+
 	/*output: */
 	int lower_row,upper_row;
@@ -28,5 +32,5 @@
 
 	/*Gather all range values into allranges, for all nodes*/
-	allranges=xNew<int>(num_procs);
+	allranges=xNew<int>(num_procs2);
 	MPI_Allgather(&range,1,MPI_INT,allranges,1,MPI_INT,comm);
 
@@ -34,5 +38,5 @@
 	lower_row=0;
 	upper_row=lower_row+allranges[0];
-	for (i=1;i<=my_rank;i++){
+	for (i=1;i<=my_rank2;i++){
 		lower_row=lower_row+allranges[i-1];
 		upper_row=upper_row+allranges[i];
Index: /issm/trunk-jpl/src/c/toolkits/petsc/patches/MatToSerial.cpp
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/petsc/patches/MatToSerial.cpp	(revision 13600)
+++ /issm/trunk-jpl/src/c/toolkits/petsc/patches/MatToSerial.cpp	(revision 13601)
@@ -16,6 +16,6 @@
 
 	int i;
-	extern int my_rank;
-	extern int num_procs;
+	int my_rank2;
+	int num_procs2;
 	
 	/*Petsc variables*/
@@ -29,4 +29,8 @@
 	int buffer[3];
 	
+	/*recover my_rank2 and num_procs2:*/
+	MPI_Comm_size(comm,&num_procs2);
+	MPI_Comm_rank(comm,&my_rank2);
+
 	/*Output*/
 	double* outmatrix=NULL;
@@ -41,5 +45,5 @@
 	
 	/*Local and global allocation*/
-	if (my_rank==0)outmatrix=xNew<double>(M*N);
+	if (my_rank2==0)outmatrix=xNew<double>(M*N);
 	
 	if (range){
@@ -61,7 +65,7 @@
 	 * We send these rows to the matrix on node 0*/
 	
-	for (i=1;i<num_procs;i++){
-		if (my_rank==i){ 
-			buffer[0]=my_rank;
+	for (i=1;i<num_procs2;i++){
+		if (my_rank2==i){ 
+			buffer[0]=my_rank2;
 			buffer[1]=lower_row;
 			buffer[2]=range;
@@ -69,10 +73,10 @@
 			if (range)MPI_Send(local_matrix,N*range,MPI_DOUBLE,0,1,comm); 
 		}
-		if (my_rank==0){
+		if (my_rank2==0){
 			MPI_Recv(buffer,3,MPI_INT,i,1,comm,&status); 
 			if (buffer[2])MPI_Recv(outmatrix+(buffer[1]*N),N*buffer[2],MPI_DOUBLE,i,1,comm,&status);
 		}
 	} 
-	if (my_rank==0){ 
+	if (my_rank2==0){ 
 		//Still have the local_matrix on node 0 to take care of.
 		memcpy(outmatrix,local_matrix,N*range*sizeof(double));
Index: /issm/trunk-jpl/src/c/toolkits/petsc/patches/VecToMPISerial.cpp
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/petsc/patches/VecToMPISerial.cpp	(revision 13600)
+++ /issm/trunk-jpl/src/c/toolkits/petsc/patches/VecToMPISerial.cpp	(revision 13601)
@@ -16,6 +16,6 @@
 	
 	int i;
-	extern int num_procs; 
-	extern int my_rank;
+	int num_procs2; 
+	int my_rank2;
 
 	/*Petsc*/
@@ -34,4 +34,8 @@
 	/*Output*/
 	double* gathered_vector=NULL; //Global vector holding the final assembled vector on all nodes.
+	
+	/*recover my_rank2 and num_procs2*/
+	MPI_Comm_size(comm,&num_procs2);
+	MPI_Comm_rank(comm,&my_rank2);
 
 	VecGetSize(vector,&vector_size);
@@ -61,7 +65,7 @@
 	/*Now each node holds its local_vector containing range rows. 
 	 * We send this local_vector  to the gathered_vector on node 0*/
-	for (i=1;i<num_procs;i++){
-		if (my_rank==i){ 
-			buffer[0]=my_rank;
+	for (i=1;i<num_procs2;i++){
+		if (my_rank2==i){ 
+			buffer[0]=my_rank2;
 			buffer[1]=lower_row;
 			buffer[2]=range;
@@ -69,5 +73,5 @@
 			if (range)MPI_Send(local_vector,range,MPI_DOUBLE,0,1,comm); 
 		}
-		if (my_rank==0){
+		if (my_rank2==0){
 			MPI_Recv(buffer,3,MPI_INT,i,1,comm,&status); 
 			if (buffer[2])MPI_Recv(gathered_vector+buffer[1],buffer[2],MPI_DOUBLE,i,1,comm,&status);
@@ -75,5 +79,5 @@
 	}
 
-	if (my_rank==0){ 
+	if (my_rank2==0){ 
 		//Still have the local_vector on node 0 to take care of.
 		if (range)memcpy(gathered_vector+lower_row,local_vector,range*sizeof(double));
