Index: issm/trunk/src/c/Qmux/Qmux.cpp
===================================================================
--- issm/trunk/src/c/Qmux/Qmux.cpp	(revision 2047)
+++ issm/trunk/src/c/Qmux/Qmux.cpp	(revision 2048)
@@ -125,7 +125,8 @@
 		
 		#ifdef _PARALLEL_
-		//Warn other cpus that we are done running the dakota iterator
-		MPI_Bcast(&status,1,MPI_INT,0,MPI_COMM_WORLD); 
+		//Warn other cpus that we are done running the dakota iterator, by setting the counter to -1:
+		SpawnCore(NULL,0, NULL,NULL,0,model,inputs,analysis_type,sub_analysis_type,-1);
 		#endif
+
 	#ifdef _PARALLEL_
 	}
@@ -133,22 +134,6 @@
 
 		for(;;){
-
-			SpawnCore(NULL,0, NULL,NULL,0,model,inputs,analysis_type,sub_analysis_type,0);
-
-			//Figure out if cpu 0 is done iterating
-			MPI_Bcast(&status,1,MPI_INT,0,MPI_COMM_WORLD); 
-
-			//yes!
-			if(status){
-				break; //yes, we are done
-			}
-			else{
-				/*We are not done: */
-
-
-			}
+			if(!SpawnCore(NULL,0, NULL,NULL,0,model,inputs,analysis_type,sub_analysis_type,0))break; //counter came in at -1 on cpu0, bail out.
 		}
-
-			
 	}
 	#endif
Index: issm/trunk/src/c/Qmux/Qmux.h
===================================================================
--- issm/trunk/src/c/Qmux/Qmux.h	(revision 2047)
+++ issm/trunk/src/c/Qmux/Qmux.h	(revision 2048)
@@ -9,5 +9,5 @@
 
 /* local prototypes: */
-void SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* model,void* inputs,int analysis_type,int sub_analysis_type,int counter);
+int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* model,void* inputs,int analysis_type,int sub_analysis_type,int counter);
 #ifdef _SERIAL_
 void Qmux(mxArray* model,mxArray* inputs,int analysis_type,int sub_analysis_type,char* dakota_input_file,char* dakota_output_file,char* dakota_error_file);
Index: issm/trunk/src/c/Qmux/SpawnCore.cpp
===================================================================
--- issm/trunk/src/c/Qmux/SpawnCore.cpp	(revision 2047)
+++ issm/trunk/src/c/Qmux/SpawnCore.cpp	(revision 2048)
@@ -19,6 +19,5 @@
 #include "../include/macros.h"
 
-void SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* model,void* inputs,int analysis_type,int sub_analysis_type,int counter){
-
+int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* model,void* inputs,int analysis_type,int sub_analysis_type,int counter){
 
 	/*Branch into a serial SpawnCore and a parallel SpawnCore: */
@@ -26,7 +25,10 @@
 	SpawnCoreSerial(responses, numresponses, variables, variables_descriptors,numvariables, (mxArray*)model, (mxArray*)inputs,analysis_type,sub_analysis_type,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, (Model*)model, (ParameterInputs*)inputs,analysis_type,sub_analysis_type,counter);
 	#endif
 
-
+	return 1;
 }
Index: issm/trunk/src/c/objects/DakotaPlugin.cpp
===================================================================
--- issm/trunk/src/c/objects/DakotaPlugin.cpp	(revision 2047)
+++ issm/trunk/src/c/objects/DakotaPlugin.cpp	(revision 2048)
@@ -59,5 +59,4 @@
 int DakotaPlugin::derived_map_ac(const Dakota::String& driver) {
 
-	int status=0;
 	int i;
 	double* variables=NULL;
@@ -98,8 +97,4 @@
 	}
 
-	#ifdef _PARALLEL_ 
-	/*warn other cpus that we are done running this iteration: */
-	MPI_Bcast(&status,1,MPI_INT,0,MPI_COMM_WORLD); 
-	#endif
 
 	/*Free ressources:*/
Index: issm/trunk/src/c/parallel/diagnostic.cpp
===================================================================
--- issm/trunk/src/c/parallel/diagnostic.cpp	(revision 2047)
+++ issm/trunk/src/c/parallel/diagnostic.cpp	(revision 2048)
@@ -117,4 +117,27 @@
 			control_core(results,model,inputs);
 		}
+		if(!control_analysis){
+			/*Add analysis_type to results: */
+			result=new Result(results->Size()+1,0,1,"analysis_type","diagnostic");
+			results->AddObject(result);
+			
+			_printf_("process results:\n");
+			ProcessResults(&results,model,DiagnosticAnalysisEnum());
+		}
+		else{
+			/*Add analysis_type and control_type to results: */
+			result=new Result(results->Size()+1,0,1,"analysis_type","diagnostic");
+			results->AddObject(result);
+			
+			model->FindParam(&control_type,"control_type");
+			result=new Result(results->Size()+1,0,1,"control_type",control_type);
+			results->AddObject(result);
+
+			_printf_("process results:\n");
+			ProcessResults(&results,model,ControlAnalysisEnum());
+		}
+
+		_printf_("write results to disk:\n");
+		OutputResults(results,outputfilename);
 	}
 	else{
@@ -129,33 +152,9 @@
 	}
 
-	if(!control_analysis){
-		/*Add analysis_type to results: */
-		result=new Result(results->Size()+1,0,1,"analysis_type","diagnostic");
-		results->AddObject(result);
-		
-		_printf_("process results:\n");
-		ProcessResults(&results,model,DiagnosticAnalysisEnum());
-	}
-	else{
-		/*Add analysis_type and control_type to results: */
-		result=new Result(results->Size()+1,0,1,"analysis_type","diagnostic");
-		results->AddObject(result);
-		
-		model->FindParam(&control_type,"control_type");
-		result=new Result(results->Size()+1,0,1,"control_type",control_type);
-		results->AddObject(result);
-
-		_printf_("process results:\n");
-		ProcessResults(&results,model,ControlAnalysisEnum());
-	}
-
-	_printf_("write results to disk:\n");
-	OutputResults(results,outputfilename);
-
 	_printf_("write lock file:\n");
 	if (waitonlock){
 		WriteLockFile(lockname);
 	}
-		
+
 	_printf_("closing MPI and Petsc\n");
 	PetscFinalize(); 
Index: issm/trunk/src/c/parallel/steadystate.cpp
===================================================================
--- issm/trunk/src/c/parallel/steadystate.cpp	(revision 2047)
+++ issm/trunk/src/c/parallel/steadystate.cpp	(revision 2048)
@@ -135,4 +135,28 @@
 			control_core(results,model,inputs);
 		}
+
+		if(!control_analysis){
+			/*Add analysis_type to results: */
+			result=new Result(results->Size()+1,0,1,"analysis_type","steadystate");
+			results->AddObject(result);
+
+			_printf_("process results:\n");
+			ProcessResults(&results,model,SteadystateAnalysisEnum());
+		}
+		else{
+			/*Add analysis_type and control_type to results: */
+			result=new Result(results->Size()+1,0,1,"analysis_type","steadystate");
+			results->AddObject(result);
+
+			model->FindParam(&control_type,"control_type");
+			result=new Result(results->Size()+1,0,1,"control_type",control_type);
+			results->AddObject(result);
+
+			_printf_("process results:\n");
+			ProcessResults(&results,model,ControlAnalysisEnum());
+		}
+
+		_printf_("write results to disk:\n");
+		OutputResults(results,outputfilename);
 	}
 	else{
@@ -146,28 +170,4 @@
 		#endif
 	}
-
-	if(!control_analysis){
-		/*Add analysis_type to results: */
-		result=new Result(results->Size()+1,0,1,"analysis_type","steadystate");
-		results->AddObject(result);
-
-		_printf_("process results:\n");
-		ProcessResults(&results,model,SteadystateAnalysisEnum());
-	}
-	else{
-		/*Add analysis_type and control_type to results: */
-		result=new Result(results->Size()+1,0,1,"analysis_type","steadystate");
-		results->AddObject(result);
-
-		model->FindParam(&control_type,"control_type");
-		result=new Result(results->Size()+1,0,1,"control_type",control_type);
-		results->AddObject(result);
-
-		_printf_("process results:\n");
-		ProcessResults(&results,model,ControlAnalysisEnum());
-	}
-
-	_printf_("write results to disk:\n");
-	OutputResults(results,outputfilename);
 
 	_printf_("write lock file:\n");
Index: issm/trunk/src/c/parallel/thermal.cpp
===================================================================
--- issm/trunk/src/c/parallel/thermal.cpp	(revision 2047)
+++ issm/trunk/src/c/parallel/thermal.cpp	(revision 2048)
@@ -99,4 +99,13 @@
 		thermal_core(results,model,inputs);
 
+		/*Add analysis_type to results: */
+		result=new Result(results->Size()+1,0,1,"analysis_type","thermal");
+		results->AddObject(result);
+			
+		_printf_("process results:\n");
+		ProcessResults(&results,model,ThermalAnalysisEnum());
+		
+		_printf_("write results to disk:\n");
+		OutputResults(results,outputfilename);
 	}
 	else{
@@ -110,14 +119,4 @@
 		#endif
 	}
-
-	/*Add analysis_type to results: */
-	result=new Result(results->Size()+1,0,1,"analysis_type","thermal");
-	results->AddObject(result);
-		
-	_printf_("process results:\n");
-	ProcessResults(&results,model,ThermalAnalysisEnum());
-	
-	_printf_("write results to disk:\n");
-	OutputResults(results,outputfilename);
 
 	_printf_("write lock file:\n");
Index: issm/trunk/src/c/parallel/transient.cpp
===================================================================
--- issm/trunk/src/c/parallel/transient.cpp	(revision 2047)
+++ issm/trunk/src/c/parallel/transient.cpp	(revision 2048)
@@ -124,4 +124,14 @@
 		_printf_("call computational core:\n");
 		transient_core(results,model,inputs);
+	
+		/*Add analysis_type to results: */
+		result=new Result(results->Size()+1,0,1,"analysis_type","transient");
+		results->AddObject(result);
+
+		_printf_("process results:\n");
+		ProcessResults(&results,model,TransientAnalysisEnum());
+		
+		_printf_("write results to disk:\n");
+		OutputResults(results,outputfilename);
 	}
 	else{
@@ -135,15 +145,4 @@
 		#endif
 	}
-
-	/*Add analysis_type to results: */
-	result=new Result(results->Size()+1,0,1,"analysis_type","transient");
-	results->AddObject(result);
-
-	_printf_("process results:\n");
-	ProcessResults(&results,model,TransientAnalysisEnum());
-	
-	_printf_("write results to disk:\n");
-	OutputResults(results,outputfilename);
-
 	_printf_("write lock file:\n");
 	if (waitonlock){
