Index: /issm/trunk/src/c/Container/DataSet.h
===================================================================
--- /issm/trunk/src/c/Container/DataSet.h	(revision 6371)
+++ /issm/trunk/src/c/Container/DataSet.h	(revision 6372)
@@ -13,5 +13,4 @@
 /*forward declarations */
 
-
 class Elements;
 class Loads;
@@ -20,4 +19,7 @@
 class Materials;
 class Parameters;
+class Patch;
+class Results;
+class Patch;
 
 class DataSet{
@@ -62,4 +64,5 @@
 		DataSet* Copy(void);
 		int   DeleteObject(Object* object);
+		Results* SpawnTriaResults(int* indices);
 		/*}}}*/
 
@@ -69,4 +72,6 @@
 DataSet* DataSetDemarshall(char* marshalled_dataset);
 DataSet* DataSetDemarshallRaw(char** pmarshalled_dataset);
+	
+
 
 #endif
Index: /issm/trunk/src/c/Container/Elements.cpp
===================================================================
--- /issm/trunk/src/c/Container/Elements.cpp	(revision 6371)
+++ /issm/trunk/src/c/Container/Elements.cpp	(revision 6372)
@@ -42,3 +42,138 @@
 /*}}}*/
 
+
+
 /*Object management*/
+/*FUNCTION Elements::ProcessResultsUnits{{{1*/
+void Elements::ProcessResultsUnits(void){
+
+	int i;
+
+	//Process results to be output in the correct units
+	for(i=0;i<this->Size();i++){
+		Element* element=(Element*)this->GetObjectByOffset(i);
+		element->ProcessResultsUnits();
+	}
+}
+/*}}}*/
+/*FUNCTION Elements::DeleteResults{{{1*/
+void Elements::DeleteResults(void){
+	
+	int i;
+
+	for (i=0;i<this->Size();i++){
+		Element* element=(Element*)this->GetObjectByOffset(i);
+		element->DeleteResults();
+	}
+}
+/*}}}*/
+/*FUNCTION Elements::ToResults{{{1*/
+void Elements::ToResults(Results* results,Parameters* parameters,int step, double time){
+
+	/*output: */
+	Patch* patch=NULL;
+
+	/*I/O strategy: */
+	bool   io_gather=true; //the default
+
+	/*Recover parameters: */
+	parameters->FindParam(&io_gather,IoGatherEnum);
+
+
+	/*create patch object out of all results in this dataset: */
+	patch=this->ResultsToPatch();
+
+	/*Gather onto master cpu 0, if needed: */
+	#ifdef _PARALLEL_
+	if(io_gather)patch->MPI_Gather();
+	#endif
+	
+	/*create result object and add to results dataset:*/
+	if (patch->maxvertices && patch->maxnodes){
+		results->AddObject(new IntExternalResult(results->Size()+1,PatchVerticesEnum,patch->maxvertices,step,time));
+		results->AddObject(new IntExternalResult(results->Size()+1,PatchNodesEnum,   patch->maxnodes,step,time));
+		results->AddObject(new DoubleMatExternalResult(results->Size()+1,PatchEnum,patch->values,patch->numrows,patch->numcols,step,time));
+	}
+
+	/*Free ressources:*/
+	delete patch;
+
+}
+/*}}}*/
+/*FUNCTION Elements::ResultsToPatch{{{1*/
+Patch* Elements::ResultsToPatch(void){ 
+
+	/*output: */
+	Patch* patch=NULL;
+
+	/*intermediary: */
+	int i;
+	int count;
+	int numrows;
+	int numvertices;
+	int numnodes;
+	int max_numvertices;
+	int max_numnodes;
+	int element_numvertices;
+	int element_numrows;
+	int element_numnodes;
+
+	/*We are going to extract from the results within the elements, the desired results , and create a table 
+	 * of patch information, that will hold, for each element that computed the result that 
+	 * we desire, the enum_type of the result, the step and time, the id of the element, the interpolation type, the vertices ids, and the values 
+	 * at the nodes (could be different from the vertices). This will be used for visualization purposes. 
+	 * For example, we could build the following patch table, for velocities: 
+	 * 
+	 1. on a Beam element, Vx, at step 1, time .5, element id 1, interpolation type P0 (constant), vertices ids 1 and 2, one constant value 4.5
+	 VxEnum 1  .5  1 P0  1 2       4.5 NaN  NaN
+	 2. on a Tria element, Vz, at step 2, time .8, element id 2, interpolation type P1 (linear), vertices ids 1 3 and 4, with values at 3 nodes 4.5, 3.2, 2.5
+	 VzEnum 2  .8  2 P1  1 3 4     4.5 3.2  2.5
+	 * ... etc ...
+	 *
+	 * So what do we need to build the table: the maximum number of vertices included in the table, 
+	 * and the maximum number of nodal values, as well as the number of rows. Once we have that, 
+	 * we ask the elements to fill their own row in the table, by looping on the elememnts. 
+	 *
+	 * We will use the Patch object, which will store all of the information needed, and will be able 
+	 * to output itself to disk on its own. See object/Patch.h for format of this object.*/
+	
+	/*First, determine maximum number of vertices, nodes, and number of results: */
+	numrows=0;
+	numvertices=0;
+	numnodes=0;
+
+	for(i=0;i<this->Size();i++){
+
+		Element* element=(Element*)this->GetObjectByOffset(i);
+		element->PatchSize(&element_numrows,&element_numvertices,&element_numnodes);
+
+		numrows+=element_numrows;
+		if(element_numvertices>numvertices)numvertices=element_numvertices;
+		if(element_numnodes>numnodes)numnodes=element_numnodes;
+	}
+
+	#ifdef _PARALLEL_
+	/*Synchronize across cluster, so as to not end up with different sizes for each patch on each cpu: */
+	MPI_Reduce (&numvertices,&max_numvertices,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
+	MPI_Bcast(&max_numvertices,1,MPI_INT,0,MPI_COMM_WORLD);
+	numvertices=max_numvertices;
+
+	MPI_Reduce (&numnodes,&max_numnodes,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
+	MPI_Bcast(&max_numnodes,1,MPI_INT,0,MPI_COMM_WORLD);
+	numnodes=max_numnodes;
+	#endif
+
+	/*Ok, initialize Patch object: */
+	patch=new Patch(numrows,numvertices,numnodes);
+
+	/*Now, go through elements, and fill the Patch object: */
+	count=0;
+	for(i=0;i<this->Size();i++){
+		Element* element=(Element*)this->GetObjectByOffset(i);
+		element->PatchFill(&count,patch);
+	}
+
+	return patch;
+
+}
+/*}}}*/
Index: /issm/trunk/src/c/Container/Elements.h
===================================================================
--- /issm/trunk/src/c/Container/Elements.h	(revision 6371)
+++ /issm/trunk/src/c/Container/Elements.h	(revision 6372)
@@ -27,4 +27,8 @@
 		/*}}}*/
 		/*numerics: {{{1*/
+		void ProcessResultsUnits(void);
+		void DeleteResults(void);
+		void ToResults(Results* results,Parameters* parameters,int step, double time);
+		Patch* ResultsToPatch(void);
 		/*}}}*/
 
Index: /issm/trunk/src/c/Container/Materials.h
===================================================================
--- /issm/trunk/src/c/Container/Materials.h	(revision 6371)
+++ /issm/trunk/src/c/Container/Materials.h	(revision 6372)
@@ -7,5 +7,4 @@
 
 /*forward declarations */
-class Materials;
 class Parameters;
 class Elements;
Index: /issm/trunk/src/c/Container/Results.cpp
===================================================================
--- /issm/trunk/src/c/Container/Results.cpp	(revision 6371)
+++ /issm/trunk/src/c/Container/Results.cpp	(revision 6372)
@@ -69,2 +69,107 @@
 }
 /*}}}*/
+/*FUNCTION Results::Write{{{1*/
+#ifdef _SERIAL_
+void Results::Write(mxArray** pdataref){
+
+	int i,j;
+	int count;
+
+	/*output: */
+	mxArray* dataref=NULL;
+	mxArray* processeddataref=NULL;
+	mwSize nfields;
+	mwSize maxfields;
+	mwSize nsteps;
+	mwSize step;
+	const char **fnames      = NULL;
+	int         *enums       = NULL;
+	int          baseenum;
+	mwSize       onebyone[2] = {1,1};
+	mwSize       ndim        = 2;
+
+	/*How many time steps do we have? : */
+	nsteps=0;
+	for(i=0;i<this->Size();i++){
+		ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
+		step=result->GetStep();
+		if(step>nsteps)nsteps=step;
+	}
+	onebyone[0]=nsteps;
+
+	/*How many field names do we have. First, figure out how many result types we have: */
+	maxfields=(mwSize)this->Size();
+	enums=(int*)xmalloc(maxfields*sizeof(int));
+	for(i=0;i<maxfields;i++){
+		ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
+		enums[i]=result->EnumType();
+	}
+	/*Now, make result types unique: */
+	for(i=0;i<maxfields;i++){
+		if(enums[i]>=0){//if <0, it means this enum was found to replicate another one previously
+			baseenum=enums[i]; 		
+			/*is the baseenum repeated later on?:*/
+			for(j=i+1;j<maxfields;j++){
+				if (enums[j]==baseenum)enums[j]=-1;
+			}
+		}
+		else continue;
+	}
+
+	/*Now, go through enums, and whatever is not null is a non repeated field name: */
+	nfields=0;
+	for(i=0;i<maxfields;i++)if(enums[i]>0)nfields++;
+
+	/*Add 2 fields for time and step: */
+	nfields=nfields+2;
+	
+	/*Fill the names of the structure field: */
+	fnames=(const char**)xmalloc(nfields*sizeof(char*));
+	count=0;
+	for(i=0;i<maxfields;i++){
+		if (enums[i]>0){
+			fnames[count]=EnumToString(enums[i]);
+			count++;
+		}
+	}
+	/*don't forget the extra fields "time" and "step":*/
+	fnames[nfields-2]="time";
+	fnames[nfields-1]="step";
+
+	/*Initialize structure: */
+	dataref=mxCreateStructArray( ndim,onebyone,nfields,fnames);
+
+	/*Fill each field: */
+	for(i=0;i<nfields-2;i++){ //do not include the last one used for time
+		ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
+		result->SetMatlabField(dataref);
+	}
+
+	/*Now, process the patch in the dataref structure, by calling MatlabProcessPatch.m 
+	 *on the current dataref structure: */
+	mexCallMATLAB(1,&processeddataref,1,&dataref, "MatlabProcessPatch");
+
+	/*Assign output pointers:*/
+	*pdataref=processeddataref;
+}
+#else 
+void Results::Write(Parameters* parameters){
+	
+	int         i;
+	FILE       *fid          = NULL;
+
+	/*Recover file descriptor: */
+	parameters->FindParam(&fid,OutputFilePointerEnum);
+
+	for(i=0;i<this->Size();i++){
+
+		ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
+
+		/*write result to disk: */
+		result->WriteData(fid);
+
+	}
+
+}
+#endif
+/*}}}*/
Index: /issm/trunk/src/c/Container/Results.h
===================================================================
--- /issm/trunk/src/c/Container/Results.h	(revision 6371)
+++ /issm/trunk/src/c/Container/Results.h	(revision 6372)
@@ -27,10 +27,11 @@
 		/*numerics: {{{1*/
 		Results* SpawnTriaResults(int* indices);
+		#ifdef _SERIAL_
+		void Write(mxArray** pdataref);
+		#else 
+		void Write(Parameters* parameters);
+		#endif
 		/*}}}*/
-
 };
-
-
-
 #endif //ifndef _RESULTS_H_
 
Index: /issm/trunk/src/c/Container/Vertices.h
===================================================================
--- /issm/trunk/src/c/Container/Vertices.h	(revision 6371)
+++ /issm/trunk/src/c/Container/Vertices.h	(revision 6372)
@@ -8,5 +8,4 @@
 /*forward declarations */
 class Materials;
-class Parameters;
 class Elements;
 class Vertices;
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 6371)
+++ /issm/trunk/src/c/Makefile.am	(revision 6372)
@@ -415,6 +415,4 @@
 					./modules/OutputResultsx/OutputResultsx.h\
 					./modules/OutputResultsx/OutputResultsx.cpp\
-					./modules/OutputResultsx/ElementResultsToPatch.cpp\
-					./modules/OutputResultsx/MatlabWriteResults.cpp\
 					./modules/MinVelx/MinVelx.h\
 					./modules/MinVelx/MinVelx.cpp\
@@ -989,6 +987,4 @@
 					./modules/OutputResultsx/OutputResultsx.h\
 					./modules/OutputResultsx/OutputResultsx.cpp\
-					./modules/OutputResultsx/ElementResultsToPatch.cpp\
-					./modules/OutputResultsx/FileWriteResults.cpp\
 					./modules/MinVelx/MinVelx.h\
 					./modules/MinVelx/MinVelx.cpp\
Index: /issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 6371)
+++ /issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 6372)
@@ -72,4 +72,6 @@
 	parameters->AddObject(new IntParam(NumberOfElementsEnum,iomodel->numberofelements));
 	parameters->AddObject(new BoolParam(KffEnum,iomodel->kff));
+	parameters->AddObject(new BoolParam(IoGatherEnum,iomodel->io_gather));
+	parameters->AddObject(new BoolParam(IoSplitEnum,iomodel->io_split));
 
 	/*Deal with more complex parameters*/
Index: sm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp	(revision 6371)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/*!\file:  ElementResultsToPatch
- * \brief: go through our finite elements, and see what results they have stored within. 
- * Then output them into serialized patch arrays, and add to results dataset
- */ 
-
-#ifdef HAVE_CONFIG_H
-	#include "config.h"
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#include "stdio.h"
-#include "../../Container/Container.h"
-#include "../../io/io.h"
-#include "../../objects/objects.h"
-		
-void ElementResultsToPatch(Elements* elements,  Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results,int step, double time){
-
-	int i;
-
-	/*output: */
-	Patch* patch=NULL;
-
-	/*intermediary: */
-	int count;
-	int numrows;
-	int numvertices;
-	int numnodes;
-	int max_numvertices;
-	int max_numnodes;
-	int element_numvertices;
-	int element_numrows;
-	int element_numnodes;
-
-	//Process results to be output in the correct units
-	for(i=0;i<elements->Size();i++){
-		Element* element=(Element*)elements->GetObjectByOffset(i);
-		element->ProcessResultsUnits();
-	}
-
-	/*We are going to extract from the results within the elements, the desired results , and create a table 
-	 * of patch information, that will hold, for each element that computed the result that 
-	 * we desire, the enum_type of the result, the step and time, the id of the element, the interpolation type, the vertices ids, and the values 
-	 * at the nodes (could be different from the vertices). This will be used for visualization purposes. 
-	 * For example, we could build the following patch table, for velocities: 
-	 * 
-	 1. on a Beam element, Vx, at step 1, time .5, element id 1, interpolation type P0 (constant), vertices ids 1 and 2, one constant value 4.5
-	 VxEnum 1  .5  1 P0  1 2       4.5 NaN  NaN
-	 2. on a Tria element, Vz, at step 2, time .8, element id 2, interpolation type P1 (linear), vertices ids 1 3 and 4, with values at 3 nodes 4.5, 3.2, 2.5
-	 VzEnum 2  .8  2 P1  1 3 4     4.5 3.2  2.5
-	 * ... etc ...
-	 *
-	 * So what do we need to build the table: the maximum number of vertices included in the table, 
-	 * and the maximum number of nodal values, as well as the number of rows. Once we have that, 
-	 * we ask the elements to fill their own row in the table, by looping on the elememnts. 
-	 *
-	 * We will use the Patch object, which will store all of the information needed, and will be able 
-	 * to output itself to disk on its own. See object/Patch.h for format of this object.*/
-	
-	/*First, determine maximum number of vertices, nodes, and number of results: */
-	numrows=0;
-	numvertices=0;
-	numnodes=0;
-
-	for(i=0;i<elements->Size();i++){
-		Element* element=(Element*)elements->GetObjectByOffset(i);
-		element->PatchSize(&element_numrows,&element_numvertices,&element_numnodes);
-
-		numrows+=element_numrows;
-		if(element_numvertices>numvertices)numvertices=element_numvertices;
-		if(element_numnodes>numnodes)numnodes=element_numnodes;
-	}
-
-	#ifdef _PARALLEL_
-	/*Synchronize across cluster, so as to not end up with different sizes for each patch on each cpu: */
-	MPI_Reduce (&numvertices,&max_numvertices,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
-	MPI_Bcast(&max_numvertices,1,MPI_INT,0,MPI_COMM_WORLD);
-	numvertices=max_numvertices;
-
-	MPI_Reduce (&numnodes,&max_numnodes,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
-	MPI_Bcast(&max_numnodes,1,MPI_INT,0,MPI_COMM_WORLD);
-	numnodes=max_numnodes;
-	#endif
-
-	/*Ok, initialize Patch object: */
-	patch=new Patch(numrows,numvertices,numnodes);
-
-	/*Now, go through elements, and fill the Patch object: */
-	count=0;
-	for(i=0;i<elements->Size();i++){
-		Element* element=(Element*)elements->GetObjectByOffset(i);
-		element->PatchFill(&count,patch);
-	}
-
-	/*Now, gather patch onto node 0, so that we do not dump to disk from every node: */
-	patch->MPI_Gather();
-
-	/*create result object and add to results dataset (if not empty): */
-	if (patch->maxvertices && patch->maxnodes){
-		results->AddObject(new       IntExternalResult(results->Size()+1,PatchVerticesEnum,patch->maxvertices,step,time));
-		results->AddObject(new       IntExternalResult(results->Size()+1,PatchNodesEnum,   patch->maxnodes,step,time));
-		results->AddObject(new DoubleMatExternalResult(results->Size()+1,PatchEnum,patch->values,patch->numrows,patch->numcols,step,time));
-	}
-
-	/*Free ressources:*/
-	delete patch;
-
-}
Index: sm/trunk/src/c/modules/OutputResultsx/FileWriteResults.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/FileWriteResults.cpp	(revision 6371)
+++ 	(revision )
@@ -1,31 +1,0 @@
-/*!\file: FileWriteResults.cpp
- * \brief: write results in femmodel->results to disk
- */ 
-
-#ifdef HAVE_CONFIG_H
-	#include "config.h"
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#include "../../io/io.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
-
-void FileWriteResults(Parameters* parameters, DataSet* results){
-
-	int         i;
-	extern int  my_rank;
-	FILE       *fid          = NULL;
-
-	//Recover file name: 
-	parameters->FindParam(&fid,OutputFilePointerEnum);
-
-	for(i=0;i<results->Size();i++){
-		ExternalResult* result=(ExternalResult*)results->GetObjectByOffset(i);
-
-		/*write result to disk: */
-		result->WriteData(fid);
-	}
-}
Index: sm/trunk/src/c/modules/OutputResultsx/MatlabWriteResults.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/MatlabWriteResults.cpp	(revision 6371)
+++ 	(revision )
@@ -1,101 +1,0 @@
-/*!\file: MatlabWriteResults.cpp
- * \brief: write results into a matlab array
- */ 
-
-#ifdef HAVE_CONFIG_H
-	#include "config.h"
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#ifdef _SERIAL_
-
-#include <mex.h>
-#include "../../io/io.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
-
-void  MatlabWriteResults(mxArray** pdataref, Parameters* parameters, DataSet* results){
-
-	int i,j;
-	int count;
-
-	/*output: */
-	mxArray* dataref=NULL;
-	mxArray* processeddataref=NULL;
-	mwSize nfields;
-	mwSize maxfields;
-	mwSize nsteps;
-	mwSize step;
-	const char **fnames      = NULL;
-	int         *enums       = NULL;
-	int          baseenum;
-	mwSize       onebyone[2] = {1,1};
-	mwSize       ndim        = 2;
-
-	/*How many time steps do we have? : */
-	nsteps=0;
-	for(i=0;i<results->Size();i++){
-		ExternalResult* result=(ExternalResult*)results->GetObjectByOffset(i);
-		step=result->GetStep();
-		if(step>nsteps)nsteps=step;
-	}
-	onebyone[0]=nsteps;
-
-	/*How many field names do we have. First, figure out how many result types we have: */
-	maxfields=(mwSize)results->Size();
-	enums=(int*)xmalloc(maxfields*sizeof(int));
-	for(i=0;i<maxfields;i++){
-		ExternalResult* result=(ExternalResult*)results->GetObjectByOffset(i);
-		enums[i]=result->EnumType();
-	}
-	/*Now, make result types unique: */
-	for(i=0;i<maxfields;i++){
-		if(enums[i]>=0){//if <0, it means this enum was found to replicate another one previously
-			baseenum=enums[i]; 		
-			/*is the baseenum repeated later on?:*/
-			for(j=i+1;j<maxfields;j++){
-				if (enums[j]==baseenum)enums[j]=-1;
-			}
-		}
-		else continue;
-	}
-
-	/*Now, go through enums, and whatever is not null is a non repeated field name: */
-	nfields=0;
-	for(i=0;i<maxfields;i++)if(enums[i]>0)nfields++;
-
-	/*Add 2 fields for time and step: */
-	nfields=nfields+2;
-	
-	/*Fill the names of the structure field: */
-	fnames=(const char**)xmalloc(nfields*sizeof(char*));
-	count=0;
-	for(i=0;i<maxfields;i++){
-		if (enums[i]>0){
-			fnames[count]=EnumToString(enums[i]);
-			count++;
-		}
-	}
-	/*don't forget the extra fields "time" and "step":*/
-	fnames[nfields-2]="time";
-	fnames[nfields-1]="step";
-
-	/*Initialize structure: */
-	dataref=mxCreateStructArray( ndim,onebyone,nfields,fnames);
-
-	/*Fill each field: */
-	for(i=0;i<nfields-2;i++){ //do not include the last one used for time
-		ExternalResult* result=(ExternalResult*)results->GetObjectByOffset(i);
-		result->SetMatlabField(dataref);
-	}
-
-	/*Now, process the patch in the dataref structure, by calling MatlabProcessPatch.m 
-	 *on the current dataref structure: */
-	mexCallMATLAB(1,&processeddataref,1,&dataref, "MatlabProcessPatch");
-
-	/*Assign output pointers:*/
-	*pdataref=processeddataref;
-}
-#endif
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 6371)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 6372)
@@ -17,51 +17,79 @@
 		
 #ifdef _SERIAL_
-void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet** presults, int step, double time){
+void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,Results** presults, int step, double time){
 #else                                                                                                                                                                                             
-void OutputResultsx(                    Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet** presults, int step, double time){
+void OutputResultsx(                    Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,Results** presults, int step, double time){
 #endif
 
-	/*Intermediaries*/
-	int      i;
-	int      solutiontype;
-	DataSet *results;
-	Element *element;
+	extern int  my_rank;
+	FILE       *fid                     = NULL;
+	char       *outputfilename          = NULL;
+	char        cpu_outputfilename[100];        //easier to convert an integer with sprintf
+	bool        io_gather;
+	bool        io_split;
+	int         solutiontype;
+	Results    *results                 = NULL;
 
-	/*Recover results*/
+	/*recover results dataset: */
 	results=*presults;
-	
-	/*Transfer element results into the femmodel->results dataset: */
-	ElementResultsToPatch( elements,  nodes,  vertices,  loads, materials, parameters,results,step,time);
 
-	#ifdef _PARALLEL_
+
+	/*We have results inside our elements, loads, etc ... Get them out of there, into the results dataset: */
+	elements->ProcessResultsUnits();
+	elements->ToResults(results,parameters,step,time);
+	elements->DeleteResults();
+
+
 	/*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: */
-	parameters->FindParam(&solutiontype,SolutionTypeEnum);
-	results->AddObject(new StringExternalResult(results->Size()+1,SolutionTypeEnum,EnumToString(solutiontype),1,0));
+	#ifdef _PARALLEL_
+	if(my_rank==0){
+		parameters->FindParam(&solutiontype,SolutionTypeEnum);
+		results->AddObject(new StringExternalResult(results->Size()+1,SolutionTypeEnum,EnumToString(solutiontype),1,0));
+	}
+
+
+	/*Now, open file for writing, if not already done: */
+	if(!parameters->FindParam(&fid,OutputFilePointerEnum)){
+		
+		/*We don't have a file pointer. Retrieve the output file name and open it for writing:*/
+		parameters->FindParam(&outputfilename,OutputFileNameEnum);
+
+
+		/*What strategy? : */
+		parameters->FindParam(&io_gather,IoGatherEnum);
+		parameters->FindParam(&io_split,IoSplitEnum);
+		
+
+		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(io_split){
+			/*We are opening different  files for output on all cpus. Append the  rank to the filename, and open: */
+			sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank);
+			fid=pfopen(cpu_outputfilename ,"wb");
+		}
+		
+		/*Add file pointer in parameters for further calls to OutputResultsx: */
+		parameters->SetParam(fid,OutputFilePointerEnum);
+	}
+
 	#endif
 
-	/*Write data to matlab structure or filename: */
+	/*Write results to disk (in parallel), or to memory (in serial mode): */
 	#ifdef _SERIAL_
-		/*Write Matlab structure*/
-		MatlabWriteResults(pdataref,parameters,results);
-
-		/*DO NOT delete results serially*/
+		results->Write(pdataref);
 	#else
-		/*Write File*/
-		FileWriteResults(parameters,results);
-
-		/*Now delete results (ElementResults and ExternalResults)*/
-		delete results;
-		for (i=0;i<elements->Size();i++){
-			element=(Element*)elements->GetObjectByOffset(i);
-			element->DeleteResults();
-		}
+		results->Write(parameters);
 	#endif
 
 
+	/*Delete and reinitialize results, in parallel: */
+	#ifdef _PARALLEL_
+		delete results; results=new Results();
+	#endif
 
-	/*We have to reinitialize results for next step*/
-	results=new DataSet();
+	/*Assign output pointers:*/
 	*presults=results;
-
 }
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 6371)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 6372)
@@ -16,13 +16,8 @@
 #ifdef _SERIAL_
 #include <mex.h>
-void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters,DataSet** results,int step=1,double time=0);
-void MatlabWriteResults(mxArray** pdataref, Parameters* parameters, DataSet* results);
+void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters, Results** presults,int step=1,double time=0);
 #else
-void OutputResultsx(Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters,DataSet** results,int step=1,double time=0);
-void FileWriteResults(Parameters* parameters, DataSet* results);
+void OutputResultsx(Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters, Results** presults,int step=1,double time=0);
 #endif
-
-/* local prototypes: */
-void ElementResultsToPatch(Elements* elements,  Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results,int step, double time);
 
 #endif  /* _OUTPUTRESULTS_H */
Index: /issm/trunk/src/c/objects/FemModel.cpp
===================================================================
--- /issm/trunk/src/c/objects/FemModel.cpp	(revision 6371)
+++ /issm/trunk/src/c/objects/FemModel.cpp	(revision 6372)
@@ -20,9 +20,14 @@
 /*Object constructors and destructor*/
 /*FUNCTION FemModel::constructor {{{1*/
-FemModel::FemModel(ConstDataHandle IOMODEL,const int in_solution_type,const int* analyses,const int nummodels){
+FemModel::FemModel(char* inputfilename, char* outputfilename, const int in_solution_type,const int* analyses,const int nummodels){
+#ifdef _PARALLEL_
 
 	/*intermediary*/
 	int i;
 	int analysis_type;
+	FILE* IOMODEL;
+
+	/*Open input file on cpu 0: */
+	if(my_rank==0) IOMODEL= pfopen(inputfilename ,"rb");
 
 	/*Initialize internal data: */
@@ -30,5 +35,5 @@
 	this->solution_type=in_solution_type;
 	this->analysis_counter=nummodels-1; //point to last analysis_type carried out.
-	this->results=new DataSet(); //not initialized by CreateDataSets
+	this->results=new Results(); //not initialized by CreateDataSets
 	
 	/*Dynamically allocate whatever is a list of length nummodels: */
@@ -72,5 +77,15 @@
 		ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
 	}
+	
+	/*Close input file descriptors: */
+	if(my_rank==0) pfclose(IOMODEL,inputfilename);
+
+	/*Add output file name to parameters: */
+	this->parameters->AddObject(new StringParam(OutputFileNameEnum,outputfilename));
+
+#endif
+
 }
+
 /*}}}1*/
 /*FUNCTION FemModel::destructor {{{1*/
Index: /issm/trunk/src/c/objects/FemModel.h
===================================================================
--- /issm/trunk/src/c/objects/FemModel.h	(revision 6371)
+++ /issm/trunk/src/c/objects/FemModel.h	(revision 6372)
@@ -34,5 +34,5 @@
 		Materials*          materials;  //one set of materials, for each element
 		Parameters*         parameters; //one set of parameters, independent of the analysis_type
-		DataSet*            results; //results that cannot be fit into the elements (such as one time constants, arrays, strings, etc ...)
+		Results*            results; //results that cannot be fit into the elements (such as one time constants, arrays, strings, etc ...)
 
 		//multiple  sets of matrices/vectors for each analysis_type. m stands for multiple
@@ -46,5 +46,5 @@
 
 		/*constructors, destructors: */
-		FemModel(ConstDataHandle IOMODEL,const int solution_type,const int* analyses,const int nummodels);
+		FemModel(char* inputfilename, char* outputfilename, const int solution_type,const int* analyses,const int nummodels);
 		~FemModel();
 
Index: /issm/trunk/src/c/objects/IoModel.cpp
===================================================================
--- /issm/trunk/src/c/objects/IoModel.cpp	(revision 6371)
+++ /issm/trunk/src/c/objects/IoModel.cpp	(revision 6372)
@@ -211,4 +211,7 @@
 		IoModelFetchData(&this->qmu_mass_flux_num_profiles,iomodel_handle,"qmu_mass_flux_num_profiles");
 	}
+	/*i/o: */
+	IoModelFetchData(&this->io_gather,iomodel_handle,"io_gather");
+	IoModelFetchData(&this->io_split,iomodel_handle,"io_split");
 	
 	/*parameter output : */
@@ -247,4 +250,6 @@
 	this->gridonmacayeal=NULL;
 	this->gridonpattyn=NULL;
+	this->io_gather=1;
+	this->io_split=0;
 	
 	this->vx_obs=NULL;
Index: /issm/trunk/src/c/objects/IoModel.h
===================================================================
--- /issm/trunk/src/c/objects/IoModel.h	(revision 6371)
+++ /issm/trunk/src/c/objects/IoModel.h	(revision 6372)
@@ -55,4 +55,8 @@
 		double* pressure;
 		double* temperature;
+
+		/*i/o: */
+		int    io_gather;
+		int    io_split;
 
 		/*observations: */
Index: /issm/trunk/src/c/solutions/issm.cpp
===================================================================
--- /issm/trunk/src/c/solutions/issm.cpp	(revision 6371)
+++ /issm/trunk/src/c/solutions/issm.cpp	(revision 6372)
@@ -12,9 +12,6 @@
 
 	/*I/O: */
-	FILE     *input_fid        = NULL;
 	FILE     *output_fid       = NULL;
-	char     *inputfilename    = NULL;
 	char     *petscoptionsfilename = NULL;
-	char     *outputfilename   = NULL;
 	char     *lockname         = NULL;
 	bool      qmu_analysis     = false;
@@ -53,7 +50,5 @@
 	_printf_("Launching solution sequence\n");
 	solution_type=StringToEnum(argv[1]);
-	inputfilename=argv[3];
 	petscoptionsfilename=argv[4];
-	outputfilename=argv[5];
 	lockname=argv[6];
 
@@ -64,13 +59,6 @@
 	SolutionConfiguration(&analyses,&numanalyses,&solutioncore,solution_type);
 
-	/*Open input file to process model
-	 * and ouput file to start unload results*/
-	input_fid =pfopen(inputfilename ,"rb");
-	output_fid=pfopen(outputfilename,"wb");
-
-	femmodel=new FemModel(input_fid,solution_type,analyses,numanalyses);
-
-	/*add output_fid to parameters: */
-	femmodel->parameters->SetParam(output_fid,OutputFilePointerEnum);
+	/*Create femmodel, using input file: */
+	femmodel=new FemModel(argv[3] /*input*/,argv[5] /*output*/,solution_type,analyses,numanalyses);
 
 	/*add petsc options to parameters: */
@@ -112,5 +100,5 @@
 
 	/*Close output file and write lock file if requested*/
-	pfclose(output_fid,outputfilename);
+	femmodel->parameters->FindParam(&output_fid,OutputFilePointerEnum); pfclose(output_fid,argv[5]);
 	if (waitonlock>0){
 		_printf_("write lock file:\n");
Index: /issm/trunk/src/c/solutions/transient2d_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/transient2d_core.cpp	(revision 6371)
+++ /issm/trunk/src/c/solutions/transient2d_core.cpp	(revision 6372)
@@ -43,5 +43,8 @@
 	
 		/*Increment*/
-		if(time_adapt) TimeAdaptx(&dt,femmodel->elements, femmodel->nodes,femmodel->vertices,femmodel->loads, femmodel->materials, femmodel->parameters); 
+		if(time_adapt){
+			TimeAdaptx(&dt,femmodel->elements, femmodel->nodes,femmodel->vertices,femmodel->loads, femmodel->materials, femmodel->parameters); 
+			InputUpdateFromConstantx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,dt,DtEnum);
+		}
 		time+=dt;
 		step+=1;
Index: /issm/trunk/src/c/solutions/transient3d_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/transient3d_core.cpp	(revision 6371)
+++ /issm/trunk/src/c/solutions/transient3d_core.cpp	(revision 6372)
@@ -43,5 +43,8 @@
 
 		/*Increment*/
-		if(time_adapt) TimeAdaptx(&dt,femmodel->elements, femmodel->nodes,femmodel->vertices,femmodel->loads, femmodel->materials, femmodel->parameters); 
+		if(time_adapt){
+			TimeAdaptx(&dt,femmodel->elements, femmodel->nodes,femmodel->vertices,femmodel->loads, femmodel->materials, femmodel->parameters); 
+			InputUpdateFromConstantx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,dt,DtEnum);
+		}
 		step+=1;
 		time+=dt;
Index: /issm/trunk/src/m/classes/@model/model.m
===================================================================
--- /issm/trunk/src/m/classes/@model/model.m	(revision 6371)
+++ /issm/trunk/src/m/classes/@model/model.m	(revision 6372)
@@ -41,4 +41,8 @@
 	md.elementconnectivity=NaN;
 	md.edges=NaN;
+
+	%I/O
+	md.io_gather=NaN;
+	md.io_split=NaN;
 
 	%Initial 2d mesh 
Index: /issm/trunk/src/m/classes/@model/setdefaultparameters.m
===================================================================
--- /issm/trunk/src/m/classes/@model/setdefaultparameters.m	(revision 6371)
+++ /issm/trunk/src/m/classes/@model/setdefaultparameters.m	(revision 6372)
@@ -245,2 +245,6 @@
 %solution speed-up
 md.kff=0;
+
+%i/o:
+md.io_gather=1;
+md.io_split=0;
Index: /issm/trunk/src/m/enum/IoGatherEnum.m
===================================================================
--- /issm/trunk/src/m/enum/IoGatherEnum.m	(revision 6372)
+++ /issm/trunk/src/m/enum/IoGatherEnum.m	(revision 6372)
@@ -0,0 +1,11 @@
+function macro=IoGatherEnum()
+%IOGATHERENUM - Enum of IoGather
+%
+%   WARNING: DO NOT MODIFY THIS FILE
+%            this file has been automatically generated by src/c/EnumDefinitions/Synchronize.sh
+%            Please read src/c/EnumDefinitions/README for more information
+%
+%   Usage:
+%      macro=IoGatherEnum()
+
+macro=237;
Index: /issm/trunk/src/m/enum/IoSplitEnum.m
===================================================================
--- /issm/trunk/src/m/enum/IoSplitEnum.m	(revision 6372)
+++ /issm/trunk/src/m/enum/IoSplitEnum.m	(revision 6372)
@@ -0,0 +1,11 @@
+function macro=IoSplitEnum()
+%IOSPLITENUM - Enum of IoSplit
+%
+%   WARNING: DO NOT MODIFY THIS FILE
+%            this file has been automatically generated by src/c/EnumDefinitions/Synchronize.sh
+%            Please read src/c/EnumDefinitions/README for more information
+%
+%   Usage:
+%      macro=IoSplitEnum()
+
+macro=238;
Index: /issm/trunk/src/m/enum/OutputFileNameEnum.m
===================================================================
--- /issm/trunk/src/m/enum/OutputFileNameEnum.m	(revision 6372)
+++ /issm/trunk/src/m/enum/OutputFileNameEnum.m	(revision 6372)
@@ -0,0 +1,11 @@
+function macro=OutputFileNameEnum()
+%OUTPUTFILENAMEENUM - Enum of OutputFileName
+%
+%   WARNING: DO NOT MODIFY THIS FILE
+%            this file has been automatically generated by src/c/EnumDefinitions/Synchronize.sh
+%            Please read src/c/EnumDefinitions/README for more information
+%
+%   Usage:
+%      macro=OutputFileNameEnum()
+
+macro=302;
Index: /issm/trunk/src/m/model/marshall.m
===================================================================
--- /issm/trunk/src/m/model/marshall.m	(revision 6371)
+++ /issm/trunk/src/m/model/marshall.m	(revision 6372)
@@ -182,4 +182,9 @@
 WriteData(fid,md.outputfilename,'String','outputfilename');
 
+%i/o: 
+WriteData(fid,md.io_gather,'Integer','io_gather');
+WriteData(fid,md.io_split,'Integer','io_split');
+
+
 %close file
 st=fclose(fid);
Index: /issm/trunk/src/m/solutions/transient2d_core.m
===================================================================
--- /issm/trunk/src/m/solutions/transient2d_core.m	(revision 6371)
+++ /issm/trunk/src/m/solutions/transient2d_core.m	(revision 6372)
@@ -22,5 +22,8 @@
 
 		%increment
-		if(time_adapt) dt=TimeAdapt(femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters); end
+		if(time_adapt),
+			dt=TimeAdapt(femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters); end
+			[femmodel.elements]=InputUpdateFromConstant(femmodel.elements,femmodel.nodes,femmodel.vertices,loads,femmodel.materials,femmodel.parameters,dt,DtEnum);
+		end
 		step=step+1;
 		time=time+dt;
Index: /issm/trunk/src/m/solutions/transient3d_core.m
===================================================================
--- /issm/trunk/src/m/solutions/transient3d_core.m	(revision 6371)
+++ /issm/trunk/src/m/solutions/transient3d_core.m	(revision 6372)
@@ -22,5 +22,8 @@
 
 		%Increment
-		if(time_adapt) dt=TimeAdapt(femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters); end
+		if(time_adapt),
+			dt=TimeAdapt(femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.loads,femmodel.materials,femmodel.parameters); end
+			[femmodel.elements]=InputUpdateFromConstant(femmodel.elements,femmodel.nodes,femmodel.vertices,loads,femmodel.materials,femmodel.parameters,dt,DtEnum);
+		end
 		step=step+1;
 		time=time+dt;
Index: /issm/trunk/src/mex/OutputResults/OutputResults.cpp
===================================================================
--- /issm/trunk/src/mex/OutputResults/OutputResults.cpp	(revision 6371)
+++ /issm/trunk/src/mex/OutputResults/OutputResults.cpp	(revision 6372)
@@ -14,5 +14,5 @@
 	Materials* materials=NULL;
 	Parameters* parameters=NULL;
-	DataSet* results=NULL;
+	Results* results=NULL;
 	
 	/* output datasets: */
@@ -32,5 +32,5 @@
 	FetchData((DataSet**)&materials,MATERIALS);
 	FetchParams(&parameters,PARAMETERS);
-	FetchData(&results,RESULTS);
+	FetchData((DataSet**)&results,RESULTS);
 
 	/*results might be NILL, allocate: */
Index: /issm/trunk/test/NightlyRun/test101.m
===================================================================
--- /issm/trunk/test/NightlyRun/test101.m	(revision 6371)
+++ /issm/trunk/test/NightlyRun/test101.m	(revision 6372)
@@ -5,4 +5,6 @@
 md.cluster=none;
 md=solve(md,'analysis_type',DiagnosticSolutionEnum);
+md.verbose=verbose('mprocessor',true,'module',true,'solution',true,'solver',true,'convergence',true,'qmu',true,'control',true);
+
 
 %Fields and tolerances to track changes
Index: /issm/trunk/test/NightlyRun/test102.m
===================================================================
--- /issm/trunk/test/NightlyRun/test102.m	(revision 6371)
+++ /issm/trunk/test/NightlyRun/test102.m	(revision 6372)
@@ -4,4 +4,5 @@
 md=setelementstype(md,'macayeal','all');
 md=SetParallel(md,3);
+md.cluster.np=1;
 md=solve(md,'analysis_type',DiagnosticSolutionEnum);
 
