Index: /issm/trunk-jpl/src/c/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/c/Makefile.am	(revision 14726)
+++ /issm/trunk-jpl/src/c/Makefile.am	(revision 14727)
@@ -750,4 +750,5 @@
 				./toolkits/mpi/patches/mpipatches.h\
 				./toolkits/mpi/patches/DetermineLocalSize.cpp\
+				./toolkits/mpi/patches/DetermineGlobalSize.cpp\
 				./toolkits/mpi/patches/DetermineRowRankFromLocalSize.cpp\
 				./toolkits/mpi/patches/GetOwnershipBoundariesFromRange.cpp\
Index: /issm/trunk-jpl/src/c/classes/objects/Bucket.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/objects/Bucket.h	(revision 14726)
+++ /issm/trunk-jpl/src/c/classes/objects/Bucket.h	(revision 14727)
@@ -52,4 +52,17 @@
 				this->values=xNew<doubletype>(this->n*this->m);
 				xMemCpy(this->values,valuesin,this->n*this->m);
+			}
+		} /*}}}*/
+		Bucket(int min,int* idxmin,doubletype* valuesin,InsMode modein){ /*{{{*/ 
+			this->m=min;
+			this->n=1;
+			this->mode=modein;
+			if(this->m){
+				this->idxm=xNew<int>(this->m); 
+				xMemCpy(this->idxm,idxmin,this->m);
+			}
+			if(this->m){
+				this->values=xNew<doubletype>(this->m);
+				xMemCpy(this->values,valuesin,this->m);
 			}
 		} /*}}}*/
@@ -119,5 +132,6 @@
 		};
 		/*}}}*/
-		void Isend(int receiver_rank,MPI_Request* requests,int* pcount,MPI_Comm comm){ /*{{{*/
+#ifdef _HAVE_MPI_
+			void Isend(int receiver_rank,MPI_Request* requests,int* pcount,MPI_Comm comm){ /*{{{*/
 			int count=0;
 			int int_mode;
@@ -162,4 +176,5 @@
 
 		} /*}}}*/
+#endif
 };
 
Index: /issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h	(revision 14726)
+++ /issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h	(revision 14727)
@@ -22,4 +22,7 @@
 #include "../../shared/Alloc/alloc.h"
 #include "../../include/macros.h"
+#ifdef _HAVE_MPI_
+#include "../mpi/mpiincludes.h"
+#endif
 #include <math.h>
 
@@ -36,6 +39,8 @@
 	public:
 
-		doubletype* vector;
-		int M;
+		int M; //global size
+		int m; //local number of rows
+		doubletype* vector;  /*here, doubletype is either IssmDouble or IssmPDouble*/
+		DataSet*    buckets;  /*here, we store buckets of values that we will Assemble into a global vector.*/
 
 		/*IssmMpiVec constructors, destructors*/
@@ -44,40 +49,54 @@
 
 			this->M=0;
+			this->m=0;
 			this->vector=NULL;
+			this->buckets=new DataSet();
 		}
 		/*}}}*/
 		/*FUNCTION IssmMpiVec(int M){{{*/
-		IssmMpiVec(int pM){
-
-			this->M=pM;
+		IssmMpiVec(int Min){
+			this->Init(Min,false);
+		}
+		/*}}}*/
+		/*FUNCTION IssmMpiVec(int m,int M){{{*/
+		/*IssmMpiVec(int min,int Min){
+			this->Init(Min,false);
+		}*/
+		/*}}}*/
+		/*FUNCTION IssmMpiVec(int M,bool fromlocalsize){{{*/
+		IssmMpiVec(int Min, bool fromlocalsize){
+			this->Init(Min,fromlocalsize);
+		}
+		/*}}}*/
+		/*FUNCTION IssmMpiVec(doubletype* serial_vec,int M){{{*/
+		IssmMpiVec(doubletype* buffer,int Min){
+
+			this->Init(Min,false);
+
+			if(this->M){
+				this->vector=xNew<doubletype>(Min);
+				xMemCpy<doubletype>(this->vector,buffer,this->m);
+			}
+		}
+		/*}}}*/
+		/*FUNCTION IssmMpiVec::Init(int Min,bool fromlocalsize){{{*/
+		void Init(int Min,bool fromlocalsize){
+
+			this->buckets=new DataSet();
+			
+			if(fromlocalsize){
+				this->m=Min;
+				this->M=DetermineGlobalSize(this->m,IssmComm::GetComm());
+			}
+			else{
+				this->M=Min;
+				this->m=DetermineLocalSize(this->M,IssmComm::GetComm());
+			}
+			
+			/*Initialize pointer: */
 			this->vector=NULL;
-			if(this->M) this->vector=xNewZeroInit<doubletype>(pM);
-		}
-		/*}}}*/
-		/*FUNCTION IssmMpiVec(int m,int M){{{*/
-		IssmMpiVec(int pm,int pM){
-
-			this->M=pM;
-			this->vector=NULL;
-			if(this->M) this->vector=xNewZeroInit<doubletype>(pM);
-		}
-		/*}}}*/
-		/*FUNCTION IssmMpiVec(int M,bool fromlocalsize){{{*/
-		IssmMpiVec(int pM,bool fromlocalsize){
-
-			this->M=pM;
-			this->vector=NULL;
-			if(this->M) this->vector=xNewZeroInit<doubletype>(pM);
-		}
-		/*}}}*/
-		/*FUNCTION IssmMpiVec(doubletype* serial_vec,int M){{{*/
-		IssmMpiVec(doubletype* buffer,int pM){
-
-			this->M=pM;
-			this->vector=NULL;
-			if(this->M){
-				this->vector=xNew<doubletype>(pM);
-				xMemCpy<doubletype>(this->vector,buffer,pM);
-			}
+
+			/*Allocate: */
+			if (m)this->vector=xNewZeroInit<doubletype>(this->m);
 		}
 		/*}}}*/
@@ -85,5 +104,7 @@
 		~IssmMpiVec(){
 			xDelete<doubletype>(this->vector);
-			M=0;
+			this->M=0;
+			this->n=0;
+			delete buckets;
 		}
 		/*}}}*/
@@ -92,9 +113,16 @@
 		/*FUNCTION Echo{{{*/
 		void Echo(void){
-
-			int i;
-			_printLine_("IssmMpiVec size " << this->M);
-			for(i=0;i<M;i++){
-				_printString_(vector[i] << "\n ");
+			
+			int i,j;
+
+			/*Do a synchronized dump across all the rows: */
+			for(i=0;i<IssmComm::GetSize();i++){
+				if (IssmComm::GetRank()==i){
+					printf("cpu %i #rows: %i\n",i,this->m);
+					for (j=0;j<this->m;j++){
+						printf("row %i %g",j,this->vector[j]);
+					}
+				}
+				MPI_Barrier(IssmComm::GetComm());
 			}
 		}
@@ -102,24 +130,16 @@
 		/*FUNCTION Assemble{{{*/
 		void Assemble(void){
-
-			/*do nothing*/
-
+			_error_("not implemented yet!");
 		}
 		/*}}}*/
 		/*FUNCTION SetValues{{{*/
 		void SetValues(int ssize, int* list, doubletype* values, InsMode mode){
-
-			int i;
-			switch(mode){
-				case ADD_VAL:
-					for(i=0;i<ssize;i++) this->vector[list[i]]+=values[i];
-					break;
-				case INS_VAL:
-					for(i=0;i<ssize;i++) this->vector[list[i]]=values[i];
-					break;
-				default:
-					_error_("unknown insert mode!");
-					break;
-			}
+			
+			/*we need to store all the values we collect here in order to Assemble later. 
+			 * Indeed, the values we are collecting here most of the time will not belong 
+			 * to us, but to another part of the vector on another cpu: */
+			_assert_(buckets);
+
+			buckets->AddObject(new Bucket<doubletype>(ssize, list, values, mode));
 
 		}
@@ -128,21 +148,15 @@
 		void SetValue(int dof, doubletype value, InsMode mode){
 
-			switch(mode){
-				case ADD_VAL:
-					this->vector[dof]+=value;
-					break;
-				case INS_VAL:
-					this->vector[dof]=value;
-					break;
-				default:
-					_error_("unknown insert mode!");
-					break;
-			}
+			/*we need to store the value we collect here in order to Assemble later. 
+			 * Indeed, the value we are collecting here most of the time will not belong 
+			 * to us, but to another part of the vector on another cpu: */
+			_assert_(buckets);
+
+			buckets->AddObject(new Bucket<doubletype>(1,&dof,&value, mode));
 		}
 		/*}}}*/
 		/*FUNCTION GetValue{{{*/
 		void GetValue(doubletype* pvalue,int dof){
-
-			*pvalue=this->vector[dof];
+			_error_("Get value on a MpiVec vector not implemented yet!");
 
 		}
@@ -158,5 +172,5 @@
 		void GetLocalSize(int* pM){
 
-			*pM=this->M;
+			*pM=this->m;
 
 		}
@@ -173,5 +187,5 @@
 
 			int i;
-			for(i=0;i<this->M;i++)this->vector[i]=value;
+			for(i=0;i<this->m;i++)this->vector[i]=value;
 
 		}
@@ -179,31 +193,10 @@
 		/*FUNCTION AXPY{{{*/
 		void AXPY(IssmAbsVec<doubletype>* Xin, doubletype a){
-
-			int i;
-			
-			/*Assume X is of the correct type, and downcast: */
-			IssmMpiVec* X=NULL;
-
-			X=(IssmMpiVec<doubletype>*)Xin;
-
-
-			/*y=a*x+y where this->vector is y*/
-			for(i=0;i<this->M;i++)this->vector[i]=a*X->vector[i]+this->vector[i];
-
+			_error_("not implemented yet!");
 		}
 		/*}}}*/
 		/*FUNCTION AYPX{{{*/
 		void AYPX(IssmAbsVec<doubletype>* Xin, doubletype a){
-
-			int i;
-
-			/*Assume X is of the correct type, and downcast: */
-			IssmMpiVec* X=NULL;
-
-			X=(IssmMpiVec<doubletype>*)Xin;
-
-			/*y=x+a*y where this->vector is y*/
-			for(i=0;i<this->M;i++)this->vector[i]=X->vector[i]+a*this->vector[i];
-
+			_error_("not implemented yet!");
 		}
 		/*}}}*/
Index: /issm/trunk-jpl/src/c/toolkits/mpi/patches/DetermineGlobalSize.cpp
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/mpi/patches/DetermineGlobalSize.cpp	(revision 14727)
+++ /issm/trunk-jpl/src/c/toolkits/mpi/patches/DetermineGlobalSize.cpp	(revision 14727)
@@ -0,0 +1,20 @@
+/* \file DetermineGlobalSize.cpp
+ * \brief: routine to determine global size from local size 
+ */
+
+#include <stdio.h>
+#include <math.h>
+#include "../../../shared/shared.h"
+#include "../../../include/types.h"
+
+int DetermineGlobalSize(int local_size,COMM comm){
+
+	/*output: */
+	int  global_size;
+
+	MPI_Reduce(&local_size, &global_size, 1, MPI_INT, MPI_SUM, 0, comm);
+	MPI_Bcast(&global_size,1,MPI_INT,0,comm);
+
+	return global_size;
+
+}
Index: /issm/trunk-jpl/src/c/toolkits/mpi/patches/mpipatches.h
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/mpi/patches/mpipatches.h	(revision 14726)
+++ /issm/trunk-jpl/src/c/toolkits/mpi/patches/mpipatches.h	(revision 14727)
@@ -11,4 +11,5 @@
 int* DetermineRowRankFromLocalSize(int global_size,int localsize,COMM comm);
 void GetOwnershipBoundariesFromRange(int* plower_row,int* pupper_row,int range,COMM comm);
+int DetermineGlobalSize(int local_size,COMM comm);
 
 #endif
Index: /issm/trunk-jpl/src/wrappers/matlab/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/Makefile.am	(revision 14726)
+++ /issm/trunk-jpl/src/wrappers/matlab/Makefile.am	(revision 14727)
@@ -23,6 +23,6 @@
 				./io/MatlabVectorToDoubleVector.cpp\
 				./io/MatlabMatrixToDoubleMatrix.cpp\
-				./io/MatlabMatrixToIssmDenseMat.cpp\
-				./io/MatlabVectorToIssmSeqVec.cpp
+				./io/MatlabMatrixToIssmMat.cpp\
+				./io/MatlabVectorToIssmVec.cpp
 				
 if PETSC
Index: sm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToIssmDenseMat.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToIssmDenseMat.cpp	(revision 14726)
+++ 	(revision )
@@ -1,25 +1,0 @@
-/*!\file MatlabMatrixToIssmDenseMat.cpp
- */
-
-/*Headers:*/
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include "./matlabio.h"
-#include "../../c/toolkits/toolkits.h"
-#include "../../c/shared/shared.h"
-
-IssmDenseMat<double>* MatlabMatrixToIssmDenseMat(const mxArray* dataref){
-
-	IssmDenseMat<double>* output=NULL;
-
-	output=new IssmDenseMat<double>();
-	MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref);
-	return output;
-
-}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToIssmMat.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToIssmMat.cpp	(revision 14727)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToIssmMat.cpp	(revision 14727)
@@ -0,0 +1,25 @@
+/*!\file MatlabMatrixToIssmDenseMat.cpp
+ */
+
+/*Headers:*/
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "./matlabio.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/shared/shared.h"
+
+IssmDenseMat<double>* MatlabMatrixToIssmDenseMat(const mxArray* dataref){
+
+	IssmDenseMat<double>* output=NULL;
+
+	output=new IssmDenseMat<double>();
+	MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref);
+	return output;
+
+}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp	(revision 14726)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp	(revision 14727)
@@ -25,5 +25,5 @@
 	matrix->pmatrix=MatlabMatrixToPetscMat(mxmatrix);
 	#else
-	matrix->smatrix=MatlabMatrixToIssmDenseMat(mxmatrix);
+	matrix->imatrix=MatlabMatrixToIssmMat(mxmatrix);
 	#endif
 
Index: sm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp	(revision 14726)
+++ 	(revision )
@@ -1,25 +1,0 @@
-/*!\file MatlabMatrixToSeqMat.cpp
- */
-
-/*Headers:*/
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include "./matlabio.h"
-#include "../../c/toolkits/toolkits.h"
-#include "../../c/shared/shared.h"
-
-SeqMat<double>* MatlabMatrixToSeqMat(const mxArray* dataref){
-
-	SeqMat<double>* output=NULL;
-
-	output=new SeqMat<double>();
-	MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref);
-	return output;
-
-}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToIssmVec.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToIssmVec.cpp	(revision 14727)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToIssmVec.cpp	(revision 14727)
@@ -0,0 +1,26 @@
+/*!\file MatlabVectorToIssmVec.cpp
+ */
+
+/*Headers:*/
+#include <mex.h>
+#include <stdio.h>
+#include <string.h>
+#include "./matlabio.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/shared/shared.h"
+
+IssmVec<double>* MatlabVectorToIssmVec(const mxArray* dataref){
+
+	IssmVec<double>* output=NULL;
+	IssmSeqVec<double>* seqvec=NULL;
+
+	output=new IssmVec<double>();
+	
+	seqvec=new IssmSeqVec<double>();
+
+	MatlabVectorToDoubleVector(&seqvec->vector,&seqvec->M,dataref);
+
+	output->vector=(IssmAbsVec<double>*)seqvec;
+	return output;
+
+}
Index: sm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToSeqVec.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToSeqVec.cpp	(revision 14726)
+++ 	(revision )
@@ -1,20 +1,0 @@
-/*!\file MatlabVectorToSeqVec.cpp
- */
-
-/*Headers:*/
-#include <mex.h>
-#include <stdio.h>
-#include <string.h>
-#include "./matlabio.h"
-#include "../../c/toolkits/toolkits.h"
-#include "../../c/shared/shared.h"
-
-SeqVec<double>* MatlabVectorToSeqVec(const mxArray* dataref){
-
-	SeqVec<double>* output=NULL;
-
-	output=new SeqVec<double>();
-	MatlabVectorToDoubleVector(&output->vector,&output->M,dataref);
-	return output;
-
-}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp	(revision 14726)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp	(revision 14727)
@@ -25,5 +25,5 @@
 	vector->pvector=MatlabVectorToPetscVec(mxvector);
 	#else
-	vector->svector=MatlabVectorToIssmSeqVec(mxvector);
+	vector->ivector=MatlabVectorToIssmVec(mxvector);
 	#endif
 
Index: /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 14726)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 14727)
@@ -85,6 +85,6 @@
 
 /*Matlab to IssmDenseMat routines: */
-IssmDenseMat<double>* MatlabMatrixToIssmDenseMat(const mxArray* dataref);
-IssmSeqVec<double>* MatlabVectorToIssmSeqVec(const mxArray* dataref);
+IssmMat<double>* MatlabMatrixToIssmMat(const mxArray* dataref);
+IssmVec<double>* MatlabVectorToIssmVec(const mxArray* dataref);
 
 /*Matlab to Petsc routines: */
Index: /issm/trunk-jpl/test/NightlyRun/test101.m
===================================================================
--- /issm/trunk-jpl/test/NightlyRun/test101.m	(revision 14726)
+++ /issm/trunk-jpl/test/NightlyRun/test101.m	(revision 14727)
@@ -3,6 +3,9 @@
 md=parameterize(md,'../Par/SquareShelfConstrained.par');
 md=setflowequation(md,'macayeal','all');
-md.cluster=generic('name',oshostname(),'np',3);
+md.cluster=generic('name',oshostname(),'np',8);
 md.diagnostic.requested_outputs=StressTensorEnum();
+md.toolkits.DefaultAnalysis=issmsolver();
+md.verbose=verbose('11111111');
+%md.debug.valgrind=true;
 md=solve(md,DiagnosticSolutionEnum());
 
