Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 4192)
+++ /issm/trunk/src/c/Makefile.am	(revision 4193)
@@ -1030,4 +1030,5 @@
 					./modules/Qmux/Qmux.cpp\
 					./modules/Qmux/DakotaResponses.cpp\
+					./modules/Qmux/DakotaMPI_Bcast.cpp\
 					./modules/Qmux/SpawnCore.cpp\
 					./modules/Qmux/SpawnCoreParallel.cpp\
Index: /issm/trunk/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp
===================================================================
--- /issm/trunk/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 4192)
+++ /issm/trunk/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 4193)
@@ -9,5 +9,12 @@
 #include "../../EnumDefinitions/EnumDefinitions.h"
 
-void InputUpdateFromDakotax(double* variables,char** variables_descriptors,int numvariables,FemModel* femmodel,double* qmu_part,int qmu_npart){
+void InputUpdateFromDakotax(FemModel* femmodel, double* variables,char** variables_descriptors,int numvariables){
+	
+	/*retrieve parameters: */
+	femmodel->parameters->FindParam(&verbose,VerboseEnum);
+	femmodel->parameters->FindParam(&qmu_npart,QmuNPartEnum);
+	femmodel->parameters->FindParam(&qmu_part,&dummy,QmuPartEnum);
+
+
 
 	ISSMERROR(" not supported yet!");
Index: /issm/trunk/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h
===================================================================
--- /issm/trunk/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h	(revision 4192)
+++ /issm/trunk/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h	(revision 4193)
@@ -9,6 +9,5 @@
 #include "../../DataSet/DataSet.h"
 
-
-void InputUpdateFromDakotax(double* variables,char** variables_descriptors,int numvariables,FemModel* femmodel,double* qmu_part,int qmu_npart);
+void InputUpdateFromDakotax(FemModel* femmodel,double* variables,char** variables_descriptors,int numvariables);
 
 #endif  /* _INPUTUPDATEFROMDAKOTAXX_H */
Index: /issm/trunk/src/c/modules/Qmux/DakotaMPI_Bcast.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/DakotaMPI_Bcast.cpp	(revision 4193)
+++ /issm/trunk/src/c/modules/Qmux/DakotaMPI_Bcast.cpp	(revision 4193)
@@ -0,0 +1,58 @@
+/*!\file: DakotaMPI_Bcast
+ * \brief: broadcast variables_descriptors, variables, numvariables and numresponses
+ * from cpu 0 to all other cpus.
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./Qmux.h"
+
+void DakotaMPI_Bcast(double** pvariables, char*** pvariables_descriptors,int* pnumvariables, int* pnumresponses){
+
+	/*inputs and outputs: */
+	double* variables=NULL;
+	char**  variables_descriptors=NULL;
+	int     numvariables;
+	int     numresponses;
+
+	/*recover inputs from pointers: */
+	variables=*pvariables;
+	variables_descriptors=*pvariables_descriptors;
+	numvariables=*pnumvariables;
+	numresponses=*pnumresponses;
+
+	/*numvariables: */
+	MPI_Bcast(&numvariables,1,MPI_INT,0,MPI_COMM_WORLD); 
+	
+	/*variables:*/
+	if(my_rank!=0)variables=(double*)xmalloc(numvariables*sizeof(double));
+	MPI_Bcast(variables,numvariables,MPI_DOUBLE,0,MPI_COMM_WORLD); 
+
+	/*variables_descriptors: */
+	if(my_rank!=0){
+		variables_descriptors=(char**)xmalloc(numvariables*sizeof(char*));
+	}
+	for(i=0;i<numvariables;i++){
+		if(my_rank==0){
+			string=variables_descriptors[i];
+			string_length=(strlen(string)+1)*sizeof(char);
+		}
+		MPI_Bcast(&string_length,1,MPI_INT,0,MPI_COMM_WORLD); 
+		if(my_rank!=0)string=(char*)xmalloc(string_length);
+		MPI_Bcast(string,string_length,MPI_CHAR,0,MPI_COMM_WORLD); 
+		if(my_rank!=0)variables_descriptors[i]=string;
+	}
+
+	/*numresponses: */
+	MPI_Bcast(&numresponses,1,MPI_INT,0,MPI_COMM_WORLD); 
+
+	/*Assign output pointers:*/
+	*pnumvariables=numvariables;
+	*pvariables=variables;
+	*pvariables_descriptors=variables_descriptors;
+	*pnumresponses=numresponses;
+}
Index: /issm/trunk/src/c/modules/Qmux/Qmux.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/Qmux.cpp	(revision 4192)
+++ /issm/trunk/src/c/modules/Qmux/Qmux.cpp	(revision 4193)
@@ -50,28 +50,20 @@
 #endif
 
-#ifdef _SERIAL_
-void Qmux(mxArray* femmodel,char* dakota_input_file,char* dakota_output_file,char* dakota_error_file){
-#else
-void Qmux(FemModel* femmodel){
-#endif
+void Qmux(void* femmodel,Parameters* parameters){ //void* for femmodel, because we do not use it, just pass it along
 
 
 	#ifdef _HAVE_DAKOTA_ //only works if dakota library has been compiled in.
-
-	#ifdef _PARALLEL_
-	char* dakota_input_file=NULL;
-	char* dakota_output_file=NULL;
-	char* dakota_error_file=NULL;
-	extern int my_rank;
-	#endif
-	int status=0;
+	
+	extern int         my_rank;
+	char*              dakota_input_file  = NULL;
+	char*              dakota_output_file = NULL;
+	char*              dakota_error_file  = NULL;
+	int                status=0;
 	Dakota::ModelLIter ml_iter;
 
-	#ifdef _PARALLEL_
 	/*Recover dakota_input_file, dakota_output_file and dakota_error_file, in the parameters dataset in parallel */
-	model->FindParam(&dakota_input_file,QmuInNameEnum);
-	model->FindParam(&dakota_output_file,QmuOutNameEnum);
-	model->FindParam(&dakota_error_file,QmuErrNameEnum);
-	#endif
+	parameters->FindParam(&dakota_input_file,QmuInNameEnum);
+	parameters->FindParam(&dakota_output_file,QmuOutNameEnum);
+	parameters->FindParam(&dakota_error_file,QmuErrNameEnum);
 
 	#ifdef _PARALLEL_
@@ -131,15 +123,11 @@
 		}
 	}
-	#endif
+	#endif //#ifdef _PARALLEL_
 
 	/*Free ressources:*/
-	#ifdef _PARALLEL_
 	xfree((void**)&dakota_input_file);
 	xfree((void**)&dakota_error_file);
 	xfree((void**)&dakota_output_file);
-	#endif
 
-
-	#endif
-
+	#endif //#ifdef _HAVE_DAKOTA_
 }
Index: /issm/trunk/src/c/modules/Qmux/Qmux.h
===================================================================
--- /issm/trunk/src/c/modules/Qmux/Qmux.h	(revision 4192)
+++ /issm/trunk/src/c/modules/Qmux/Qmux.h	(revision 4193)
@@ -9,16 +9,16 @@
 #include "../../objects/objects.h"
 
+void Qmux(void* femmodel,Parameters* parameters);
+
 /* local prototypes: */
 int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* femmodel,int counter);
+
 #ifdef _SERIAL_
-void Qmux(mxArray* femmodel,char* dakota_input_file,char* dakota_output_file,char* dakota_error_file);
 void SpawnCoreSerial(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, mxArray* femmodel,int counter);
 #else
-void Qmux(FemModel* femmodel);
 void SpawnCoreParallel(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, FemModel* femmodel,int counter);
 void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,FemModel* femmodel);
+void DakotaMPI_Bcast(double** pvariables, char*** pvariables_descriptors,int* pnumvariables, int* pnumresponses);
 #endif
 
-
 #endif  /* _QMUX_H */
-
Index: /issm/trunk/src/c/modules/Qmux/SpawnCore.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/SpawnCore.cpp	(revision 4192)
+++ /issm/trunk/src/c/modules/Qmux/SpawnCore.cpp	(revision 4193)
@@ -20,11 +20,14 @@
 
 	/*Branch into a serial SpawnCore and a parallel SpawnCore: */
+
 	#ifdef _SERIAL_
-	SpawnCoreSerial(responses, numresponses, variables, variables_descriptors,numvariables, (mxArray*)femmodel, counter);
+		SpawnCoreSerial(responses, numresponses, variables, variables_descriptors,numvariables, (mxArray*)femmodel, counter);
 	#else
-	/*Call SpawnCoreParallel unless counter=-1 on cpu0, in which case, bail out and return 0: */
-	MPI_Bcast(&counter,1,MPI_INT,0,MPI_COMM_WORLD); if(counter==-1)return 0;
-	
-	SpawnCoreParallel(responses, numresponses, variables, variables_descriptors,numvariables, (FemModel*)femmodel,counter);
+
+		/*Call SpawnCoreParallel unless counter=-1 on cpu0, in which case, bail out and return 0: */
+		MPI_Bcast(&counter,1,MPI_INT,0,MPI_COMM_WORLD); 
+		if(counter==-1)return 0;
+
+		SpawnCoreParallel(responses, numresponses, variables, variables_descriptors,numvariables, (FemModel*)femmodel,counter);
 	#endif
 
Index: /issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp
===================================================================
--- /issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp	(revision 4192)
+++ /issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp	(revision 4193)
@@ -41,5 +41,4 @@
 	
 	char   **responses_descriptors     = NULL;
-	int      num_responses_descriptors;
 	char    *string                    = NULL;
 	int      string_length;
@@ -50,84 +49,48 @@
 	int      solution_type;
 
-	
-	
 	/*synchronize all cpus, as CPU 0 is probably late (it is starting the entire dakota strategy!) : */
 	MPI_Barrier(MPI_COMM_WORLD);
+	_printf_("qmu iteration: %i\n",counter);
 	
-	/*some parameters needed: */
+	/*retrieve parameters: */
 	femmodel->parameters->FindParam(&verbose,VerboseEnum);
+	femmodel->parameters->FindParam(&responses_descriptors,&dummy,ResponseDescriptorsEnum);
+	if(dummy!=numresponses)ISSMERROR(" parameter numresponses not equal to Dakota provided numresponses: %i vs %i\n",dummy,numresponses);
+
+	/* only cpu 0, running dakota is providing us with variables, variables_descriptors and responses. 
+	 * broadcast onto other cpus: */
+	DakotaMPI_Bcast(&variables,&variables_descriptors,&numvariables,&numresponses);
+
+	/*Modify core inputs in objects contained in femmodel, to reflect the dakota variables inputs: */
+	InputUpdateFromDakotax(femmodel,variables,variables_descriptors,numvariables);
+
+	/*Run the analysis core solution sequence: */
 	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
-		
-	/*Recover partitioning for dakota: */
-	femmodel->parameters->FindParam(&qmu_npart,QmuNPartEnum);
-	femmodel->parameters->FindParam(&qmu_part,&dummy,QmuPartEnum);
-
-	/*broadcast variables: only cpu 0 has correct values*/
-	MPI_Bcast(&numvariables,1,MPI_INT,0,MPI_COMM_WORLD); 
-	if(my_rank!=0)variables=(double*)xmalloc(numvariables*sizeof(double));
-	MPI_Bcast(variables,numvariables,MPI_DOUBLE,0,MPI_COMM_WORLD); 
-
-	/*broadcast variables_descriptors: */
-	if(my_rank!=0){
-		variables_descriptors=(char**)xmalloc(numvariables*sizeof(char*));
-	}
-	for(i=0;i<numvariables;i++){
-		if(my_rank==0){
-			string=variables_descriptors[i];
-			string_length=(strlen(string)+1)*sizeof(char);
-		}
-		MPI_Bcast(&string_length,1,MPI_INT,0,MPI_COMM_WORLD); 
-		if(my_rank!=0)string=(char*)xmalloc(string_length);
-		MPI_Bcast(string,string_length,MPI_CHAR,0,MPI_COMM_WORLD); 
-		if(my_rank!=0)variables_descriptors[i]=string;
+	if(verbose)_printf_("%s%s%s\n","Starting ",EnumAsString(solution_type)," core:");
+	switch(solution_type){
+		case DiagnosticAnalysisEnum:
+			diagnostic_core(femmodel);
+			break;
+		case ThermalAnalysisEnum:
+			thermal_core(femmodel);
+			break;
+		case PrognosticAnalysisEnum:
+			prognostic_core(femmodel);
+			break;
+		case Transient2DAnalysisEnum:
+			transient2d_core(femmodel);
+			break;
+		case Transient3DAnalysisEnum:
+			transient3d_core(femmodel);
+		default:
+			ISSMERROR("%s%s%s"," solution_type: ",EnumAsString(solution_type),", not supported yet!");
+			break;
 	}
 
-	/*broadcast numresponses: */
-	MPI_Bcast(&numresponses,1,MPI_INT,0,MPI_COMM_WORLD); 
-
-	_printf_("qmu iteration: %i\n",counter);
-
-	/*Modify core inputs in objects contained in femmodel, to reflect the dakota variables inputs: */
-	InputUpdateFromDakotax(variables,variables_descriptors,numvariables,femmodel,qmu_part,qmu_npart);
-
-	/*Run the analysis core solution sequence: */
-	if(solution_type==DiagnosticAnalysisEnum){
-			
-		if(verbose)_printf_("Starting diagnostic core\n");
-
-		diagnostic_core(femmodel);
-
-	}
-	else if(solution_type==ThermalAnalysisEnum){
-		
-		if(verbose)_printf_("Starting thermal core\n");
-		thermal_core(femmodel);
-
-	}
-	else if(solution_type==PrognosticAnalysisEnum){
-
-		if(verbose)_printf_("Starting prognostic core\n");
-		prognostic_core(femmodel);
-
-	}
-	else if(solution_type==Transient2DAnalysisEnum){
-
-		if(verbose)_printf_("Starting transient core\n");
-		transient2d_core(femmodel);
-
-	}
-	else if(solution_type==Transient3DAnalysisEnum){
-
-		if(verbose)_printf_("Starting transient core\n");
-		transient3d_core(femmodel);
-
-	}
-	else ISSMERROR("%s%s%s"," solution_type: ",EnumAsString(solution_type),", not supported yet!");
-	
 	/*compute responses on cpu 0: dummy for now! */
 	if(verbose)_printf_("compute dakota responses:\n");
 	DakotaResponses(responses,responses_descriptors,numresponses,femmodel);
 
-	/*Free ressources:*/
+	/*Free ressources:{{{1*/
 	//variables only on cpu != 0
 	if(my_rank!=0){
@@ -147,6 +110,5 @@
 	xfree((void**)&responses_descriptors);
 	xfree((void**)&qmu_part);
-
-
+	/*}}}*/
 }
 
Index: /issm/trunk/src/m/solutions/NewFemModel.m
===================================================================
--- /issm/trunk/src/m/solutions/NewFemModel.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/NewFemModel.m	(revision 4193)
@@ -18,5 +18,5 @@
    displaystring(md.verbose,'\n   reading data from model %s...',md.name);
    [femmodel.elements,femmodel.nodes,femmodel.vertices,femmodel.constraints,femmodel.loads,femmodel.materials,femmodel.parameters]=ModelProcessor(md,solution_type,femmodel.analysis_type_list);
-
+   
 	%Initialize some fiels with empty celils
 	femmodel.m_yg=cell(nummodels,1);
Index: /issm/trunk/src/m/solutions/SpawnCore.m
===================================================================
--- /issm/trunk/src/m/solutions/SpawnCore.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/SpawnCore.m	(revision 4193)
@@ -1,20 +1,19 @@
-function responses=SpawnCore(models,variables,variabledescriptors,counter);
+function responses=SpawnCore(femmodel,variables,variabledescriptors,counter);
 %SPAWNCORE - for Qmu analysis, using Dakota. Spawn the core solution.
 %
 %   Usage:
-%      responses=SpawnCore(models,variables,variabledescriptors)
+%      responses=SpawnCore(femmodel,variables,variabledescriptors)
 %
 
 %recover parameters
-verbose=models.dh.parameters.Verbose;
-parameters=models.dh.parameters;
-responsedescriptors=models.dh.parameters.responsedescriptors; 
-npart=models.dh.parameters.qmu_npart;
-part=models.dh.parameters.qmu_part+1; %C indexing
-numberofnodes=models.dh.parameters.NumberOfNodes;
+verbose=femmodel.parameters.Verbose;
+responsedescriptors=femmodel.parameters.responsedescriptors; 
+npart=femmodel.parameters.qmu_npart;
+part=femmodel.parameters.qmu_part+1; %C indexing
+numberofnodes=femmodel.parameters.NumberOfNodes;
 
-disp(['   qmu iteration: ',num2str(counter)]);
+displaystring(verbose,'%s%i',['   qmu iteration:'],counter);
 
-%first update the inputs to the models using the variables provided to us by dakota.
+%first update the inputs to the femmodel using the variables provided to us by dakota.
 count=1;
 while count<=numel(variables)
@@ -27,5 +26,5 @@
 	else
 		root=qmuroot(descriptor);
-		param=parameters.(root);
+		param=femmodel.parameters.(root);
 
 		%next npart values in variables are partition values for this param, collect them.
@@ -47,5 +46,5 @@
 if analysis_type==DiagnosticAnalysisEnum(),
 
-	results=diagnostic_core(models);
+	results=diagnostic_core(femmodel);
 
 else
@@ -54,5 +53,5 @@
 
 %process results
-processedresults=processresults(models,results);
+processedresults=processresults(femmodel,results);
 
 %now process the results to get response function values
@@ -60,4 +59,4 @@
 for i=1:numel(responsedescriptors),
 	descriptor=responsedescriptors{i};
-	responses(i)=qmuresponse(models,results,processedresults,descriptor);
+	responses(i)=qmuresponse(femmodel,results,processedresults,descriptor);
 end
Index: /issm/trunk/src/m/solutions/bedslope.m
===================================================================
--- /issm/trunk/src/m/solutions/bedslope.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/bedslope.m	(revision 4193)
@@ -28,5 +28,5 @@
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(femmodel);
+		Qmu(femmodel,femmodel.parameters);
 	end
 
Index: /issm/trunk/src/m/solutions/diagnostic.m
===================================================================
--- /issm/trunk/src/m/solutions/diagnostic.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/diagnostic.m	(revision 4193)
@@ -37,5 +37,5 @@
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(femmodel);
+		Qmu(femmodel,femmodel.parameters);
 	end
 
Index: /issm/trunk/src/m/solutions/prognostic.m
===================================================================
--- /issm/trunk/src/m/solutions/prognostic.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/prognostic.m	(revision 4193)
@@ -28,5 +28,5 @@
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(femmodel);
+		Qmu(femmodel,femmodel.parameters);
 	end
 
Index: /issm/trunk/src/m/solutions/prognostic2.m
===================================================================
--- /issm/trunk/src/m/solutions/prognostic2.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/prognostic2.m	(revision 4193)
@@ -27,5 +27,5 @@
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(femmodel);
+		Qmu(femmodel,femmodel.parameters);
 	end
 
Index: /issm/trunk/src/m/solutions/surfaceslope.m
===================================================================
--- /issm/trunk/src/m/solutions/surfaceslope.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/surfaceslope.m	(revision 4193)
@@ -28,5 +28,5 @@
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(femmodel);
+		Qmu(femmodel,femmodel.parameters);
 	end
 
Index: /issm/trunk/src/m/solutions/transient2d.m
===================================================================
--- /issm/trunk/src/m/solutions/transient2d.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/transient2d.m	(revision 4193)
@@ -27,5 +27,5 @@
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(femmodel);
+		Qmu(femmodel,femmodel.parameters);
 	end
 
Index: /issm/trunk/src/m/solutions/transient3d.m
===================================================================
--- /issm/trunk/src/m/solutions/transient3d.m	(revision 4192)
+++ /issm/trunk/src/m/solutions/transient3d.m	(revision 4193)
@@ -26,5 +26,5 @@
 	else
 		%launch dakota driver for diagnostic core solution
-		Qmu(femmodel);
+		Qmu(femmodel,femmodel.parameters);
 	end
 
Index: /issm/trunk/src/mex/Qmu/Qmu.cpp
===================================================================
--- /issm/trunk/src/mex/Qmu/Qmu.cpp	(revision 4192)
+++ /issm/trunk/src/mex/Qmu/Qmu.cpp	(revision 4193)
@@ -14,12 +14,9 @@
 
 	/*diverse: */
-	int   noerr=1;
+	int         noerr      = 1;
 
 	/*input datasets: */
-	mxArray* femmodel=NULL;
-	mxArray* parameters=NULL;
-	char*    dakota_input_file=NULL;
-	char*    dakota_output_file=NULL;
-	char*    dakota_error_file=NULL;
+	mxArray    *femmodel   = NULL;
+	Parameters *parameters = NULL;
 
 	/* output datasets: none*/
@@ -38,18 +35,9 @@
 	femmodel=FEMMODEL;
 
-	/*get parameters from femmodel structure: */
-	parameters=mxGetField(FEMMODEL,0,"parameters");
-
-	FetchData(&dakota_input_file,mxGetField(parameters,0,"qmuinname"));
-	FetchData(&dakota_output_file,mxGetField(parameters,0,"qmuoutname"));
-	FetchData(&dakota_error_file,mxGetField(parameters,0,"qmuerrname"));
+	/*Fetch parameters from femmodel structure: */
+	FetchData(&parameters,PARAMETERS);
 
 	/*!Generate internal degree of freedom numbers: */
-	Qmux(femmodel,dakota_input_file,dakota_output_file,dakota_error_file);
-
-	/*Free ressources:*/
-	xfree((void**)&dakota_input_file);
-	xfree((void**)&dakota_output_file);
-	xfree((void**)&dakota_error_file);
+	Qmux(femmodel,parameters);
 
 	/*end module: */
