Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Updating the documentation
[simgrid.git] / src / msg / global.c
index 19b502f..c29633b 100644 (file)
@@ -23,13 +23,20 @@ MSG_Global_t msg_global = NULL;
  */
 void MSG_global_init(void)
 {
-  if (!msg_global) {
-    int argc=0;
-    char **argv=NULL;
+  int argc=0;
+  char **argv=NULL;
+
+  CRITICAL0("Please stop using this function. Use MSG_global_init_args instead.");
+  DIE_IMPOSSIBLE;
+  MSG_global_init_args(&argc,argv);
+}
 
+void MSG_global_init_args(int *argc, char **argv)
+{
+  if (!msg_global) {
     msg_global = xbt_new0(s_MSG_Global_t,1);
 
-    surf_init(&argc, argv);    /* Initialize some common structures */
+    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();
@@ -60,9 +67,7 @@ void MSG_set_verbosity(MSG_outputmode_t mode)
  */
 MSG_error_t MSG_set_channel_number(int number)
 {
-  MSG_global_init();
-
-  xbt_assert0((msg_global->max_channel == 0), "Channel number already set!");
+  xbt_assert0((msg_global) && (msg_global->max_channel == 0), "Channel number already set!");
 
   msg_global->max_channel = number;
 
@@ -98,9 +103,7 @@ MSG_error_t MSG_set_sharing_policy(MSG_sharing_t mode, long double param)
  */
 int MSG_get_channel_number(void)
 {
-  MSG_global_init();
-
-  xbt_assert0((msg_global->max_channel != 0), "Channel number not set yet!");
+  xbt_assert0((msg_global)&&(msg_global->max_channel != 0), "Channel number not set yet!");
 
   return msg_global->max_channel;
 }
@@ -139,6 +142,7 @@ MSG_error_t MSG_main(void)
 /*       fprintf(stderr, "No change in time\n"); */
 /*     } */
     if (elapsed_time<0.0) {
+/*       fprintf(stderr, "We're done %lg\n",elapsed_time); */
       break;
     }
 
@@ -154,8 +158,12 @@ MSG_error_t MSG_main(void)
          task = action->data;
          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,
+                    process->simdata->host->name);
              xbt_fifo_unshift(msg_global->process_to_run, process);
            }
            process=NULL;
@@ -167,8 +175,12 @@ MSG_error_t MSG_main(void)
          task = action->data;
          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,
+                    process->simdata->host->name);
              xbt_fifo_unshift(msg_global->process_to_run, process);
            }
            process=NULL;
@@ -192,9 +204,16 @@ MSG_error_t MSG_main(void)
       simdata_process_t p_simdata = (simdata_process_t) process->simdata;
       simdata_host_t h_simdata=(simdata_host_t)p_simdata->host->simdata;
       
+
       fprintf(stderr,"MSG:  %s(%d) on %s: ",
             process->name,p_simdata->PID,
             p_simdata->host->name);
+
+      if (process->simdata->blocked)     
+       fprintf(stderr,"[blocked] ");
+      if (process->simdata->suspended)           
+       fprintf(stderr,"[suspended] ");
+
       for (i=0; i<msg_global->max_channel; i++) {
        if (h_simdata->sleeping[i] == process) {
          fprintf(stderr,"Listening on channel %d.\n",i);
@@ -203,24 +222,29 @@ MSG_error_t MSG_main(void)
       }
       if (i==msg_global->max_channel) {
        if(p_simdata->waiting_task) {
-         if(p_simdata->waiting_task->simdata->compute)
-           fprintf(stderr,"Waiting for %s to finish.\n",p_simdata->waiting_task->name);
-         else if (p_simdata->waiting_task->simdata->comm)
+         if(p_simdata->waiting_task->simdata->compute) {
+           if(p_simdata->put_host) 
+             fprintf(stderr,"Trying to send a task on Host %s, channel %d.\n",
+                     p_simdata->put_host->name, p_simdata->put_channel);
+           else 
+             fprintf(stderr,"Waiting for %s to finish.\n",p_simdata->waiting_task->name);
+         } else if (p_simdata->waiting_task->simdata->comm)
            fprintf(stderr,"Waiting for %s to be finished transfered.\n",
                    p_simdata->waiting_task->name);
          else
            fprintf(stderr,"UNKNOWN STATUS. Please report this bug.\n");
        }
        else { /* Must be trying to put a task somewhere */
-         if(p_simdata->put_host) {
-           fprintf(stderr,"Trying to send a task on Host %s, channel %d.\n",
-                   p_simdata->put_host->name, p_simdata->put_channel);
-         } else {
-           fprintf(stderr,"UNKNOWN STATUS. Please report this bug.\n");
-         }
-       }       
+         fprintf(stderr,"UNKNOWN STATUS. Please report this bug.\n");
+       }
       } 
     }
+    if(XBT_LOG_ISENABLED(msg, xbt_log_priority_debug) ||
+       XBT_LOG_ISENABLED(global, xbt_log_priority_debug)) {
+      DEBUG0("Aborting!");
+      xbt_abort();
+    }
+
     return MSG_WARNING;
   }
 }
@@ -275,7 +299,12 @@ MSG_error_t MSG_clean(void)
 {
   xbt_fifo_item_t i = NULL;
   m_host_t h = NULL;
+  m_process_t p = NULL;
 
+
+  while((p=xbt_fifo_shift(msg_global->process_list))) {
+    MSG_process_kill(p);
+  }
   xbt_context_exit();
 
   xbt_fifo_foreach(msg_global->host,i,h,m_host_t) {