Przeglądaj źródła

- Add timing in the incrementer example.
- Generate a graph to show the duration of the incrementer test depending on
the number of iterations.

Cédric Augonnet 15 lat temu
rodzic
commit
395d4f8c66
2 zmienionych plików z 67 dodań i 3 usunięć
  1. 17 3
      examples/incrementer/incrementer.c
  2. 50 0
      tests/incrementer/speed.sh

+ 17 - 3
examples/incrementer/incrementer.c

@@ -17,13 +17,12 @@
 #include <starpu.h>
 #include <pthread.h>
 
-#define NITER	50000
+static unsigned niter = 50000;
 
 #ifdef USE_CUDA
 extern void cuda_codelet(void *descr[], __attribute__ ((unused)) void *_args);
 #endif
 
-
 extern void cuda_codelet_host(float *tab);
 
 void core_codelet(void *descr[], __attribute__ ((unused)) void *_args)
@@ -37,6 +36,9 @@ int main(int argc, char **argv)
 {
 	starpu_init(NULL);
 
+	if (argc == 2)
+		niter = atoi(argv[1]);
+
 	float float_array[3] __attribute__ ((aligned (16))) = { 0.0f, 0.0f, 0.0f}; 
 
 	starpu_data_handle float_array_handle;
@@ -54,8 +56,13 @@ int main(int argc, char **argv)
 		.nbuffers = 1
 	};
 
+	struct timeval start;
+	struct timeval end;
+
+	gettimeofday(&start, NULL);
+
 	unsigned i;
-	for (i = 0; i < NITER; i++)
+	for (i = 0; i < niter; i++)
 	{
 		struct starpu_task *task = starpu_task_create();
 
@@ -79,6 +86,8 @@ int main(int argc, char **argv)
 	/* update the array in RAM */
 	starpu_sync_data_with_mem(float_array_handle, STARPU_R);
 	
+	gettimeofday(&end, NULL);
+
 	fprintf(stderr, "array -> %f, %f, %f\n", float_array[0], 
 			float_array[1], float_array[2]);
 	
@@ -87,6 +96,11 @@ int main(int argc, char **argv)
 	
 	starpu_release_data_from_mem(float_array_handle);
 
+	double timing = (double)((end.tv_sec - start.tv_sec)*1000000 +
+					(end.tv_usec - start.tv_usec));
+
+	fprintf(stderr, "%d elems took %lf ms\n", niter, timing/1000);
+
 	starpu_shutdown();
 
 	return 0;

+ 50 - 0
tests/incrementer/speed.sh

@@ -0,0 +1,50 @@
+#!/bin/bash
+
+#
+# StarPU
+# Copyright (C) INRIA 2008-2010 (see AUTHORS file)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# See the GNU Lesser General Public License in COPYING.LGPL for more details.
+#
+
+# We compute the duration of the experiment for multiple powers of 2
+
+i=1
+
+examplebindir=../../examples/incrementer/
+
+rm -f .perftable
+
+max=20
+
+for logi in `seq 0 $max`
+do
+	$examplebindir/incrementer $i 2> .tmpperf
+
+	grep "ms" .tmpperf
+	grep "ms" .tmpperf | sed -e "s/^\(.*\) elems took \(.*\) ms$/\1	\2/" >> .perftable 
+
+	i=$((2 * $i))
+done
+
+gnuplot > /dev/null << EOF
+set term postscript eps enhanced color
+set output "incrementer.eps"
+
+set xlabel "Number of iterations"
+set ylabel "Execution time (ms)"
+
+set logscale x
+set logscale y
+
+plot ".perftable" using 1:2 with linespoint title "Time"
+EOF