Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement stride for parmap_apply.
[simgrid.git] / testsuite / xbt / parmap_bench.c
index 112fbae..1ce420a 100644 (file)
@@ -3,7 +3,8 @@
 #include <xbt/dynar.h>
 #include <xbt/parmap.h>
 #include <xbt/sysdep.h>
-#include <gras_config.h>        /* HAVE_FUTEX_H */
+#include <internal_config.h>        /* HAVE_FUTEX_H */
+#include "simgrid/simix.h"
 #include "xbt/xbt_os_time.h"
 
 #define MODES_DEFAULT 0x7
@@ -30,7 +31,7 @@ static const char *parmap_mode_name(e_xbt_parmap_mode_t mode)
     snprintf(name, sizeof name, "DEFAULT");
     break;
   default:
-    snprintf(name, sizeof name, "UNKNOWN(%d)", mode);
+    snprintf(name, sizeof name, "UNKNOWN(%d)", (int)mode);
     break;
   }
   return name;
@@ -81,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;
@@ -101,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++;
@@ -114,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;
@@ -134,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);
@@ -147,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,
@@ -157,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);
   }
 }
 
@@ -165,12 +166,16 @@ int main(int argc, char *argv[])
 {
   int nthreads;
   unsigned modes = MODES_DEFAULT;
+  unsigned stride = 1;
 
-  if (argc != 2 && argc != 3) {
+  SIMIX_global_init(&argc, argv);
+
+  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;
   }
@@ -179,30 +184,32 @@ int main(int argc, char *argv[])
     fprintf(stderr, "ERROR: invalid thread count: %d\n", nthreads);
     return EXIT_FAILURE;
   }
-  if (argc == 3)
-    modes = atoi(argv[2]);
+  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;