瀏覽代碼

mlr: writing nan when model is unknown

Luka Stanisic 8 年之前
父節點
當前提交
6818c04f85
共有 2 個文件被更改,包括 43 次插入32 次删除
  1. 12 7
      src/core/perfmodel/multiple_regression.c
  2. 31 25
      src/core/perfmodel/perfmodel_history.c

+ 12 - 7
src/core/perfmodel/multiple_regression.c

@@ -243,15 +243,15 @@ int dgels_multiple_reg_coeff(double *mpar, double *my, long nn, unsigned ncoeff,
    Validating the accuracy of the coefficients.
    Validating the accuracy of the coefficients.
    For the the validation is extremely basic, but it should be improved.
    For the the validation is extremely basic, but it should be improved.
  */
  */
-void validate(double *coeff, unsigned ncoeff)
+void validate(double *coeff, unsigned ncoeff, const char *codelet_name)
 {
 {
 	unsigned i;
 	unsigned i;
 	if (coeff[0] < 0)
 	if (coeff[0] < 0)
-		_STARPU_DISP("Warning: Constant computed by least square method is negative (%f). The model is likely to be inaccurate.\n", coeff[0]);
+		_STARPU_DISP("Warning: Constant computed by least square method is negative (%f). The model %s is likely to be inaccurate.\n", coeff[0], codelet_name);
 		
 		
 	for(i=1; i<ncoeff; i++)
 	for(i=1; i<ncoeff; i++)
 		if(coeff[i] < 1E-10)
 		if(coeff[i] < 1E-10)
-			_STARPU_DISP("Warning: Coefficient computed by least square method is extremelly small (%f). The model is likely to be inaccurate.\n", coeff[i]);
+			_STARPU_DISP("Warning: Coefficient computed by least square method is extremelly small (%f). The model %s is likely to be inaccurate.\n", coeff[i], codelet_name);
 }
 }
 	
 	
 int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, double *coeff, unsigned ncoeff, unsigned nparameters, const char **parameters_names, unsigned **combinations, const char *codelet_name)
 int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, double *coeff, unsigned ncoeff, unsigned nparameters, const char **parameters_names, unsigned **combinations, const char *codelet_name)
@@ -260,6 +260,8 @@ int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, doubl
 	unsigned j;
 	unsigned j;
 #ifndef STARPU_MLR_MODEL
 #ifndef STARPU_MLR_MODEL
 	_STARPU_DISP("Warning: StarPU was compiled with '--disable-mlr' option or on Windows machine, thus multiple linear regression model will not be computed.\n");
 	_STARPU_DISP("Warning: StarPU was compiled with '--disable-mlr' option or on Windows machine, thus multiple linear regression model will not be computed.\n");
+	if (ncoeff==0 || combinations==NULL)
+		return 2;
 	for(i=0; i<ncoeff; i++)
 	for(i=0; i<ncoeff; i++)
 		coeff[i] = 0.;
 		coeff[i] = 0.;
 	return 1;
 	return 1;
@@ -308,14 +310,17 @@ int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, doubl
 	/* Filling X and Y matrices with measured values */
 	/* Filling X and Y matrices with measured values */
 	dump_multiple_regression_list(mpar, my, old_lines, nparameters, ptr);
 	dump_multiple_regression_list(mpar, my, old_lines, nparameters, ptr);
 
 
+	if (ncoeff!=0 && combinations!=NULL)
+	{
 #ifdef STARPU_MLR_MODEL
 #ifdef STARPU_MLR_MODEL
-	/* Computing coefficients using multiple linear regression */
-	if(dgels_multiple_reg_coeff(mpar, my, n, ncoeff, nparameters, coeff, combinations))
+		/* Computing coefficients using multiple linear regression */
+		if(dgels_multiple_reg_coeff(mpar, my, n, ncoeff, nparameters, coeff, combinations))
 		return 1;
 		return 1;
 #endif //STARPU_MLR_MODEL
 #endif //STARPU_MLR_MODEL
 
 
-	/* Basic validation of the model accuracy */
-	validate(coeff, ncoeff);
+		/* Basic validation of the model accuracy */
+		validate(coeff, ncoeff, codelet_name);
+	}
 	
 	
 	/* Preparing new output calibration file */
 	/* Preparing new output calibration file */
 	if (calibrate==1 || calibrate==2)
 	if (calibrate==1 || calibrate==2)

+ 31 - 25
src/core/perfmodel/perfmodel_history.c

@@ -292,8 +292,10 @@ static void dump_reg_model(FILE *f, struct starpu_perfmodel *model, int comb, in
 
 
 	if (model->type == STARPU_MULTIPLE_REGRESSION_BASED)
 	if (model->type == STARPU_MULTIPLE_REGRESSION_BASED)
 	{
 	{
-		if (reg_model->ncoeff==0)
+		if (reg_model->ncoeff==0 && model->ncombinations!=0 && model->combinations!=NULL)
+		{
 			reg_model->ncoeff = model->ncombinations + 1;
 			reg_model->ncoeff = model->ncombinations + 1;
+		}
 
 
 		reg_model->coeff = (double *) malloc(reg_model->ncoeff*sizeof(double));
 		reg_model->coeff = (double *) malloc(reg_model->ncoeff*sizeof(double));
 		_starpu_multiple_regression(per_arch_model->list, reg_model->coeff, reg_model->ncoeff, model->nparameters, model->parameters_names, model->combinations, model->symbol);
 		_starpu_multiple_regression(per_arch_model->list, reg_model->coeff, reg_model->ncoeff, model->nparameters, model->parameters_names, model->combinations, model->symbol);
@@ -301,39 +303,43 @@ static void dump_reg_model(FILE *f, struct starpu_perfmodel *model, int comb, in
 		fprintf(f, "# n\tintercept\t");
 		fprintf(f, "# n\tintercept\t");
 	        unsigned i, j;
 	        unsigned i, j;
 		int first;
 		int first;
-		for (i=0; i < model->ncombinations; i++)
+		if (reg_model->ncoeff==0 || model->ncombinations==0 || model->combinations==NULL)
+			fprintf(f, "\n1\tnan");
+		else
 		{
 		{
-			if (model->parameters_names == NULL)
-				fprintf(f, "c%d", i+1);
-			else
+			for (i=0; i < model->ncombinations; i++)
 			{
 			{
-				first=1;
-				for(j=0; j < model->nparameters; j++)
+				if (model->parameters_names == NULL)
+					fprintf(f, "c%d", i+1);
+				else
 				{
 				{
-					if (model->combinations[i][j] > 0)
+					first=1;
+					for(j=0; j < model->nparameters; j++)
 					{
 					{
-						if (first)
-							first=0;
-						else
-							fprintf(f, "*");
+						if (model->combinations[i][j] > 0)
+						{
+							if (first)
+								first=0;
+							else
+								fprintf(f, "*");
 						
 						
-						if(model->parameters_names[j]!= NULL)
-							fprintf(f, "%s", model->parameters_names[j]);
-						else
-							fprintf(f, "P%d", j);
+							if(model->parameters_names[j] != NULL)
+								fprintf(f, "%s", model->parameters_names[j]);
+							else
+								fprintf(f, "P%d", j);
 						
 						
-						if (model->combinations[i][j] > 1)
-							fprintf(f, "^%d", model->combinations[i][j]);
+							if (model->combinations[i][j] > 1)
+								fprintf(f, "^%d", model->combinations[i][j]);
+						}
 					}
 					}
 				}
 				}
+				fprintf(f, "\t\t");
 			}
 			}
-			fprintf(f, "\t\t");
-		}
-
-		fprintf(f, "\n%u", reg_model->ncoeff);
-		for (i=0; i < reg_model->ncoeff; i++)
-			fprintf(f, "\t%-15e", reg_model->coeff[i]);
 
 
+			fprintf(f, "\n%u", reg_model->ncoeff);
+			for (i=0; i < reg_model->ncoeff; i++)
+				fprintf(f, "\t%-15e", reg_model->coeff[i]);
+		}
 	}
 	}
 }
 }
 #endif
 #endif
@@ -1323,7 +1329,7 @@ double _starpu_multiple_regression_based_job_expected_perf(struct starpu_perfmod
 	reg_model = &model->state->per_arch[comb][nimpl].regression;
 	reg_model = &model->state->per_arch[comb][nimpl].regression;
 	if (reg_model->coeff == NULL)
 	if (reg_model->coeff == NULL)
 		goto docal;
 		goto docal;
-
+	
 	double parameter_value;
 	double parameter_value;
 	double *parameters;
 	double *parameters;
 	parameters = (double *) malloc(model->nparameters*sizeof(double));
 	parameters = (double *) malloc(model->nparameters*sizeof(double));