Objet : Developers list for StarPU
Archives de la liste
- From: Nathalie Furmento <nathalie.furmento@labri.fr>
- To: starpu-devel@lists.gforge.inria.fr
- Subject: [Starpu-devel] [patch request] Double comparison
- Date: Mon, 30 Jan 2012 13:25:30 +0100
- List-archive: <http://lists.gforge.inria.fr/pipermail/starpu-devel>
- List-id: "Developers list. For discussion of new features, code changes, etc." <starpu-devel.lists.gforge.inria.fr>
As we are not supposed to compare double values, here a patch that
uses fpclassify or nearbyint to compare double values.
Let me know if you see anything wrong,
Cheers,
Nathalie
Index: src/common/utils.c
===================================================================
--- src/common/utils.c (revision 5379)
+++ src/common/utils.c (working copy)
@@ -1,7 +1,7 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010, 2012 Université de Bordeaux 1
- * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche
Scientifique
*
* 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
@@ -20,6 +20,7 @@
#include <common/utils.h>
#include <libgen.h>
#include <errno.h>
+#include <math.h>
#ifdef __MINGW32__
#include <io.h>
@@ -92,3 +93,10 @@
return 1;
}
+
+int _starpu_approximately_equal(double a, double b)
+{
+ int ai = (int) nearbyint(a * 1000.0);
+ int bi = (int) nearbyint(b * 1000.0);
+ return ai == bi;
+}
Index: src/common/utils.h
===================================================================
--- src/common/utils.h (revision 5379)
+++ src/common/utils.h (working copy)
@@ -1,7 +1,7 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010 Université de Bordeaux 1
- * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche
Scientifique
*
* 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
@@ -50,6 +50,8 @@
} while (0)
+int _starpu_approximately_equal(double a, double b);
+
int _starpu_mkpath(const char *s, mode_t mode);
int _starpu_check_mutex_deadlock(pthread_mutex_t *mutex);
Index: src/core/perfmodel/perfmodel_history.c
===================================================================
--- src/core/perfmodel/perfmodel_history.c (revision 5379)
+++ src/core/perfmodel/perfmodel_history.c (working copy)
@@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <common/config.h>
+#include <common/utils.h>
#include <core/perfmodel/perfmodel.h>
#include <core/jobs.h>
#include <core/workers.h>
@@ -962,7 +963,7 @@
/* Not calibrated enough */
exp = -1.0;
- if (exp == -1.0 && !model->benchmarking)
+ if (_starpu_approximately_equal(exp, -1.0) && !model->benchmarking)
{
_STARPU_DISP("Warning: model %s is not calibrated enough,
forcing calibration for this run. Use the STARPU_CALIBRATE environment
variable to control this.\n", model->symbol);
_starpu_set_calibrate_flag(1);
Index: src/core/perfmodel/perfmodel.c
===================================================================
--- src/core/perfmodel/perfmodel.c (revision 5380)
+++ src/core/perfmodel/perfmodel.c (working copy)
@@ -26,6 +26,7 @@
#include <core/jobs.h>
#include <core/workers.h>
#include <datawizard/datawizard.h>
+#include <math.h>
#ifdef STARPU_HAVE_WINDOWS
#include <windows.h>
@@ -125,7 +126,7 @@
exp = model->cost_function(task, nimpl);
alpha = starpu_worker_get_relative_speedup(arch);
- STARPU_ASSERT(alpha != 0.0f);
+ STARPU_ASSERT(fpclassify(alpha) != FP_ZERO);
return (exp/alpha);
}
@@ -134,7 +135,7 @@
exp = model->cost_model(task->buffers);
alpha = starpu_worker_get_relative_speedup(arch);
- STARPU_ASSERT(alpha != 0.0f);
+ STARPU_ASSERT(fpclassify(alpha) != FP_ZERO);
return (exp/alpha);
}
Index: src/profiling/bound.c
===================================================================
--- src/profiling/bound.c (revision 5379)
+++ src/profiling/bound.c (working copy)
@@ -1,6 +1,6 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
- * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche
Scientifique
* Copyright (C) 2010, 2011 Université de Bordeaux 1
* Copyright (C) 2011 Télécom-SudParis
*
@@ -25,6 +25,7 @@
#include <starpu_config.h>
#include <profiling/bound.h>
#include <core/jobs.h>
+#include <math.h>
#ifdef HAVE_GLPK_H
#include <glpk.h>
@@ -353,7 +354,7 @@
};
enum starpu_perf_archtype arch =
starpu_worker_get_perf_archtype(w);
double length =
_starpu_history_based_job_expected_perf(tp->cl->model, arch, &j, j.nimpl);
- if (length == -1.0)
+ if ( _starpu_approximately_equal(length, -1.0))
times[w*nt+t] = -1.0;
else
times[w*nt+t] = length / 1000.;
@@ -429,10 +430,10 @@
for (w = 0; w < nw; w++)
{
enum starpu_perf_archtype arch =
starpu_worker_get_perf_archtype(w);
- if (t1->duration[arch] == 0.)
+ if (fpclassify(t1->duration[arch]) == FP_ZERO)
{
double length =
_starpu_history_based_job_expected_perf(t1->cl->model, arch, &j,j.nimpl);
- if (length == -1.0)
+ if (
_starpu_approximately_equal(length, -1.0))
/* Avoid problems with binary
coding of doubles */
t1->duration[arch] = -1.0;
else
@@ -456,7 +457,7 @@
for (w = 0; w < nw; w++)
{
enum starpu_perf_archtype arch =
starpu_worker_get_perf_archtype(w);
- if (t1->duration[arch] != -1.0)
+ if
(!_starpu_approximately_equal(t1->duration[arch], -1.0))
fprintf(output, " +t%luw%d", t1->id,
w);
}
fprintf(output, " = 1;\n");
@@ -470,7 +471,7 @@
for (w = 0; w < nw; w++)
{
enum starpu_perf_archtype arch =
starpu_worker_get_perf_archtype(w);
- if (t1->duration[arch] != -1.0)
+ if (!
_starpu_approximately_equal(t1->duration[arch], -1.0))
fprintf(output, " + %f t%luw%d",
t1->duration[arch], t1->id, w);
}
fprintf(output, ";\n");
@@ -506,7 +507,7 @@
for (w = 0; w < nw; w++)
{
enum starpu_perf_archtype
arch = starpu_worker_get_perf_archtype(w);
- if (t1->duration[arch] !=
-1.0)
+ if (!
_starpu_approximately_equal(t1->duration[arch], -1.0))
{
fprintf(output, "s%lu
- c%lu >= -3e5 + 1e5 t%luw%d + 1e5 t%luw%d + 1e5 t%luafter%lu;\n",
t1->id, t2->id, t1->id, w, t2->id, w, t1->id, t2->id);
@@ -651,7 +652,7 @@
fprintf(output, "/* worker %s */\n0", name);
for (t = 0, tp = task_pools; tp; t++, tp =
tp->next)
{
- if (times[w*nt+t] != -1.0)
+ if (!
_starpu_approximately_equal(times[w*nt+t], -1.0))
fprintf(output, "\t%+f *
w%dt%dn", (float) times[w*nt+t], w, t);
}
fprintf(output, " <= tmax;\n");
@@ -663,7 +664,7 @@
{
fprintf(output, "/* task %s key %x */\n0",
tp->cl->name, (unsigned) tp->footprint);
for (w = 0; w < nw; w++)
- if (times[w*nt+t] != -1.0)
+ if (!
_starpu_approximately_equal(times[w*nt+t], -1.0))
fprintf(output, "\t+w%dt%dn",
w, t);
fprintf(output, " = %lu;\n", tp->n);
/* Show actual values */
@@ -747,7 +748,7 @@
fprintf(output, "\n* Execution times and completion of all
tasks\n");
for (w = 0; w < nw; w++)
for (t = 0, tp = task_pools; tp; t++, tp = tp->next)
- if (times[w*nt+t] != -1.0)
+ if (!
_starpu_approximately_equal(times[w*nt+t], -1.0))
{
char name[9];
snprintf(name, sizeof(name),
"W%dT%d", w, t);
@@ -830,7 +831,7 @@
{
int someone = 0;
for (w = 0; w < nw; w++)
- if (times[w*nt+t] != -1.)
+ if (!
_starpu_approximately_equal(times[w*nt+t], -1.0))
someone = 1;
if (!someone)
{
@@ -849,7 +850,7 @@
{
ia[n] = w+1;
ja[n] = colnum(w, t);
- if (times[w*nt+t] == -1.)
+ if
(_starpu_approximately_equal(times[w*nt+t], -1.0))
ar[n] = 1000000000.;
else
ar[n] = times[w*nt+t];
Index: src/datawizard/coherency.c
===================================================================
--- src/datawizard/coherency.c (revision 5379)
+++ src/datawizard/coherency.c (working copy)
@@ -1,7 +1,7 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2009-2011 Université de Bordeaux 1
- * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche
Scientifique
*
* 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
@@ -67,7 +67,7 @@
if (!link_supports_direct_transfers(handle,
i, destination, &handling_node))
continue;
- if (time == 0.0)
+ if (fpclassify(time) == FP_ZERO)
{
/* No estimation, will have to revert
to dumb strategy */
cost = 0.0;
Index: src/sched_policies/parallel_heft.c
===================================================================
--- src/sched_policies/parallel_heft.c (revision 5379)
+++ src/sched_policies/parallel_heft.c (working copy)
@@ -262,16 +262,16 @@
double ntasks_end = compute_ntasks_end(worker);
if (ntasks_best == -1
- || (!calibrating && ntasks_end <
ntasks_best_end) /* Not calibrating, take better task */
- || (!calibrating &&
local_task_length[worker][nimpl] == -1.0) /* Not calibrating but this worker
is being calibrated */
- || (calibrating &&
local_task_length[worker][nimpl] == -1.0 && ntasks_end < ntasks_best_end) /*
Calibrating, compete this worker with other non-calibrated */
+ || (!calibrating && ntasks_end < ntasks_best_end)
/* Not calibrating, take better task */
+ || (!calibrating &&
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0)) /* Not
calibrating but this worker is being calibrated */
+ || (calibrating &&
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0) &&
ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other
non-calibrated */
)
{
ntasks_best_end = ntasks_end;
ntasks_best = worker;
}
- if (local_task_length[worker][nimpl] == -1.0)
+ if (
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0))
/* we are calibrating, we want to speed-up
calibration time
* so we privilege non-calibrated tasks (but
still
* greedily distribute them to avoid dumb
schedules) */
@@ -300,7 +300,7 @@
local_power[worker][nimpl] =
starpu_task_expected_power(task, perf_arch,nimpl);
//_STARPU_DEBUG("Scheduler parallel heft: task length
(%lf) local power (%lf) worker (%u) kernel (%u) \n",
local_task_length[worker][nimpl],local_power[worker][nimpl],worker,nimpl);
- if (local_power[worker][nimpl] == -1.0)
+ if (
_starpu_approximately_equal(local_power[worker][nimpl], -1.0))
local_power[worker][nimpl] = 0.;
} //end for
Index: src/sched_policies/deque_modeling_policy_data_aware.c
===================================================================
--- src/sched_policies/deque_modeling_policy_data_aware.c (revision
5379)
+++ src/sched_policies/deque_modeling_policy_data_aware.c (working copy)
@@ -1,7 +1,7 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2010, 2011-2012 Université de Bordeaux 1
- * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche
Scientifique
* Copyright (C) 2011 Télécom-SudParis
*
* StarPU is free software; you can redistribute it and/or modify
@@ -344,17 +344,17 @@
//_STARPU_DEBUG("Scheduler dm: task length (%lf)
worker (%u) kernel (%u) \n", local_length,worker,nimpl);
if (ntasks_best == -1
- || (!calibrating && ntasks_end <
ntasks_best_end) /* Not calibrating, take better task */
- || (!calibrating && local_length ==
-1.0) /* Not calibrating but this worker is being calibrated */
- || (calibrating && local_length ==
-1.0 && ntasks_end < ntasks_best_end) /* Calibrating, compete this worker
with other non-calibrated */
- )
+ || (!calibrating && ntasks_end < ntasks_best_end)
/* Not calibrating, take better task */
+ || (!calibrating &&
_starpu_approximately_equal(local_length, -1.0)) /* Not calibrating but this
worker is being calibrated */
+ || (calibrating &&
_starpu_approximately_equal(local_length, -1.0) && ntasks_end <
ntasks_best_end) /* Calibrating, compete this worker with other
non-calibrated */
+ )
{
ntasks_best_end = ntasks_end;
ntasks_best = worker;
best_impl = nimpl;
}
- if (local_length == -1.0)
+ if (_starpu_approximately_equal(local_length, -1.0))
/* we are calibrating, we want to speed-up
calibration time
* so we privilege non-calibrated tasks (but
still
* greedily distribute them to avoid dumb
schedules) */
@@ -457,17 +457,17 @@
double ntasks_end = fifo->ntasks /
starpu_worker_get_relative_speedup(perf_arch);
if (ntasks_best == -1
- || (!calibrating && ntasks_end <
ntasks_best_end) /* Not calibrating, take better task */
- || (!calibrating &&
local_task_length[worker][nimpl] == -1.0) /* Not calibrating but this worker
is being calibrated */
- || (calibrating &&
local_task_length[worker][nimpl] == -1.0 && ntasks_end < ntasks_best_end) /*
Calibrating, compete this worker with other non-calibrated */
- )
+ || (!calibrating && ntasks_end < ntasks_best_end)
/* Not calibrating, take better task */
+ || (!calibrating &&
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0)) /* Not
calibrating but this worker is being calibrated */
+ || (calibrating &&
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0) &&
ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other
non-calibrated */
+ )
{
ntasks_best_end = ntasks_end;
ntasks_best = worker;
best_impl = nimpl;
}
- if (local_task_length[worker][nimpl] == -1.0)
+ if
(_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0))
/* we are calibrating, we want to speed-up
calibration time
* so we privilege non-calibrated tasks (but
still
* greedily distribute them to avoid dumb
schedules) */
@@ -491,7 +491,7 @@
}
local_power[worker][nimpl] =
starpu_task_expected_power(task, perf_arch, nimpl);
- if (local_power[worker][nimpl] == -1.0)
+ if
(_starpu_approximately_equal(local_power[worker][nimpl], -1.0))
local_power[worker][nimpl] = 0.;
}
Index: src/sched_policies/heft.c
===================================================================
--- src/sched_policies/heft.c (revision 5380)
+++ src/sched_policies/heft.c (working copy)
@@ -139,7 +139,7 @@
exp_end[workerid] = exp_start[workerid] + exp_len[workerid];
/* If there is no prediction available, we consider the task has a
null length */
- if (predicted != -1.0)
+ if (!_starpu_approximately_equal(predicted, -1.0))
{
task->predicted = predicted;
exp_end[workerid] += predicted;
@@ -147,7 +147,7 @@
}
/* If there is no prediction available, we consider the task has a
null length */
- if (predicted_transfer != -1.0)
+ if (!_starpu_approximately_equal(predicted_transfer, -1.0))
{
if (starpu_timing_now() + predicted_transfer <
exp_end[workerid])
{
@@ -289,9 +289,9 @@
double ntasks_end = ntasks[worker] /
starpu_worker_get_relative_speedup(perf_arch);
if (ntasks_best == -1
- || (!calibrating && ntasks_end <
ntasks_best_end) /* Not calibrating, take better task */
- || (!calibrating &&
local_task_length[worker][nimpl] == -1.0) /* Not calibrating but this worker
is being calibrated */
- || (calibrating &&
local_task_length[worker][nimpl] == -1.0 && ntasks_end < ntasks_best_end) /*
Calibrating, compete this worker with other non-calibrated */
+ || (!calibrating && ntasks_end < ntasks_best_end)
/* Not calibrating, take better task */
+ || (!calibrating &&
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0)) /* Not
calibrating but this worker is being calibrated */
+ || (calibrating &&
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0) &&
ntasks_end < ntasks_best_end) /* Calibrating, compete this worker with other
non-calibrated */
)
{
ntasks_best_end = ntasks_end;
@@ -299,7 +299,7 @@
nimpl_best = nimpl;
}
- if (local_task_length[worker][nimpl] == -1.0)
+ if (
_starpu_approximately_equal(local_task_length[worker][nimpl], -1.0))
/* we are calibrating, we want to speed-up
calibration time
* so we privilege non-calibrated tasks (but
still
* greedily distribute them to avoid dumb
schedules) */
@@ -322,7 +322,7 @@
nimpl_best = nimpl;
}
- if (local_power[worker][nimpl] == -1.0)
+ if (
_starpu_approximately_equal(local_power[worker][nimpl], -1.0))
local_power[worker][nimpl] = 0.;
}
- [Starpu-devel] [patch request] Double comparison, Nathalie Furmento, 30/01/2012
- <Suite(s) possible(s)>
- Re: [Starpu-devel] [patch request] Double comparison, Samuel Thibault, 30/01/2012
- Re: [Starpu-devel] [patch request] Double comparison, Nathalie Furmento, 30/01/2012
- Message indisponible
- Re: [Starpu-devel] [patch request] Double comparison, Samuel Thibault, 30/01/2012
- Message indisponible
- Re: [Starpu-devel] [patch request] Double comparison, Samuel Thibault, 30/01/2012
Archives gérées par MHonArc 2.6.19+.