Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement stride for parmap_apply.
[simgrid.git] / testsuite / xbt / parmap_bench.c
index e95d77d..1ce420a 100644 (file)
@@ -82,7 +82,7 @@ static void array_new(unsigned **a, xbt_dynar_t *data)
   }
 }
 
-static void bench_parmap_full(int nthreads, e_xbt_parmap_mode_t mode)
+static void bench_parmap_full(int nthreads, e_xbt_parmap_mode_t mode, unsigned stride)
 {
   unsigned *a;
   xbt_dynar_t data;
@@ -102,7 +102,7 @@ static void bench_parmap_full(int nthreads, e_xbt_parmap_mode_t mode)
   start_time = xbt_os_time();
   do {
     parmap = xbt_parmap_new(nthreads, mode);
-    xbt_parmap_apply(parmap, fun_to_apply, data);
+    xbt_parmap_apply(parmap, fun_to_apply, data, stride, 0);
     xbt_parmap_destroy(parmap);
     elapsed_time = xbt_os_time() - start_time;
     i++;
@@ -115,7 +115,7 @@ static void bench_parmap_full(int nthreads, e_xbt_parmap_mode_t mode)
   xbt_free(a);
 }
 
-static void bench_parmap_apply(int nthreads, e_xbt_parmap_mode_t mode)
+static void bench_parmap_apply(int nthreads, e_xbt_parmap_mode_t mode, unsigned stride)
 {
   unsigned *a;
   xbt_dynar_t data;
@@ -135,7 +135,7 @@ static void bench_parmap_apply(int nthreads, e_xbt_parmap_mode_t mode)
   i = 0;
   start_time = xbt_os_time();
   do {
-    xbt_parmap_apply(parmap, fun_to_apply, data);
+    xbt_parmap_apply(parmap, fun_to_apply, data, stride, 0);
     elapsed_time = xbt_os_time() - start_time;
     i++;
   } while (elapsed_time < TIMEOUT);
@@ -148,8 +148,8 @@ static void bench_parmap_apply(int nthreads, e_xbt_parmap_mode_t mode)
   xbt_free(a);
 }
 
-static void bench_all_modes(void (*bench_fun)(int, e_xbt_parmap_mode_t),
-                            int nthreads, unsigned modes)
+static void bench_all_modes(void (*bench_fun)(int, e_xbt_parmap_mode_t, unsigned),
+                            int nthreads, unsigned modes, unsigned stride)
 {
   e_xbt_parmap_mode_t all_modes[] = {
     XBT_PARMAP_POSIX, XBT_PARMAP_FUTEX,
@@ -158,7 +158,7 @@ static void bench_all_modes(void (*bench_fun)(int, e_xbt_parmap_mode_t),
   unsigned i;
   for (i = 0 ; i < sizeof all_modes / sizeof all_modes[0] ; i++) {
     if (1U << i & modes)
-      bench_fun(nthreads, all_modes[i]);
+      bench_fun(nthreads, all_modes[i], stride);
   }
 }
 
@@ -166,14 +166,16 @@ int main(int argc, char *argv[])
 {
   int nthreads;
   unsigned modes = MODES_DEFAULT;
+  unsigned stride = 1;
 
   SIMIX_global_init(&argc, argv);
 
-  if (argc != 2 && argc != 3) {
+  if (argc < 2 || argc > 4) {
     fprintf(stderr,
-            "Usage: %s nthreads [modes]\n"
+            "Usage: %s nthreads [modes [stride]]\n"
             "    nthreads - number of working threads\n"
-            "    modes    - bitmask of modes to test\n",
+            "    modes    - bitmask of modes to test\n"
+            "    stride   - parmap stride\n",
             argv[0]);
     return EXIT_FAILURE;
   }
@@ -182,30 +184,32 @@ int main(int argc, char *argv[])
     fprintf(stderr, "ERROR: invalid thread count: %d\n", nthreads);
     return EXIT_FAILURE;
   }
-  if (argc == 3)
+  if (argc >= 3)
     modes = strtol(argv[2], NULL, 0);
+  if (argc >= 4)
+    stride = atoi(argv[3]);
 
-  printf("Parmap benchmark with %d workers (modes = %#x)...\n\n",
-         nthreads, modes);
+  printf("Parmap benchmark with %d workers (modes = %#x; stride = %d)...\n\n",
+         nthreads, modes, stride);
 
   fun_to_apply = fun_small_comp;
 
   printf("Benchmark for parmap create+apply+destroy (small comp):\n");
-  bench_all_modes(bench_parmap_full, nthreads, modes);
+  bench_all_modes(bench_parmap_full, nthreads, modes, stride);
   printf("\n");
 
   printf("Benchmark for parmap apply only (small comp):\n");
-  bench_all_modes(bench_parmap_apply, nthreads, modes);
+  bench_all_modes(bench_parmap_apply, nthreads, modes, stride);
   printf("\n");
 
   fun_to_apply = fun_big_comp;
 
   printf("Benchmark for parmap create+apply+destroy (big comp):\n");
-  bench_all_modes(bench_parmap_full, nthreads, modes);
+  bench_all_modes(bench_parmap_full, nthreads, modes, stride);
   printf("\n");
 
   printf("Benchmark for parmap apply only (big comp):\n");
-  bench_all_modes(bench_parmap_apply, nthreads, modes);
+  bench_all_modes(bench_parmap_apply, nthreads, modes, stride);
   printf("\n");
 
   return EXIT_SUCCESS;