浏览代码

perfmodel: use our own function to write double (we already had one for reading them), windows cannot be relied on

Nathalie Furmento 9 年之前
父节点
当前提交
3d9232c549

+ 3 - 2
src/core/perfmodel/perfmodel.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
  * Copyright (C) 2009-2015  Université de Bordeaux
  * Copyright (C) 2009-2015  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  * Copyright (C) 2011  Télécom-SudParis
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
@@ -98,9 +98,10 @@ int *_starpu_get_cuda_affinity_vector(unsigned gpuid);
 int *_starpu_get_opencl_affinity_vector(unsigned gpuid);
 int *_starpu_get_opencl_affinity_vector(unsigned gpuid);
 #endif
 #endif
 
 
-void _starpu_save_bandwidth_and_latency_disk(double bandwidth_write, double bandwidth_read, 
+void _starpu_save_bandwidth_and_latency_disk(double bandwidth_write, double bandwidth_read,
 					    double latency_write, double latency_read, unsigned node);
 					    double latency_write, double latency_read, unsigned node);
 
 
+void _starpu_write_double(FILE *f, char *format, double val);
 int _starpu_read_double(FILE *f, char *format, double *val);
 int _starpu_read_double(FILE *f, char *format, double *val);
 void _starpu_simgrid_get_platform_path(char *path, size_t maxlen);
 void _starpu_simgrid_get_platform_path(char *path, size_t maxlen);
 
 

+ 6 - 6
src/core/perfmodel/perfmodel_bus.c

@@ -1030,7 +1030,7 @@ static int load_bus_latency_file_content(void)
 		_starpu_drop_comments(f);
 		_starpu_drop_comments(f);
 		for (dst = 0; dst < STARPU_MAXNODES; dst++)
 		for (dst = 0; dst < STARPU_MAXNODES; dst++)
 		{
 		{
-			n = _starpu_read_double(f, "%lf", &latency);
+			n = _starpu_read_double(f, "%le", &latency);
 			if (n != 1)
 			if (n != 1)
 			{
 			{
 				_STARPU_DISP("Error while reading latency file <%s>. Expected a number\n", path);
 				_STARPU_DISP("Error while reading latency file <%s>. Expected a number\n", path);
@@ -1069,7 +1069,7 @@ static int load_bus_latency_file_content(void)
 				break;
 				break;
 			ungetc(n, f);
 			ungetc(n, f);
 
 
-			n = _starpu_read_double(f, "%lf", &latency);
+			n = _starpu_read_double(f, "%le", &latency);
 			if (n && !isnan(latency))
 			if (n && !isnan(latency))
 			{
 			{
 				_STARPU_DISP("Too many nodes in latency file %s for this configuration (%d)\n", path, STARPU_MAXNODES);
 				_STARPU_DISP("Too many nodes in latency file %s for this configuration (%d)\n", path, STARPU_MAXNODES);
@@ -1179,7 +1179,7 @@ static void write_bus_latency_file_content(void)
 
 
 			if (dst)
 			if (dst)
 				fputc('\t', f);
 				fputc('\t', f);
-			fprintf(f, "%lf", latency);
+			_starpu_write_double(f, "%e", latency);
 		}
 		}
 
 
 		fprintf(f, "\n");
 		fprintf(f, "\n");
@@ -1252,7 +1252,7 @@ static int load_bus_bandwidth_file_content(void)
 		_starpu_drop_comments(f);
 		_starpu_drop_comments(f);
 		for (dst = 0; dst < STARPU_MAXNODES; dst++)
 		for (dst = 0; dst < STARPU_MAXNODES; dst++)
 		{
 		{
-			n = _starpu_read_double(f, "%lf", &bandwidth);
+			n = _starpu_read_double(f, "%le", &bandwidth);
 			if (n != 1)
 			if (n != 1)
 			{
 			{
 				_STARPU_DISP("Error while reading bandwidth file <%s>. Expected a number\n", path);
 				_STARPU_DISP("Error while reading bandwidth file <%s>. Expected a number\n", path);
@@ -1291,7 +1291,7 @@ static int load_bus_bandwidth_file_content(void)
 				break;
 				break;
 			ungetc(n, f);
 			ungetc(n, f);
 
 
-			n = _starpu_read_double(f, "%lf", &bandwidth);
+			n = _starpu_read_double(f, "%le", &bandwidth);
 			if (n && !isnan(bandwidth))
 			if (n && !isnan(bandwidth))
 			{
 			{
 				_STARPU_DISP("Too many nodes in bandwidth file %s for this configuration (%d)\n", path, STARPU_MAXNODES);
 				_STARPU_DISP("Too many nodes in bandwidth file %s for this configuration (%d)\n", path, STARPU_MAXNODES);
@@ -1408,7 +1408,7 @@ static void write_bus_bandwidth_file_content(void)
 
 
 			if (dst)
 			if (dst)
 				fputc('\t', f);
 				fputc('\t', f);
-			fprintf(f, "%f", bandwidth);
+			_starpu_write_double(f, "%e", bandwidth);
 		}
 		}
 
 
 		fprintf(f, "\n");
 		fprintf(f, "\n");

+ 11 - 2
src/core/perfmodel/perfmodel_history.c

@@ -261,7 +261,11 @@ static void dump_reg_model(FILE *f, struct starpu_perfmodel *model, int comb, in
 	}
 	}
 
 
 	fprintf(f, "# sumlnx\tsumlnx2\t\tsumlny\t\tsumlnxlny\talpha\t\tbeta\t\tn\tminx\t\tmaxx\n");
 	fprintf(f, "# sumlnx\tsumlnx2\t\tsumlny\t\tsumlnxlny\talpha\t\tbeta\t\tn\tminx\t\tmaxx\n");
-	fprintf(f, "%-15le\t%-15le\t%-15le\t%-15le\t%-15le\t%-15le\t%u\t%-15lu\t%-15lu\n", reg_model->sumlnx, reg_model->sumlnx2, reg_model->sumlny, reg_model->sumlnxlny, alpha, beta, reg_model->nsample, reg_model->minx, reg_model->maxx);
+	fprintf(f, "%-15le\t%-15le\t%-15le\t%-15le\t", reg_model->sumlnx, reg_model->sumlnx2, reg_model->sumlny, reg_model->sumlnxlny);
+	_starpu_write_double(f, "%-15e", alpha);
+	fprintf(f, "\t");
+	_starpu_write_double(f, "%-15e", beta);
+	fprintf(f, "\t%u\t%-15lu\t%-15lu\n", reg_model->nsample, reg_model->minx, reg_model->maxx);
 
 
 	/*
 	/*
 	 * Non-Linear Regression model
 	 * Non-Linear Regression model
@@ -273,7 +277,12 @@ static void dump_reg_model(FILE *f, struct starpu_perfmodel *model, int comb, in
 		_starpu_regression_non_linear_power(per_arch_model->list, &a, &b, &c);
 		_starpu_regression_non_linear_power(per_arch_model->list, &a, &b, &c);
 
 
 	fprintf(f, "# a\t\tb\t\tc\n");
 	fprintf(f, "# a\t\tb\t\tc\n");
-	fprintf(f, "%-15le\t%-15le\t%-15le\n", a, b, c);
+	_starpu_write_double(f, "%-15e", a);
+	fprintf(f, "\t");
+	_starpu_write_double(f, "%-15e", b);
+	fprintf(f, "\t");
+	_starpu_write_double(f, "%-15e", c);
+	fprintf(f, "\n");
 }
 }
 #endif
 #endif
 
 

+ 17 - 4
src/core/perfmodel/perfmodel_nan.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
- * Copyright (C) 2013  CNRS
+ * Copyright (C) 2013, 2015  CNRS
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * it under the terms of the GNU Lesser General Public License as published by
@@ -14,9 +14,6 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
  */
 
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <math.h>
 #include <math.h>
@@ -42,6 +39,22 @@ void _starpu_read_spaces(FILE *f)
 }
 }
 #endif /* STARPU_HAVE_WINDOWS */
 #endif /* STARPU_HAVE_WINDOWS */
 
 
+void _starpu_write_double(FILE *f, char *format, double val)
+{
+#ifdef STARPU_HAVE_WINDOWS
+        if (isnan(val))
+        {
+                fprintf(f, "nan ");
+        }
+        else
+        {
+                fprintf(f, format, val);
+        }
+#else
+	fprintf(f, format, val);
+#endif
+}
+
 int _starpu_read_double(FILE *f, char *format, double *val)
 int _starpu_read_double(FILE *f, char *format, double *val)
 {
 {
 #ifdef STARPU_HAVE_WINDOWS
 #ifdef STARPU_HAVE_WINDOWS

+ 15 - 14
tests/perfmodels/value_nan.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
- * Copyright (C) 2013  CNRS
+ * Copyright (C) 2013, 2015  CNRS
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * it under the terms of the GNU Lesser General Public License as published by
@@ -55,7 +55,9 @@ int _check_number(double val, int checknan)
 		FPRINTF(stderr, "Error when opening file %s\n", filename);
 		FPRINTF(stderr, "Error when opening file %s\n", filename);
 		return 1;
 		return 1;
 	}
 	}
-	fprintf(f, "%lf %s\n", val, STRING);
+	// A double is written with the format %e ...
+	_starpu_write_double(f, "%e", val);
+	fprintf(f, " %s\n", STRING);
 	fclose(f);
 	fclose(f);
 
 
 	/* read the double value and the string back from the file */
 	/* read the double value and the string back from the file */
@@ -67,8 +69,9 @@ int _check_number(double val, int checknan)
 	}
 	}
 	double lat;
 	double lat;
 	char str[10];
 	char str[10];
-	int x = _starpu_read_double(f, "%lf", &lat);
-	int y = fscanf(f, "%s", str);
+	// ... but is read with the format %le
+	int x = _starpu_read_double(f, "%le", &lat);
+	int y = fscanf(f, " %s", str);
 	fclose(f);
 	fclose(f);
 	unlink(filename);
 	unlink(filename);
 
 
@@ -79,22 +82,20 @@ int _check_number(double val, int checknan)
 	if (checknan)
 	if (checknan)
 		pass = pass && isnan(val) && isnan(lat);
 		pass = pass && isnan(val) && isnan(lat);
 	else
 	else
-		pass = pass && lat == val;
+		pass = pass && (int)lat == (int)val;
 	return pass?0:1;
 	return pass?0:1;
 }
 }
 
 
 int main(int argc, char **argv)
 int main(int argc, char **argv)
 {
 {
-	int ret;
+	int ret1, ret2;
+	double nanvalue = nan("");
 
 
-	ret = _check_number(42.0, 0);
-	FPRINTF(stderr, "%s when reading %lf\n", ret==0?"Success":"Error", 42.0);
+	ret1 = _check_number(42.0, 0);
+	FPRINTF(stderr, "%s when reading %e\n", ret1==0?"Success":"Error", 42.0);
 
 
-	if (ret==0)
-	{
-	     ret = _check_number(NAN, 1);
-	     FPRINTF(stderr, "%s when reading %lf\n", ret==0?"Success":"Error", NAN);
-	}
+	ret2 = _check_number(nanvalue, 1);
+	FPRINTF(stderr, "%s when reading %e\n", ret2==0?"Success":"Error", nanvalue);
 
 
-	return ret;
+	return ret1+ret2;
 }
 }