Sfoglia il codice sorgente

eradicate using timeval

Samuel Thibault 10 anni fa
parent
commit
27f203c685

+ 16 - 16
examples/sched_ctx_utils/sched_ctx_utils.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2012, 2014  Université de Bordeaux 1
  *
  * 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
@@ -131,10 +131,10 @@ void start_2benchs(void (*bench)(unsigned, unsigned))
 	starpu_pthread_t tid[2];
 	starpu_pthread_mutex_init(&mut, NULL);
 
-	struct timeval start;
-	struct timeval end;
+	double start;
+	double end;
 
-	gettimeofday(&start, NULL);
+	start = starpu_timing_now();
 
 	starpu_pthread_create(&tid[0], NULL, (void*)start_bench, (void*)&p1);
 	starpu_pthread_create(&tid[1], NULL, (void*)start_bench, (void*)&p2);
@@ -142,11 +142,11 @@ void start_2benchs(void (*bench)(unsigned, unsigned))
 	starpu_pthread_join(tid[0], NULL);
 	starpu_pthread_join(tid[1], NULL);
 
-	gettimeofday(&end, NULL);
+	end = starpu_timing_now();
 
 	starpu_pthread_mutex_destroy(&mut);
 
-	double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
+	double timing = end - start;
 	timing /= 1000000;
 
 	printf("%2.2f %2.2f ", rv[0].flops, rv[1].flops);
@@ -160,18 +160,18 @@ void start_1stbench(void (*bench)(unsigned, unsigned))
 	p1.size = size1;
 	p1.nblocks = nblocks1;
 
-	struct timeval start;
-	struct timeval end;
+	double start;
+	double end;
 
-	gettimeofday(&start, NULL);
+	start = starpu_timing_now();
 
 	start_bench((void*)&p1);
 
-	gettimeofday(&end, NULL);
+	end = starpu_timing_now();
 
 	starpu_pthread_mutex_destroy(&mut);
 
-	double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
+	double timing = end - start;
 	timing /= 1000000;
 
 	printf("%2.2f ", rv[0].flops);
@@ -184,18 +184,18 @@ void start_2ndbench(void (*bench)(unsigned, unsigned))
 	p2.size = size2;
 	p2.nblocks = nblocks2;
 
-	struct timeval start;
-	struct timeval end;
+	double start;
+	double end;
 
-	gettimeofday(&start, NULL);
+	start = starpu_timing_now();
 
 	start_bench((void*)&p2);
 
-	gettimeofday(&end, NULL);
+	end = starpu_timing_now();
 
 	starpu_pthread_mutex_destroy(&mut);
 
-	double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
+	double timing = end - start;
 	timing /= 1000000;
 
 	printf("%2.2f ", rv[1].flops);

+ 8 - 35
examples/stencil/stencil-kernels.c

@@ -18,33 +18,6 @@
 #include "stencil.h"
 #include <sys/time.h>
 
-#ifndef timersub
-#define	timersub(x, y, res) \
-	do \
-	{						   \
-		(res)->tv_sec = (x)->tv_sec - (y)->tv_sec; \
-		(res)->tv_usec = (x)->tv_usec - (y)->tv_usec; \
-		if ((res)->tv_usec < 0) \
-		{			 \
-			(res)->tv_sec--; \
-			(res)->tv_usec += 1000000; \
-		} \
-	} while (0)
-#endif
-#ifndef timeradd
-#define	timeradd(x, y, res) \
-	do \
-	{						   \
-		(res)->tv_sec = (x)->tv_sec + (y)->tv_sec; \
-		(res)->tv_usec = (x)->tv_usec + (y)->tv_usec; \
-		if ((res)->tv_usec >= 1000000) \
-		{			       \
-			(res)->tv_sec++; \
-			(res)->tv_usec -= 1000000; \
-		} \
-	} while (0)
-#endif
-
 /* Computation Kernels */
 
 /*
@@ -123,7 +96,7 @@
 int who_runs_what_len;
 int *who_runs_what;
 int *who_runs_what_index;
-struct timeval *last_tick;
+double *last_tick;
 
 /* Achieved iterations */
 static int achieved_iter;
@@ -133,16 +106,16 @@ unsigned update_per_worker[STARPU_NMAXWORKERS];
 
 static void record_who_runs_what(struct block_description *block)
 {
-	struct timeval tv, tv2, diff, delta = {.tv_sec = 0, .tv_usec = get_ticks() * 1000};
+	double now, now2, diff, delta = get_ticks() * 1000;
 	int workerid = starpu_worker_get_id();
 
-	gettimeofday(&tv, NULL);
-	timersub(&tv, &start, &tv2);
-	timersub(&tv2, &last_tick[block->bz], &diff);
-	while (timercmp(&diff, &delta, >=))
+	now = starpu_timing_now();
+	now2 = now - start;
+	diff = now2 - last_tick[block->bz];
+	while (diff >= delta)
 	{
-		timeradd(&last_tick[block->bz], &delta, &last_tick[block->bz]);
-		timersub(&tv2, &last_tick[block->bz], &diff);
+		last_tick[block->bz] += delta;
+		diff = now2 - last_tick[block->bz];
 		if (who_runs_what_index[block->bz] < who_runs_what_len)
 			who_runs_what[block->bz + (who_runs_what_index[block->bz]++) * get_nbz()] = -1;
 	}

+ 4 - 4
examples/stencil/stencil.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2011, 2012, 2013  Centre National de la Recherche Scientifique
- * Copyright (C) 2010-2012  Université de Bordeaux 1
+ * Copyright (C) 2010-2012, 2014  Université de Bordeaux 1
  *
  * 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
@@ -149,7 +149,7 @@ static void init_problem(int argc, char **argv, int rank, int world_size)
 	who_runs_what_len = 2*niter;
 	who_runs_what = (int *) calloc(nbz * who_runs_what_len, sizeof(*who_runs_what));
 	who_runs_what_index = (int *) calloc(nbz, sizeof(*who_runs_what_index));
-	last_tick = (struct timeval *) calloc(nbz, sizeof(*last_tick));
+	last_tick = (double *) calloc(nbz, sizeof(*last_tick));
 }
 
 static void free_problem(int rank)
@@ -165,7 +165,7 @@ static void free_problem(int rank)
  *	Main body
  */
 
-struct timeval start;
+double start;
 double begin, end;
 double timing; 
 
@@ -254,7 +254,7 @@ int main(int argc, char **argv)
 	if (rank == 0)
 		FPRINTF(stderr, "GO !\n");
 
-	gettimeofday(&start, NULL);
+	start = starpu_timing_now();
 
 	begin = starpu_timing_now();
 

+ 3 - 3
examples/stencil/stencil.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2011, 2012, 2013  Centre National de la Recherche Scientifique
- * Copyright (C) 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2010-2011, 2014  Université de Bordeaux 1
  *
  * 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
@@ -130,11 +130,11 @@ extern unsigned update_per_worker[STARPU_NMAXWORKERS];
 extern unsigned top_per_worker[STARPU_NMAXWORKERS];
 extern unsigned bottom_per_worker[STARPU_NMAXWORKERS];
 
-extern struct timeval start;
+extern double start;
 extern int who_runs_what_len;
 extern int *who_runs_what;
 extern int *who_runs_what_index;
-extern struct timeval *last_tick;
+extern double *last_tick;
 
 #ifndef _externC
 #define _externC

+ 6 - 8
examples/worker_collections/worker_list_example.c

@@ -40,18 +40,16 @@ int main()
 
 	FPRINTF(stderr, "ncpus %d \n", ncpus);
 
-	struct timeval start_time;
-        struct timeval end_time;
-        gettimeofday(&start_time, NULL);
+	double start_time;
+	double end_time;
 
-	co->init(co);
+	start_time = starpu_timing_now();
 
-	gettimeofday(&end_time, NULL);
+	co->init(co);
 
-        long diff_s = end_time.tv_sec  - start_time.tv_sec;
-        long diff_us = end_time.tv_usec  - start_time.tv_usec;
+	end_time = starpu_timing_now();
 
-	float timing = (float)(diff_s*1000000 + diff_us)/1000;
+	double timing = (end_time - start_time) / 1000;
 
 	int i;
 	for(i = 0; i < ncpus; i++)

+ 6 - 8
examples/worker_collections/worker_tree_example.c

@@ -53,18 +53,16 @@ int main()
 
 	FPRINTF(stderr, "ncpus %d \n", ncpus);
 
-	struct timeval start_time;
-        struct timeval end_time;
-        gettimeofday(&start_time, NULL);
+	double start_time;
+	double end_time;
 
-	co->init(co);
+	start_time = starpu_timing_now();
 
-	gettimeofday(&end_time, NULL);
+	co->init(co);
 
-        long diff_s = end_time.tv_sec  - start_time.tv_sec;
-        long diff_us = end_time.tv_usec  - start_time.tv_usec;
+	end_time = starpu_timing_now();
 
-	float timing = (float)(diff_s*1000000 + diff_us)/1000;
+	double timing = (end_time - start_time) / 1000;
 
 	int i;
 	for(i = 0; i < ncpus; i++)