Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : remove unused argument in functions for heap comparison algorithm
[simgrid.git] / src / smpi / smpi_bench.c
index 88c0aa6..2134e47 100644 (file)
@@ -4,6 +4,7 @@
 /* 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 <math.h> // sqrt
 #include "private.h"
 #include "xbt/dict.h"
 #include "xbt/sysdep.h"
@@ -91,7 +92,7 @@ static void* shm_map(int fd, size_t size, shared_data_t* data) {
       xbt_die("Could not truncate fd %d to %zu: %s", fd, size, strerror(errno));
     }
   }
-  mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+  mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
   if(mem == MAP_FAILED) {
     xbt_die("Could not map fd %d: %s", fd, strerror(errno));
   }
@@ -120,15 +121,9 @@ typedef struct {
 
 void smpi_bench_destroy(void)
 {
-  if (allocs) {
-    xbt_dict_free(&allocs);
-  }
-  if (samples) {
-    xbt_dict_free(&samples);
-  }
-  if(calls) {
-    xbt_dict_free(&calls);
-  }
+  xbt_dict_free(&allocs);
+  xbt_dict_free(&samples);
+  xbt_dict_free(&calls);
 }
 
 static void smpi_execute_flops(double flops)
@@ -138,20 +133,24 @@ static void smpi_execute_flops(double flops)
   host = SIMIX_host_self();
 
   XBT_DEBUG("Handle real computation time: %f flops", flops);
-  action = SIMIX_req_host_execute("computation", host, flops, 1);
+  action = simcall_host_execute("computation", host, flops, 1);
 #ifdef HAVE_TRACING
-  SIMIX_req_set_category (action, TRACE_internal_smpi_get_category());
+  simcall_set_category (action, TRACE_internal_smpi_get_category());
 #endif
-  SIMIX_req_host_execution_wait(action);
+  simcall_host_execution_wait(action);
 }
 
 static void smpi_execute(double duration)
 {
+  /* FIXME: a global variable would be less expensive to consult than a call to xbt_cfg_get_double() right on the critical path */
   if (duration >= xbt_cfg_get_double(_surf_cfg_set, "smpi/cpu_threshold")) {
     XBT_DEBUG("Sleep for %f to handle real computation time", duration);
     smpi_execute_flops(duration *
                        xbt_cfg_get_double(_surf_cfg_set,
                                           "smpi/running_power"));
+  } else {
+         XBT_DEBUG("Real computation took %f while threshold is set to %f; ignore it",
+                         duration, xbt_cfg_get_double(_surf_cfg_set, "smpi/cpu_threshold"));
   }
 }
 
@@ -171,21 +170,45 @@ void smpi_bench_end(void)
 
 unsigned int smpi_sleep(unsigned int secs)
 {
+  smpi_bench_end();
   smpi_execute((double) secs);
+  smpi_bench_begin();
   return secs;
 }
 
 int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
-  double now = SIMIX_get_clock();
-
+  double now;
+  smpi_bench_end();
+  now = SIMIX_get_clock();
   if (tv) {
-    tv->tv_sec = (time_t) now;
-    tv->tv_usec = (suseconds_t) (now * 1e6);
+    tv->tv_sec = (time_t)now;
+    tv->tv_usec = (suseconds_t)((now - tv->tv_sec) * 1e6);
   }
+  smpi_bench_begin();
   return 0;
 }
 
+extern double sg_maxmin_precision;
+unsigned long long smpi_rastro_resolution (void)
+{
+  smpi_bench_end();
+  double resolution = (1/sg_maxmin_precision);
+  smpi_bench_begin();
+  return (unsigned long long)resolution;
+}
+
+unsigned long long smpi_rastro_timestamp (void)
+{
+  smpi_bench_end();
+  double now = SIMIX_get_clock();
+
+  unsigned long long sec = (unsigned long long)now;
+  unsigned long long pre = (now - sec) * smpi_rastro_resolution();
+  smpi_bench_begin();
+  return (unsigned long long)sec * smpi_rastro_resolution() + pre;
+}
+
 static char *sample_location(int global, const char *file, int line)
 {
   if (global) {
@@ -202,7 +225,7 @@ int smpi_sample_1(int global, const char *file, int line, int iters, double thre
 
   smpi_bench_end();     /* Take time from previous MPI call into account */
   if (!samples) {
-    samples = xbt_dict_new();
+    samples = xbt_dict_new_homogeneous(free);
   }
   data = xbt_dict_get_or_null(samples, loc);
   if (!data) {
@@ -213,7 +236,7 @@ int smpi_sample_1(int global, const char *file, int line, int iters, double thre
     data->iters = iters;
     data->threshold = threshold;
     data->started = 0;
-    xbt_dict_set(samples, loc, data, &free);
+    xbt_dict_set(samples, loc, data, NULL);
     return 0;
   }
   free(loc);
@@ -291,7 +314,7 @@ void *smpi_shared_malloc(size_t size, const char *file, int line)
     }
   }
   if (!allocs) {
-    allocs = xbt_dict_new();
+    allocs = xbt_dict_new_homogeneous(free);
   }
   data = xbt_dict_get_or_null(allocs, loc);
   if(!data) {
@@ -312,7 +335,7 @@ void *smpi_shared_malloc(size_t size, const char *file, int line)
     if(shm_unlink(loc) < 0) {
       XBT_WARN("Could not early unlink %s: %s", loc, strerror(errno));
     }
-    xbt_dict_set(allocs, loc, data, &free);
+    xbt_dict_set(allocs, loc, data, NULL);
     XBT_DEBUG("Mapping %s at %p through %d", loc, mem, fd);
   } else {
     mem = shm_map(data->fd, size, data);
@@ -363,12 +386,13 @@ int smpi_shared_known_call(const char* func, const char* input) {
    int known;
 
    if(!calls) {
-      calls = xbt_dict_new();
+      calls = xbt_dict_new_homogeneous(NULL);
    }
    TRY {
       xbt_dict_get(calls, loc); /* Succeed or throw */
       known = 1;
-   } CATCH(ex) {
+   }
+   CATCH(ex) {
       if(ex.category == not_found_error) {
          known = 0;
          xbt_ex_free(ex);
@@ -385,7 +409,7 @@ void* smpi_shared_get_call(const char* func, const char* input) {
    void* data;
 
    if(!calls) {
-      calls = xbt_dict_new();
+      calls = xbt_dict_new_homogeneous(NULL);
    }
    data = xbt_dict_get(calls, loc);
    free(loc);
@@ -396,7 +420,7 @@ void* smpi_shared_set_call(const char* func, const char* input, void* data) {
    char* loc = bprintf("%s:%s", func, input);
 
    if(!calls) {
-      calls = xbt_dict_new();
+      calls = xbt_dict_new_homogeneous(NULL);
    }
    xbt_dict_set(calls, loc, data, NULL);
    free(loc);