Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
finish removing simix.h from C files, and avoid the use of Ptr when not needed
[simgrid.git] / teshsuite / xbt / parmap_bench / parmap_bench.c
index de148a0..3944546 100644 (file)
@@ -1,17 +1,16 @@
-/* Copyright (c) 2012-2014. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "simgrid/msg.h"
+#include "src/internal_config.h" /* HAVE_FUTEX_H */
+#include "xbt/xbt_os_time.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <xbt/dynar.h>
 #include <xbt/parmap.h>
 #include <xbt/sysdep.h>
-#include "src/internal_config.h"        /* HAVE_FUTEX_H */
-#include "simgrid/simix.h"
-#include "xbt/xbt_os_time.h"
 
 #define MODES_DEFAULT 0x7
 #define TIMEOUT 10.0
@@ -45,15 +44,13 @@ static const char *parmap_mode_name(e_xbt_parmap_mode_t mode)
 
 static int parmap_skip_mode(e_xbt_parmap_mode_t mode)
 {
-  switch (mode) {
 #if !HAVE_FUTEX_H
-  case XBT_PARMAP_FUTEX:
+  if (mode == XBT_PARMAP_FUTEX) {
     printf("not available\n");
     return 1;
+  } else
 #endif
-  default:
     return 0;
-  }
 }
 
 static unsigned fibonacci(unsigned n)
@@ -78,11 +75,10 @@ static void fun_big_comp(void *arg)
 
 static void array_new(unsigned **a, xbt_dynar_t *data)
 {
-  int i;
   *a = xbt_malloc(ARRAY_SIZE * sizeof **a);
   *data = xbt_dynar_new(sizeof *a, NULL);
   xbt_dynar_shrink(*data, ARRAY_SIZE);
-  for (i = 0 ; i < ARRAY_SIZE ; i++) {
+  for (int i = 0 ; i < ARRAY_SIZE ; i++) {
     (*a)[i] = i;
     xbt_dynar_push_as(*data, void*, &(*a)[i]);
   }
@@ -93,8 +89,7 @@ static void bench_parmap_full(int nthreads, e_xbt_parmap_mode_t mode)
   unsigned *a;
   xbt_dynar_t data;
   xbt_parmap_t parmap;
-  int i;
-  double start_time, elapsed_time;
+  double elapsed_time;
 
   printf("** mode = %-15s ", parmap_mode_name(mode));
   fflush(stdout);
@@ -104,8 +99,8 @@ static void bench_parmap_full(int nthreads, e_xbt_parmap_mode_t mode)
 
   array_new(&a, &data);
 
-  i = 0;
-  start_time = xbt_os_time();
+  int i = 0;
+  double start_time = xbt_os_time();
   do {
     parmap = xbt_parmap_new(nthreads, mode);
     xbt_parmap_apply(parmap, fun_to_apply, data);
@@ -124,7 +119,7 @@ static void bench_parmap_apply(int nthreads, e_xbt_parmap_mode_t mode)
 {
   unsigned *a;
   xbt_dynar_t data;
-  double start_time, elapsed_time;
+  double elapsed_time;
 
   printf("** mode = %-15s ", parmap_mode_name(mode));
   fflush(stdout);
@@ -136,7 +131,7 @@ static void bench_parmap_apply(int nthreads, e_xbt_parmap_mode_t mode)
 
   xbt_parmap_t parmap = xbt_parmap_new(nthreads, mode);
   int i = 0;
-  start_time = xbt_os_time();
+  double start_time = xbt_os_time();
   do {
     xbt_parmap_apply(parmap, fun_to_apply, data);
     elapsed_time = xbt_os_time() - start_time;
@@ -144,8 +139,7 @@ static void bench_parmap_apply(int nthreads, e_xbt_parmap_mode_t mode)
   } while (elapsed_time < TIMEOUT);
   xbt_parmap_destroy(parmap);
 
-  printf("ran %d times in %g seconds (%g/s)\n",
-         i, elapsed_time, i / elapsed_time);
+  printf("ran %d times in %g seconds (%g/s)\n", i, elapsed_time, i / elapsed_time);
 
   xbt_dynar_free(&data);
   xbt_free(a);
@@ -167,7 +161,7 @@ int main(int argc, char *argv[])
   int nthreads;
   unsigned modes = MODES_DEFAULT;
 
-  SIMIX_global_init(&argc, argv);
+  MSG_init(&argc, argv);
 
   if (argc != 2 && argc != 3) {
     fprintf(stderr, "Usage: %s nthreads [modes]\n"
@@ -186,7 +180,7 @@ int main(int argc, char *argv[])
 
   printf("Parmap benchmark with %d workers (modes = %#x)...\n\n", nthreads, modes);
 
-  fun_to_apply = fun_small_comp;
+  fun_to_apply = &fun_small_comp;
 
   printf("Benchmark for parmap create+apply+destroy (small comp):\n");
   bench_all_modes(bench_parmap_full, nthreads, modes);
@@ -196,7 +190,7 @@ int main(int argc, char *argv[])
   bench_all_modes(bench_parmap_apply, nthreads, modes);
   printf("\n");
 
-  fun_to_apply = fun_big_comp;
+  fun_to_apply = &fun_big_comp;
 
   printf("Benchmark for parmap create+apply+destroy (big comp):\n");
   bench_all_modes(bench_parmap_full, nthreads, modes);