Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Protect the use of parmap.
[simgrid.git] / src / simix / smx_context_raw.c
index e829551..af7c4ce 100644 (file)
@@ -159,12 +159,20 @@ static xbt_parmap_t parmap;
 
 static smx_context_factory_t raw_factory;
 
+#include "xbt/xbt_os_time.h"
+static xbt_os_timer_t timer;
+static double totaltime = 0;
+
+
 static void smx_ctx_raw_wrapper(smx_ctx_raw_t context);
 
 static int smx_ctx_raw_factory_finalize(smx_context_factory_t *factory)
 { 
+  XBT_VERB("Total User Time: %lf", totaltime);
+#ifdef CONTEXT_THREADS
   if(parmap)
       xbt_parmap_destroy(parmap);
+#endif
   return smx_ctx_base_factory_finalize(factory);
 }
 
@@ -250,22 +258,26 @@ static void smx_ctx_raw_resume(smx_process_t process)
       ((smx_ctx_raw_t) context)->stack_top);
 }
 
-
 static void smx_ctx_raw_runall_serial(xbt_dynar_t processes)
 {
   smx_process_t process;
   unsigned int cursor;
 
   xbt_dynar_foreach(processes, cursor, process) {
-    DEBUG2("Schedule item %u of %lu",cursor,xbt_dynar_length(processes));
+    XBT_DEBUG("Schedule item %u of %lu",cursor,xbt_dynar_length(processes));
+    xbt_os_timer_start(timer);
     smx_ctx_raw_resume(process);
+    xbt_os_timer_stop(timer);
+    totaltime += xbt_os_timer_elapsed(timer);
   }
   xbt_dynar_reset(processes);
 }
 
 static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
 {
+#ifdef CONTEXT_THREADS
   xbt_parmap_apply(parmap, (void_f_pvoid_t)smx_ctx_raw_resume, processes);
+#endif
   xbt_dynar_reset(processes);
 }
 
@@ -281,12 +293,12 @@ static int smx_ctx_raw_get_thread_id(){
 static void smx_ctx_raw_runall(xbt_dynar_t processes)
 {
   if (xbt_dynar_length(processes) >= SIMIX_context_get_parallel_threshold()) {
-    DEBUG1("Runall // %lu", xbt_dynar_length(processes));
+    XBT_DEBUG("Runall // %lu", xbt_dynar_length(processes));
     raw_factory->self = smx_ctx_raw_self_parallel;
     raw_factory->get_thread_id = smx_ctx_raw_get_thread_id;
     smx_ctx_raw_runall_parallel(processes);
   } else {
-    DEBUG1("Runall serial %lu", xbt_dynar_length(processes));
+    XBT_DEBUG("Runall serial %lu", xbt_dynar_length(processes));
     raw_factory->self = smx_ctx_base_self;
     raw_factory->get_thread_id = smx_ctx_base_get_thread_id;
     smx_ctx_raw_runall_serial(processes);
@@ -295,7 +307,7 @@ static void smx_ctx_raw_runall(xbt_dynar_t processes)
 
 void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory)
 {
-  VERB0("Using raw contexts. Because the glibc is just not good enough for us.");
+  XBT_VERB("Using raw contexts. Because the glibc is just not good enough for us.");
   smx_ctx_base_factory_init(factory);
 
   (*factory)->finalize  = smx_ctx_raw_factory_finalize;
@@ -305,9 +317,9 @@ void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory)
   (*factory)->stop = smx_ctx_raw_stop;
   (*factory)->suspend = smx_ctx_raw_suspend;
   (*factory)->name = "smx_raw_context_factory";
-
+#ifdef CONTEXT_THREADS
   parmap = xbt_parmap_new(2);
-
+#endif
   if (SIMIX_context_is_parallel()) {
     if (SIMIX_context_get_parallel_threshold() > 1) {
       /* choose dynamically */
@@ -326,6 +338,7 @@ void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory)
     (*factory)->get_thread_id = smx_ctx_base_get_thread_id;
     (*factory)->runall = smx_ctx_raw_runall_serial;
   }
-
   raw_factory = *factory;
+
+  timer = xbt_os_timer_new();
 }