Bläddra i källkod

Factorize starpu_timing_now() call, which is not that costless

Samuel Thibault 8 år sedan
förälder
incheckning
398abcc444
2 ändrade filer med 6 tillägg och 3 borttagningar
  1. 1 1
      src/sched_policies/helper_mct.c
  2. 5 2
      src/sched_policies/parallel_heft.c

+ 1 - 1
src/sched_policies/helper_mct.c

@@ -122,6 +122,7 @@ int starpu_mct_compute_expected_times(struct starpu_sched_component *component,
 		double *min_exp_end_with_task, double *max_exp_end_with_task, int *suitable_components)
 {
 	int nsuitable_components = 0;
+	double now = starpu_timing_now();
 
 	int i;
 	for(i = 0; i < component->nchildren; i++)
@@ -136,7 +137,6 @@ int starpu_mct_compute_expected_times(struct starpu_sched_component *component,
 
 			/* Estimated availability of worker */
 			double estimated_end = c->estimated_end(c);
-			double now = starpu_timing_now();
 			if (estimated_end < now)
 				estimated_end = now;
 			estimated_transfer_length[i] = starpu_sched_component_transfer_length(c, task);

+ 5 - 2
src/sched_policies/parallel_heft.c

@@ -312,6 +312,8 @@ static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio, uns
 	int unknown = 0;
 	struct starpu_sched_ctx_iterator it;
 
+	double now = starpu_timing_now();
+
 	memset(skip_worker, 0, nworkers_ctx*STARPU_MAXIMPLEMENTATIONS*sizeof(int));
 
 	workers->init_iterator(workers, &it);
@@ -326,7 +328,7 @@ static int _parallel_heft_push_task(struct starpu_task *task, unsigned prio, uns
 			starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
 			/* Sometimes workers didn't take the tasks as early as we expected */
 			STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
-			worker_exp_start[worker] = STARPU_MAX(worker_exp_start[worker], starpu_timing_now());
+			worker_exp_start[worker] = STARPU_MAX(worker_exp_start[worker], now);
 			worker_exp_end[worker] = worker_exp_start[worker] + worker_exp_len[worker];
 			if (worker_exp_end[worker] > max_exp_end)
 				max_exp_end = worker_exp_end[worker];
@@ -513,6 +515,7 @@ static int parallel_heft_push_task(struct starpu_task *task)
 static void parallel_heft_add_workers(__attribute__((unused)) unsigned sched_ctx_id, int *workerids, unsigned nworkers)
 {
 	unsigned i;
+	double now = starpu_timing_now();
 	for (i = 0; i < nworkers; i++)
 	{
 		int workerid = workerids[i];
@@ -520,7 +523,7 @@ static void parallel_heft_add_workers(__attribute__((unused)) unsigned sched_ctx
 		/* init these structures only once for each worker */
 		if(!workerarg->has_prev_init)
 		{
-			worker_exp_start[workerid] = starpu_timing_now();
+			worker_exp_start[workerid] = now;
 			worker_exp_len[workerid] = 0.0;
 			worker_exp_end[workerid] = worker_exp_start[workerid];
 			ntasks[workerid] = 0;