1 #include "msg_simix_private.h"
2 #include "xbt/sysdep.h"
4 #include "xbt/ex.h" /* ex_backtrace_display */
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_kernel, msg, "Logging specific to MSG (kernel)");
8 MSG_Global_t msg_global = NULL;
11 /** \defgroup msg_simulation MSG simulation Functions
12 * \brief This section describes the functions you need to know to
13 * set up a simulation. You should have a look at \ref MSG_examples
14 * to have an overview of their usage.
15 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Simulation functions" --> \endhtmlonly
18 /********************************* MSG **************************************/
20 /** \ingroup msg_simulation
21 * \brief Initialize some MSG internal data.
23 void MSG_global_init_args(int *argc, char **argv)
25 MSG_global_init(argc,argv);
28 /** \ingroup msg_simulation
29 * \brief Initialize some MSG internal data.
31 void MSG_global_init(int *argc, char **argv)
34 SIMIX_global_init(argc, argv);
36 msg_global = xbt_new0(s_MSG_Global_t,1);
38 msg_global->host = xbt_fifo_new();
39 msg_global->process_list = xbt_fifo_new();
40 msg_global->max_channel = 0;
47 /** \ingroup msg_easier_life
48 * \brief Traces MSG events in the Paje format.
51 void MSG_paje_output(const char *filename)
55 /** \defgroup m_channel_management Understanding channels
56 * \brief This section briefly describes the channel notion of MSG
58 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Channels" --> \endhtmlonly
61 * For convenience, the simulator provides the notion of channel
62 * that is close to the tag notion in MPI. A channel is not a
63 * socket. It doesn't need to be opened neither closed. It rather
64 * corresponds to the ports opened on the different machines.
68 /** \ingroup m_channel_management
69 * \brief Set the number of channel in the simulation.
71 * This function has to be called to fix the number of channel in the
72 simulation before creating any host. Indeed, each channel is
73 represented by a different mailbox on each #m_host_t. This
74 function can then be called only once. This function takes only one
76 * \param number the number of channel in the simulation. It has to be >0
78 MSG_error_t MSG_set_channel_number(int number)
80 xbt_assert0((msg_global) && (msg_global->max_channel == 0), "Channel number already set!");
82 msg_global->max_channel = number;
87 /** \ingroup m_channel_management
88 * \brief Return the number of channel in the simulation.
90 * This function has to be called once the number of channel is fixed. I can't
91 figure out a reason why anyone would like to call this function but nevermind.
92 * \return the number of channel in the simulation.
94 int MSG_get_channel_number(void)
96 xbt_assert0((msg_global)&&(msg_global->max_channel != 0), "Channel number not set yet!");
98 return msg_global->max_channel;
101 void __MSG_display_process_status(void)
106 /* FIXME: Yeah, I'll do it in a portable maner one day [Mt] */
109 static void _XBT_CALL inthandler(int ignored)
111 INFO0("CTRL-C pressed. Displaying status and bailing out");
112 __MSG_display_process_status();
116 /** \ingroup msg_simulation
117 * \brief Launch the MSG simulation
119 MSG_error_t MSG_main(void)
121 smx_cond_t cond = NULL;
122 smx_action_t smx_action;
123 xbt_fifo_t actions_done = xbt_fifo_new();
124 xbt_fifo_t actions_failed = xbt_fifo_new();
126 /* Prepare to display some more info when dying on Ctrl-C pressing */
127 signal(SIGINT,inthandler);
129 /* Clean IO before the run */
133 //surf_solve(); /* Takes traces into account. Returns 0.0 */
134 /* xbt_fifo_size(msg_global->process_to_run) */
136 while (SIMIX_solve(actions_done, actions_failed) != -1.0) {
138 while ( (smx_action = xbt_fifo_pop(actions_failed)) ) {
141 DEBUG1("** %s failed **",smx_action->name);
142 while ( (cond = xbt_fifo_pop(smx_action->cond_list)) ) {
143 SIMIX_cond_broadcast(cond);
145 /* action finished, destroy it */
146 // SIMIX_action_destroy(smx_action);
149 while ( (smx_action = xbt_fifo_pop(actions_done)) ) {
151 DEBUG1("** %s done **",smx_action->name);
152 while ( (cond = xbt_fifo_pop(smx_action->cond_list)) ) {
153 SIMIX_cond_broadcast(cond);
155 /* action finished, destroy it */
156 //SIMIX_action_destroy(smx_action);
159 xbt_fifo_free(actions_failed);
160 xbt_fifo_free(actions_done);
164 /** \ingroup msg_simulation
165 * \brief Kill all running process
167 * \param reset_PIDs should we reset the PID numbers. A negative
168 * number means no reset and a positive number will be used to set the PID
169 * of the next newly created process.
171 int MSG_process_killall(int reset_PIDs)
173 m_process_t p = NULL;
174 m_process_t self = MSG_process_self();
176 while((p=xbt_fifo_pop(msg_global->process_list))) {
177 if(p!=self) MSG_process_kill(p);
181 msg_global->PID = reset_PIDs;
182 msg_global->session++;
185 return msg_global->PID;
189 /** \ingroup msg_simulation
190 * \brief Clean the MSG simulation
192 MSG_error_t MSG_clean(void)
194 xbt_fifo_item_t i = NULL;
196 m_process_t p = NULL;
199 while((p=xbt_fifo_pop(msg_global->process_list))) {
203 xbt_fifo_foreach(msg_global->host,i,h,m_host_t) {
204 __MSG_host_destroy(h);
206 xbt_fifo_free(msg_global->host);
207 xbt_fifo_free(msg_global->process_list);
216 /** \ingroup msg_easier_life
217 * \brief A clock (in second).
219 double MSG_get_clock(void)
221 return SIMIX_get_clock();