Index: /issm/trunk-jpl/src/c/Container/Nodes.cpp
===================================================================
--- /issm/trunk-jpl/src/c/Container/Nodes.cpp	(revision 13832)
+++ /issm/trunk-jpl/src/c/Container/Nodes.cpp	(revision 13833)
@@ -55,7 +55,4 @@
 /*FUNCTION Nodes::DistributeDofs{{{*/
 void  Nodes::DistributeDofs(int analysis_type,int setenum){
-
-	int num_procs;
-	int my_rank;
 
 	int  i;
@@ -68,6 +65,6 @@
 
 	/*recover my_rank:*/
-	my_rank=IssmComm::GetRank();
-	num_procs=IssmComm::GetSize();
+	int my_rank   = IssmComm::GetRank();
+	int num_procs = IssmComm::GetSize();
 
 	/*some check: */
@@ -98,8 +95,6 @@
 	/* Every cpu should start its own dof count at the end of the dofcount from cpu-1*/
 	dofcount=0;
-	if(my_rank!=0){
-		for(i=0;i<my_rank;i++){
-			dofcount+=alldofcount[i];
-		}
+	for(i=0;i<my_rank;i++){
+		dofcount+=alldofcount[i];
 	}
 	for (i=0;i<this->Size();i++){
@@ -202,7 +197,7 @@
 
 	int i;
-	int   max=0;
-	int   allmax;
-	int   numdofs=0;
+	int max=0;
+	int allmax;
+	int numdofs=0;
 
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
@@ -215,5 +210,5 @@
 
 			numdofs=node->GetNumberOfDofs(NoneApproximationEnum,setenum);
-			if (numdofs>max)max=numdofs;
+			if(numdofs>max)max=numdofs;
 		}
 	}
@@ -221,5 +216,5 @@
 	/*Grab max of all cpus: */
 	#ifdef _HAVE_MPI_
-	MPI_Allreduce ( (void*)&max,(void*)&allmax,1,MPI_INT,MPI_MAX,IssmComm::GetComm());
+	MPI_Allreduce((void*)&max,(void*)&allmax,1,MPI_INT,MPI_MAX,IssmComm::GetComm());
 	max=allmax;
 	#endif
@@ -231,11 +226,25 @@
 int   Nodes::NumberOfDofs(int analysis_type,int setenum){
 
-	int i;
+	int   allnumdofs;
+
+	/*Get number of dofs on current cpu (excluding clones)*/
+	int numdofs=this->NumberOfDofsLocal(analysis_type,setenum);
+
+	/*Gather from all cpus: */
+	#ifdef _HAVE_MPI_
+	MPI_Allreduce ( (void*)&numdofs,(void*)&allnumdofs,1,MPI_INT,MPI_SUM,IssmComm::GetComm());
+	#else
+	allnumdofs=numdofs;
+	#endif
+	return allnumdofs;
+}
+/*}}}*/
+/*FUNCTION Nodes::NumberOfDofsLocal{{{*/
+int   Nodes::NumberOfDofsLocal(int analysis_type,int setenum){
 
 	int   numdofs=0;
-	int   allnumdofs;
 
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
-	for(i=0;i<this->Size();i++){
+	for(int i=0;i<this->Size();i++){
 
 		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
@@ -246,18 +255,10 @@
 			/*Ok, this object is a node, ask it to plug values into partition: */
 			if (!node->IsClone()){
-
 				numdofs+=node->GetNumberOfDofs(NoneApproximationEnum,setenum);
-
 			}
 		}
 	}
 
-	/*Gather from all cpus: */
-	#ifdef _HAVE_MPI_
-	MPI_Allreduce ( (void*)&numdofs,(void*)&allnumdofs,1,MPI_INT,MPI_SUM,IssmComm::GetComm());
-	#else
-	allnumdofs=numdofs;
-	#endif
-	return allnumdofs;
+	return numdofs;
 }
 /*}}}*/
@@ -267,11 +268,9 @@
 	/*Careful! only use once all clones have been setup for all nodes!: */
 
-	int i;
-
-	int   numnodes=0;
-	int   allnumnodes=0;
+	int numnodes=0;
+	int allnumnodes=0;
 
 	/*Now go through all nodes, and get how many dofs they own, unless they are clone nodes: */
-	for(i=0;i<this->Size();i++){
+	for(int i=0;i<this->Size();i++){
 		Node* node=dynamic_cast<Node*>(this->GetObjectByOffset(i));
 
@@ -333,5 +332,5 @@
 
 	int my_rank;
-	int        sid;
+	int sid;
 
 	/*recover my_rank:*/
@@ -358,5 +357,5 @@
 	Node* node=NULL;
 
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
+	for (object=objects.begin() ; object < objects.end(); object++ ){
 
 		node=dynamic_cast<Node*>(*object);
@@ -364,5 +363,4 @@
 
 	}
-
-}
-/*}}}*/
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/c/Container/Nodes.h
===================================================================
--- /issm/trunk-jpl/src/c/Container/Nodes.h	(revision 13832)
+++ /issm/trunk-jpl/src/c/Container/Nodes.h	(revision 13833)
@@ -23,4 +23,5 @@
 		int   MaxNumDofs(int analysis_type,int setenum);
 		int   NumberOfDofs(int analysis_type,int setenum);
+		int   NumberOfDofsLocal(int analysis_type,int setenum);
 		int   NumberOfNodes(int analysis_type);
 		int   NumberOfNodes(void);
