瀏覽代碼

mlr: fixing for loops

Luka Stanisic 8 年之前
父節點
當前提交
e3a9b5e852
共有 2 個文件被更改,包括 26 次插入18 次删除
  1. 14 10
      src/core/perfmodel/multiple_regression.c
  2. 12 8
      src/core/perfmodel/perfmodel_history.c

+ 14 - 10
src/core/perfmodel/multiple_regression.c

@@ -46,10 +46,11 @@ static void dump_multiple_regression_list(double *mpar, double *my, int start, u
 {
 	struct starpu_perfmodel_history_list *ptr = list_history;
 	int i = start;
+	int j;
 	while (ptr)
 	{
 		my[i] = ptr->entry->duration;
-		for(int j=0; j<nparameters; j++)
+		for(j=0; j<nparameters; j++)
 			mpar[i*nparameters+j] = ptr->entry->parameters[j];
 		ptr = ptr->next;
 		i++;
@@ -192,14 +193,15 @@ int dgels_multiple_reg_coeff(double *mpar, double *my, long nn, unsigned ncoeff,
 	doublereal *Y = malloc(sizeof(double)*m);
 
 	double coefficient;
-	for (int i=0; i < m; i++)
+	int i, j, k;
+	for (i=0; i < m; i++)
 	{
 		Y[i] = my[i];
 		X[i*n] = 1.;
-		for (int j=1; j < n; j++)
+		for (j=1; j < n; j++)
 		{
 			coefficient = 1.;
-			for(int k=0; k < nparameters; k++)
+			for(k=0; k < nparameters; k++)
 			{
 				coefficient *= pow(mpar[i*nparameters+k],combinations[j-1][k]);
 			}			
@@ -225,7 +227,7 @@ int dgels_multiple_reg_coeff(double *mpar, double *my, long nn, unsigned ncoeff,
 	}
 
 	/* Copy computed coefficients */
-	for(int i=0; i<ncoeff; i++)
+	for(i=0; i<ncoeff; i++)
 		coeff[i] = Y[i];
 
 	free(X);
@@ -242,19 +244,21 @@ int dgels_multiple_reg_coeff(double *mpar, double *my, long nn, unsigned ncoeff,
  */
 void validate(double *coeff, unsigned ncoeff)
 {
+	int i;
 	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]);
 		
-	for(int i=1; i<ncoeff; i++)
+	for(i=1; i<ncoeff; i++)
 		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]);
 }
 	
 int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, double *coeff, unsigned ncoeff, unsigned nparameters, unsigned **combinations, const char *codelet_name)
 {
+	int i, j;
 #ifndef STARPU_MLR_MODEL
 	_STARPU_DISP("Warning: StarPU was compiled with '--disable-mlr' option, thus multiple linear regression model will not be computed.\n");
-	for(int i=0; i<ncoeff; i++)
+	for(i=0; i<ncoeff; i++)
 		coeff[i] = 0.;
 	return 1;
 #endif //STARPU_MLR_MODEL
@@ -324,7 +328,7 @@ int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, doubl
 			f = fopen(filepath, "w+");
 			STARPU_ASSERT_MSG(f, "Could not save performance model into the file %s\n", filepath);
 			fprintf(f, "Duration");
-			for(int k=0; k < nparameters; k++)
+			for(i=0; k < nparameters; k++)
 				fprintf(f, ", P%d", k);
 		}
 	}
@@ -332,10 +336,10 @@ int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, doubl
 	/* Writing parameters to calibration file */
 	if (calibrate==1 || calibrate==2)
 	{
-		for(int i=old_lines; i<n; i++)
+		for(i=old_lines; i<n; i++)
 		{
 			fprintf(f, "\n%f", my[i]);
-			for(int j=0; j<nparameters;j++)
+			for(j=0; j<nparameters;j++)
 				fprintf(f, ", %f", mpar[i*nparameters+j]);
 		}
 		fclose(f);

+ 12 - 8
src/core/perfmodel/perfmodel_history.c

@@ -299,14 +299,15 @@ static void dump_reg_model(FILE *f, struct starpu_perfmodel *model, int comb, in
 		_starpu_multiple_regression(per_arch_model->list, reg_model->coeff, reg_model->ncoeff, model->nparameters, model->combinations, model->symbol);
 
 		fprintf(f, "# n\tintercept\t");
-		for (int i=0; i < model->ncombinations; i++)
+		int i, j, first;
+		for (i=0; i < model->ncombinations; i++)
 		{
 			if (model->parameters_names == NULL)
 				fprintf(f, "c%d", i+1);
 			else
 			{
-				int first=1;
-				for(int j=0; j < model->nparameters; j++)
+				first=1;
+				for(j=0; j < model->nparameters; j++)
 				{
 					if (model->combinations[i][j] > 0)
 					{
@@ -324,7 +325,7 @@ static void dump_reg_model(FILE *f, struct starpu_perfmodel *model, int comb, in
 		}
 
 		fprintf(f, "\n%u", reg_model->ncoeff);
-		for (int i=0; i < reg_model->ncoeff; i++)
+		for (i=0; i < reg_model->ncoeff; i++)
 			fprintf(f, "\t%-15e", reg_model->coeff[i]);
 
 	}
@@ -387,8 +388,9 @@ static void scan_reg_model(FILE *f, struct starpu_perfmodel_regression_model *re
 		reg_model->coeff = malloc(reg_model->ncoeff*sizeof(double));
 
 		unsigned multi_invalid = 0;
-
-		for (int i=0; i < reg_model->ncoeff; i++){
+		int i;
+		for (i=0; i < reg_model->ncoeff; i++)
+		{
 			res = _starpu_read_double(f, "%le", &reg_model->coeff[i]);
 			STARPU_ASSERT_MSG(res == 1, "Incorrect performance model file");
 			multi_invalid = (multi_invalid||isnan(reg_model->coeff[i]));
@@ -1319,9 +1321,11 @@ double _starpu_multiple_regression_based_job_expected_perf(struct starpu_perfmod
 	parameters = (double *) malloc(model->nparameters*sizeof(double));
 	model->parameters(j->task, parameters);
 	expected_duration=reg_model->coeff[0];
-	for (int i=0; i < model->ncombinations; i++){
+	int i, j;
+	for (i=0; i < model->ncombinations; i++)
+	{
 		parameter_value=1.;
-		for (int j=0; j < model->nparameters; j++)
+		for (j=0; j < model->nparameters; j++)
 			parameter_value *= pow(parameters[j],model->combinations[i][j]);
 
 		expected_duration += reg_model->coeff[i+1]*parameter_value;