Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Now, a process can be killed and all process are killed at the end of the simulation.
[simgrid.git] / src / msg / global.c
index 41ff1b2..1889843 100644 (file)
@@ -22,11 +22,22 @@ MSG_Global_t msg_global = NULL;
  * \brief Initialize some MSG internal data.
  */
 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;
+  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(NULL, NULL);     /* 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();
     msg_global->process_list = xbt_fifo_new();
@@ -41,7 +52,7 @@ void MSG_global_init(void)
  */
 void MSG_set_verbosity(MSG_outputmode_t mode)
 {
-  CRITICAL0("Not implemented yet.");
+  CRITICAL0("MSG_set_verbosity : Not implemented yet.");
 }
 
 /** \ingroup m_channel_management
@@ -56,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;
 
@@ -80,7 +89,7 @@ MSG_error_t MSG_set_channel_number(int number)
  */
 MSG_error_t MSG_set_sharing_policy(MSG_sharing_t mode, long double param)
 {
-  xbt_assert0(0,"This function is now deprecated and useless. Store and forward does not exist anymore. Please stop using it.");
+  CRITICAL0("MSG_set_sharing_policy: this function is now deprecated and useless. Store and forward does not exist anymore. Please stop using it.");
   
   return MSG_OK;
 }
@@ -94,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;
 }
@@ -117,88 +124,67 @@ MSG_error_t MSG_main(void)
   fflush(stderr);
 
   surf_solve(); /* Takes traces into account. Returns 0.0 */
-  while (xbt_fifo_size(msg_global->process_list)) {
+/* xbt_fifo_size(msg_global->process_to_run) */
+  while (1) {
+    xbt_context_empty_trash();
     while ((process = xbt_fifo_pop(msg_global->process_to_run))) {
+/*       fprintf(stderr,"-> %s (%d)\n",process->name, process->simdata->PID); */
       msg_global->current_process = process;
-      xbt_context_yield(process->simdata->context);
+      xbt_context_schedule(process->simdata->context);
       msg_global->current_process = NULL;
     }
     Before = MSG_getClock();
     elapsed_time = surf_solve();
     Now = MSG_getClock();
 
-    if (elapsed_time==0.0)
-      break;
-    
-/*     /\* Handle Failures *\/ */
-/*     { */
-/*       xbt_fifo_t failedHostList = MSG_buildFailedHostList(Before,Now); */
-/*       m_host_t host = NULL; */
-/*       TBX_HashTable_Bucket_t b; */
-/*       TBX_HashTable_t failedProcessList = TBX_HashTable_newList(); */
-      
-/*       while((host=xbt_fifo_pop(failedHostList))) { */
-/*     simdata_host_t h_simdata= host->simdata; */
-/*     TBX_HashTable_t process_list= h_simdata->process; */
-       
-/*     h_simdata->state = HOST_DOWN; */
-       
-/*     for (b=TBX_HashTable_getFirstBucket(process_list);b; */
-/*          b=TBX_HashTable_getNextBucket(process_list,b)) { */
-/*       m_process_t p = b->content; */
-/*       simdata_process_t p_simdata = p->simdata; */
-         
-/*       if(!TBX_HashTable_isInList(failedProcessList,p,TBX_basicHash))  */
-/*         TBX_HashTable_insert(failedProcessList,p,TBX_basicHash); */
-         
-/*       fprintf(stderr,"MSG:  %s(%d) on %s(%d): Has died while ", */
-/*               p->name,p_simdata->PID, */
-/*               p_simdata->host->name,h_simdata->PID); */
-/*       for (i=0; i<msg_global->max_channel; i++) { */
-/*         if (h_simdata->sleeping[i] == p_simdata->context) { */
-/*           fprintf(stderr,"listening on channel %d.\n",i); */
-/*           break; */
-/*         } */
-/*       } */
-/*       if (i==msg_global->max_channel) { */
-/*         if(p_simdata->waiting_task) {              */
-/*           fprintf(stderr,"waiting for %s to finish.\n",p_simdata->waiting_task->name); */
-/*           MarkAsFailed(p_simdata->waiting_task,failedProcessList); */
-/*         } 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,"... WTF! UNKNOWN STATUS. Please report this bug.\n"); */
-/*           } */
-/*         }    */
-/*       }  */
-/*     } */
-/*       } */
-/*       xbt_fifo_freeFIFO(failedHostList); */
-/*       for (b=TBX_HashTable_getFirstBucket(failedProcessList);b; */
-/*        b=TBX_HashTable_getNextBucket(failedProcessList,b)) { */
-/*     m_process_t p = b->content; */
-/*     xbt_fifo_insert(msg_global->process_to_run, p); /\* Brutal... *\/ */
-/*       } */
-/*       TBX_HashTable_freeList(failedProcessList,NULL); */
+/*     fprintf(stderr, "====== %Lg =====\n",Now); */
+/*     if (elapsed_time==0.0) { */
+/*       fprintf(stderr, "No change in time\n"); */
 /*     } */
-
+    if (elapsed_time<0.0) {
+/*       fprintf(stderr, "We're done %lg\n",elapsed_time); */
+      break;
+    }
 
     {
       surf_action_t action = NULL;
       surf_resource_t resource = NULL;
+      m_task_t task = NULL;
       
       xbt_dynar_foreach(resource_list, i, resource) {
        while ((action =
               xbt_swag_extract(resource->common_public->states.
                                failed_action_set))) {
-/*       xbt_fifo_insert(msg_global->process_to_run, process); */
+         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;
+         }
        }
        while ((action =
               xbt_swag_extract(resource->common_public->states.
                                done_action_set))) {
-/*       xbt_fifo_insert(msg_global->process_to_run, process); */
+         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;
+         }
        }
       }
     }
@@ -213,14 +199,21 @@ MSG_error_t MSG_main(void)
     fprintf(stderr,"MSG: %d processes are still running, waiting for something.\n",
            nbprocess);
     /*  List the process and their state */
-    fprintf(stderr,"MSG: <process>(<pid>) on <host>(<pid>): <status>.\n");
+    fprintf(stderr,"MSG: <process>(<pid>) on <host>: <status>.\n");
     while ((process=xbt_fifo_pop(msg_global->process_list))) {
       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);
@@ -228,19 +221,30 @@ MSG_error_t MSG_main(void)
        }
       }
       if (i==msg_global->max_channel) {
-       if(p_simdata->waiting_task) 
-         fprintf(stderr,"Waiting for %s to finish.\n",p_simdata->waiting_task->name);
+       if(p_simdata->waiting_task) {
+         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 */
-         CRITICAL0("Well! I don't know. I have to fix this part of the code. ;)");
-/*       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;
   }
 }
@@ -295,6 +299,13 @@ 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_free(p);
+  }
+  xbt_context_exit();
 
   xbt_fifo_foreach(msg_global->host,i,h,m_host_t) {
     __MSG_host_destroy(h);