Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tell the world that MSG_set_verbosity is deprecated.
[simgrid.git] / src / msg / global.c
index 5db4445..a85b6c5 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(global, msg,
                                "Logging specific to MSG (global)");
 
+int __stop_at_time = -1.0 ;
+
 MSG_Global_t msg_global = NULL;
 
 /* static void MarkAsFailed(m_task_t t, TBX_HashTable_t failedProcessList); */
-/* static xbt_fifo_t MSG_buildFailedHostList(long double a, long double b); */
+/* static xbt_fifo_t MSG_buildFailedHostList(double a, double b); */
 
 /** \defgroup msg_simulation   MSG simulation Functions
  *  \brief This section describes the functions you need to know to
@@ -32,8 +34,7 @@ void MSG_global_init(void)
   int argc=0;
   char **argv=NULL;
 
-  CRITICAL0("Please stop using this function. Use MSG_global_init_args instead.");
-  DIE_IMPOSSIBLE;
+  CRITICAL0("Function MSG_global_init() is deprecated by MSG_global_init_args().");
   MSG_global_init_args(&argc,argv);
 }
 
@@ -43,9 +44,10 @@ void MSG_global_init(void)
 void MSG_global_init_args(int *argc, char **argv)
 {
   if (!msg_global) {
+    surf_init(argc, argv);     /* Initialize some common structures. Warning, it sets msg_global=NULL */
+     
     msg_global = xbt_new0(s_MSG_Global_t,1);
 
-    surf_init(argc, argv);     /* Initialize some common structures */
     xbt_context_init();
     msg_global->host = xbt_fifo_new();
     msg_global->process_to_run = xbt_fifo_new();
@@ -197,9 +199,12 @@ void MSG_paje_output(const char *filename)
   const char *ext = ".trace";
   int ext_len = strlen(ext);
   int len;
+  m_host_t host;
+  m_process_t process;
+  xbt_fifo_item_t item = NULL;
 
   xbt_assert0(msg_global, "Initialize MSG first\n");
-  xbt_assert0(!msg_global->paje_output, "Paje output allready defined\n");
+  xbt_assert0(!msg_global->paje_output, "Paje output already defined\n");
   xbt_assert0(filename, "Need a real file name\n");
 
   len = strlen(filename);
@@ -208,27 +213,36 @@ void MSG_paje_output(const char *filename)
              filename,ext);
   }
 
-  xbt_assert0(filename, "Need a real file name\n");
-
   msg_global->paje_output=fopen(filename,"w");
   xbt_assert1(msg_global->paje_output, "Failed to open %s \n",filename);
 
   fprintf(msg_global->paje_output,"%s",paje_preembule);
   fprintf(msg_global->paje_output,"%s",type_definitions);
+
+  /*    Channels    */
   for(i=0; i<msg_global->max_channel; i++) {
     fprintf(msg_global->paje_output, "6        COMM_%d Comm    \"Channel %d\"\n" ,i,i);
   }
   fprintf(msg_global->paje_output,
          "7    0.0     CUR     Sim_t   0       \"MSG simulation\"\n");
 
+  /*    Hosts       */
+  xbt_fifo_foreach(msg_global->host,item,host,m_host_t) {
+    PAJE_HOST_NEW(host);
+  }
+
+  /*    Process       */
+  xbt_fifo_foreach(msg_global->process_list,item,process,m_process_t) {
+    PAJE_PROCESS_NEW(process);
+  }
 }
 
-/** \ingroup msg_simulation
- * \brief Defines the verbosity of the simulation.
+/** @deprecated Defines the verbosity of the simulation.
+ *  @ingroup msg_simulation
  */
 void MSG_set_verbosity(MSG_outputmode_t mode)
 {
-  CRITICAL0("MSG_set_verbosity : Not implemented yet.");
+  CRITICAL0("MSG_set_verbosity : Deprecated function. Use the XBT logging interface.");
 }
 
 /** \defgroup m_channel_management    Understanding channels
@@ -274,7 +288,7 @@ MSG_error_t MSG_set_channel_number(int number)
    currently used only for the MSG_STORE_AND_FORWARD flavor and represents the
    granularity of the communications (i.e. the packet size).
  */
-MSG_error_t MSG_set_sharing_policy(MSG_sharing_t mode, long double param)
+MSG_error_t MSG_set_sharing_policy(MSG_sharing_t mode, double param)
 {
   CRITICAL0("MSG_set_sharing_policy: this function is now deprecated and useless. Store and forward does not exist anymore. Please stop using it.");
   
@@ -312,20 +326,27 @@ MSG_error_t MSG_main(void)
 /* xbt_fifo_size(msg_global->process_to_run) */
   while (1) {
     xbt_context_empty_trash();
+    if(xbt_fifo_size(msg_global->process_to_run) && (elapsed_time>0)) {
+      DEBUG0("**************************************************");
+    }
+    if((__stop_at_time>0) && (MSG_getClock() >= __stop_at_time)) {
+      DEBUG0("Let's stop here!");
+    }
+
     while ((process = xbt_fifo_pop(msg_global->process_to_run))) {
-/*       fprintf(stderr,"-> %s (%d)\n",process->name, process->simdata->PID); */
       DEBUG3("Scheduling  %s(%d) on %s",            
             process->name,process->simdata->PID,
             process->simdata->host->name);
       msg_global->current_process = process;
+/*       fflush(NULL); */
       xbt_context_schedule(process->simdata->context);
       msg_global->current_process = NULL;
     }
-    DEBUG1("%Lg : Calling surf_solve",MSG_getClock());
+    DEBUG1("%lg : Calling surf_solve",MSG_getClock());
     elapsed_time = surf_solve();
     DEBUG1("Elapsed_time %lg",elapsed_time);
 
-/*     fprintf(stderr, "====== %Lg =====\n",Now); */
+/*     fprintf(stderr, "====== %lg =====\n",Now); */
 /*     if (elapsed_time==0.0) { */
 /*       fprintf(stderr, "No change in time\n"); */
 /*     } */
@@ -338,6 +359,31 @@ MSG_error_t MSG_main(void)
       surf_action_t action = NULL;
       surf_resource_t resource = NULL;
       m_task_t task = NULL;
+
+      void *fun = NULL;
+      void *arg = NULL;
+      while (surf_timer_resource->extension_public->get(&fun,(void*)&arg)) {
+       DEBUG2("got %p %p", fun, arg);
+       if(fun==MSG_process_create_with_arguments) {
+         process_arg_t args = arg;
+         DEBUG2("Launching %s on %s", args->name, args->host->name);
+         process = MSG_process_create_with_arguments(args->name, args->code, 
+                                                     args->data, args->host,
+                                                     args->argc,args->argv);
+         if(args->kill_time > MSG_getClock()) {
+           surf_timer_resource->extension_public->set(args->kill_time, 
+                                                      (void*) &MSG_process_kill,
+                                                      (void*) process);
+         }
+         xbt_free(args);
+       }
+       if(fun==MSG_process_kill) {
+         process = arg;
+         DEBUG3("Killing %s(%d) on %s", process->name, process->simdata->PID, 
+                process->simdata->host->name);
+         MSG_process_kill(process);
+       }
+      }
       
       xbt_dynar_foreach(resource_list, i, resource) {
        while ((action =
@@ -347,7 +393,6 @@ MSG_error_t MSG_main(void)
          if(task) {
            int _cursor;
            DEBUG1("** %s failed **",task->name);
-/*         fprintf(stderr,"** %s **\n",task->name); */
            xbt_dynar_foreach(task->simdata->sleeping,_cursor,process) {
              DEBUG3("\t preparing to wake up %s(%d) on %s",         
                     process->name,process->simdata->PID,
@@ -364,7 +409,6 @@ MSG_error_t MSG_main(void)
          if(task) {
            int _cursor;
            DEBUG1("** %s done **",task->name);
-/*         fprintf(stderr,"** %s **\n",task->name); */
            xbt_dynar_foreach(task->simdata->sleeping,_cursor,process) {
              DEBUG3("\t preparing to wake up %s(%d) on %s",         
                     process->name,process->simdata->PID,
@@ -465,7 +509,7 @@ MSG_error_t MSG_main(void)
   
 /* } */
 
-/* static xbt_fifo_t MSG_buildFailedHostList(long double begin, long double end) */
+/* static xbt_fifo_t MSG_buildFailedHostList(double begin, double end) */
 /* { */
 /*   xbt_fifo_t failedHostList = xbt_fifo_new(); */
 /*   m_host_t host = NULL; */
@@ -492,16 +536,23 @@ int MSG_process_killall(int reset_PIDs)
 {
   xbt_fifo_item_t i = NULL;
   m_process_t p = NULL;
+  m_process_t self = MSG_process_self();
 
   while((p=xbt_fifo_shift(msg_global->process_list))) {
-    MSG_process_kill(p);
+    if(p!=self) MSG_process_kill(p);
   }
-  xbt_context_empty_trash();
+
   if(reset_PIDs>0) {
     msg_global->PID = reset_PIDs; 
     msg_global->session++;
  }
 
+  xbt_context_empty_trash();
+
+  if(self) {
+    xbt_context_yield();
+  }
+
   return msg_global->PID;
 }
 
@@ -532,17 +583,25 @@ MSG_error_t MSG_clean(void)
     fclose(msg_global->paje_output);
     msg_global->paje_output = NULL;
   }
-  xbt_free(msg_global);
+  free(msg_global);
   surf_finalize();
 
   return MSG_OK;
 }
 
 
+/** \ingroup msg_easier_life
+ * \brief A clock (in second).
+ * \deprecated Use MSG_get_clock
+ */
+double MSG_getClock(void) {
+  return surf_get_clock();
+}
+
 /** \ingroup msg_easier_life
  * \brief A clock (in second).
  */
-long double MSG_getClock(void) {
+double MSG_get_clock(void) {
   return surf_get_clock();
 }