Index: /issm/trunk/src/c/ModelProcessorx/Partitioning.cpp
===================================================================
--- /issm/trunk/src/c/ModelProcessorx/Partitioning.cpp	(revision 3417)
+++ /issm/trunk/src/c/ModelProcessorx/Partitioning.cpp	(revision 3418)
@@ -31,7 +31,7 @@
 
 	/*output: */
-	bool*   my_elements=NULL;
-	bool*   my_vertices=NULL;
-	bool*   my_nodes=NULL;
+	bool* my_elements=NULL;
+	bool* my_vertices=NULL;
+	bool* my_nodes=NULL;
 	bool* my_bordervertices=NULL;
 
@@ -39,5 +39,5 @@
 	int* epart=NULL; //element partitioning.
 	int* npart=NULL; //node partitioning.
-	int elements_width; //size of elements
+	int  elements_width; //number of columns in elements (2d->3, 3d->6)
 	Vec  bordervertices=NULL;
 	double* serial_bordervertices=NULL;
@@ -77,4 +77,5 @@
 		epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding grids;
 	}
+
 	/*Free rifts: */
 	xfree((void**)&iomodel->riftinfo); 
@@ -161,7 +162,79 @@
 	bool*   my_vertices=NULL;
 	bool*   my_nodes=NULL;
+	bool*   my_nodescontinuous=NULL;
 	bool*   my_bordervertices=NULL;
 
 	/*Mathieu's code: */
+	/*First: get element and vertices partitioning from Continuous Galerkin: only the nodes are partitioned differently*/
+	ContinuousGalerkinPartitioning(&my_elements,&my_vertices,&my_nodescontinuous,&my_bordervertices,iomodel,iomodel_handle);
+	xfree((void**)&my_nodescontinuous);
+
+	/*Now we must build node partitioning
+	 *  - there are three nodes per element (discontinous)
+	 *  - for each element present of each partition, its three nodes will be in this partition
+	 *  - the edges require the dofs of the 2 nodes of each elements sharing the edge.
+	 *    if the 2 elements sharing the edge are on 2 different cpus, we must duplicate
+	 *    the two nodes that are not on the cpus so that the edge can access the dofs of
+	 *    all its 4 nodes
+	 */
+
+	/*Allocate*/
+	my_nodes=(int*)xcalloc(3*iomodel->numberofelements,sizeof(int));
+
+	/*First: add all the nodes of all the elements belonging to this cpu*/
+	if (strcmp(iomodel->meshtype,"2d")==0){
+		for (i=0;i<iomodel->numberofelements;i++){
+			if (my_elements[i]){
+				my_nodes[3*i+0]=1;
+				my_nodes[3*i+1]=1;
+				my_nodes[3*i+2]=1;
+			}
+		}
+	}
+	else{
+		ISSMERROR(exprintf("not implemented yet"));
+	}
+
+	/*Second: add all missing nodes*/
+	#ifdef _PARALLEL_
+
+	/*Get edges and elements*/
+	IoModelFetchData(&iomodel->edges,&iomodel->numberofedges,NULL,iomodel_handle,"edges");
+
+	/*!All elements have been partitioned above, only create elements for this CPU: */
+	for (i=0;i<iomodel->numberofedges;i++){
+
+		/*Get left and right elements*/
+		e1=iomodel->edges[4*i+2]-1; //edges are [node1 node2 elem1 elem2]
+		e2=iomodel->edges[4*i+3]-1; //edges are [node1 node2 elem1 elem2]
+
+		/* 1) If the element e1 is in the current partition
+		 * 2) and if the edge of the element is shared by another element (internal edge)
+		 * 3) and if this element is not in the same partition:
+		 * we must clone the nodes on this partition so that the loads (Numericalflux)
+		 * will have access to their properties (dofs,...)*/
+		if(my_elements[(int)e1] && !isnan(e2) && !my_elements[(int)e2]){ 
+
+			/*1: Get vertices ids*/
+			i1=(int)iomodel->edges[4*i+0];
+			i2=(int)iomodel->edges[4*i+1];
+
+			/*2: Get the column where these ids are located in the index*/
+			pos==UNDEF;
+			for(j=0;j<3;j++){
+				if (iomodel->elements[3*(int)e2+j]==i1) pos=j+1;
+			}
+			ISSMASSERT(pos!=UNDEF);
+
+			/*3: We have the id of the elements and the position of the vertices in the index
+			 * we can now create the corresponding nodes:*/
+			my_nodes[(int)e2*3+pos-1]=1;
+			my_nodes[(int)e2*3+((pos+1)%3)]=1;
+		}
+	}
+
+	/*Free data: */
+	xfree((void**)&iomodel->edges);
+	#endif
 
 	/*Assign output pointers:*/
