Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
minor modifications
[simgrid.git] / src / msg / global.c
index 54e39b9..9160e07 100644 (file)
@@ -32,7 +32,7 @@ void MSG_global_init(void)
   int argc=0;
   char **argv=NULL;
 
   int argc=0;
   char **argv=NULL;
 
-  CRITICAL0("Please stop using this function. Use MSG_global_init_args instead.");
+  CRITICAL0("Function MSG_global_init() is deprecated by MSG_global_init_args().");
   MSG_global_init_args(&argc,argv);
 }
 
   MSG_global_init_args(&argc,argv);
 }
 
@@ -42,9 +42,10 @@ void MSG_global_init(void)
 void MSG_global_init_args(int *argc, char **argv)
 {
   if (!msg_global) {
 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);
 
     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();
     xbt_context_init();
     msg_global->host = xbt_fifo_new();
     msg_global->process_to_run = xbt_fifo_new();
@@ -196,9 +197,12 @@ void MSG_paje_output(const char *filename)
   const char *ext = ".trace";
   int ext_len = strlen(ext);
   int len;
   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, "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);
   xbt_assert0(filename, "Need a real file name\n");
 
   len = strlen(filename);
@@ -207,19 +211,28 @@ void MSG_paje_output(const char *filename)
              filename,ext);
   }
 
              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);
   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");
 
   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
 }
 
 /** \ingroup msg_simulation
@@ -227,7 +240,7 @@ void MSG_paje_output(const char *filename)
  */
 void MSG_set_verbosity(MSG_outputmode_t mode)
 {
  */
 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
 }
 
 /** \defgroup m_channel_management    Understanding channels
@@ -317,6 +330,7 @@ MSG_error_t MSG_main(void)
             process->name,process->simdata->PID,
             process->simdata->host->name);
       msg_global->current_process = process;
             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;
     }
       xbt_context_schedule(process->simdata->context);
       msg_global->current_process = NULL;
     }
@@ -491,16 +505,23 @@ int MSG_process_killall(int reset_PIDs)
 {
   xbt_fifo_item_t i = NULL;
   m_process_t p = NULL;
 {
   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))) {
 
   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++;
  }
 
   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;
 }
 
   return msg_global->PID;
 }
 
@@ -531,7 +552,7 @@ MSG_error_t MSG_clean(void)
     fclose(msg_global->paje_output);
     msg_global->paje_output = NULL;
   }
     fclose(msg_global->paje_output);
     msg_global->paje_output = NULL;
   }
-  xbt_free(msg_global);
+  free(msg_global);
   surf_finalize();
 
   return MSG_OK;
   surf_finalize();
 
   return MSG_OK;
@@ -540,8 +561,16 @@ MSG_error_t MSG_clean(void)
 
 /** \ingroup msg_easier_life
  * \brief A clock (in second).
 
 /** \ingroup msg_easier_life
  * \brief A clock (in second).
+ * \deprecated Use MSG_get_clock
  */
 double MSG_getClock(void) {
   return surf_get_clock();
 }
 
  */
 double MSG_getClock(void) {
   return surf_get_clock();
 }
 
+/** \ingroup msg_easier_life
+ * \brief A clock (in second).
+ */
+double MSG_get_clock(void) {
+  return surf_get_clock();
+}
+