Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Let's start with the library versionning
[simgrid.git] / src / msg_simix / gos.c
1 #include "private.h"
2 #include "xbt/sysdep.h"
3 #include "xbt/log.h"
4
5 /** \defgroup msg_gos_functions MSG Operating System Functions
6  *  \brief This section describes the functions that can be used
7  *  by an agent for handling some task.
8  */
9
10 static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task,
11                                                         m_channel_t channel,
12                                                         double max_duration,
13                                                         m_host_t host)
14 {
15
16         MSG_RETURN(MSG_OK);
17 }
18
19 /** \ingroup msg_gos_functions
20  * \brief Listen on a channel and wait for receiving a task.
21  *
22  * It takes two parameters.
23  * \param task a memory location for storing a #m_task_t. It will
24    hold a task when this function will return. Thus \a task should not
25    be equal to \c NULL and \a *task should be equal to \c NULL. If one of
26    those two condition does not hold, there will be a warning message.
27  * \param channel the channel on which the agent should be
28    listening. This value has to be >=0 and < than the maximal
29    number of channels fixed with MSG_set_channel_number().
30  * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
31  * if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
32  */
33 MSG_error_t MSG_task_get(m_task_t * task,
34                          m_channel_t channel)
35 {
36   return MSG_task_get_with_time_out(task, channel, -1);
37 }
38
39 /** \ingroup msg_gos_functions
40  * \brief Listen on a channel and wait for receiving a task with a timeout.
41  *
42  * It takes three parameters.
43  * \param task a memory location for storing a #m_task_t. It will
44    hold a task when this function will return. Thus \a task should not
45    be equal to \c NULL and \a *task should be equal to \c NULL. If one of
46    those two condition does not hold, there will be a warning message.
47  * \param channel the channel on which the agent should be
48    listening. This value has to be >=0 and < than the maximal
49    number of channels fixed with MSG_set_channel_number().
50  * \param max_duration the maximum time to wait for a task before giving
51     up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task 
52     will not be modified and will still be
53     equal to \c NULL when returning. 
54  * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
55    if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
56  */
57 MSG_error_t MSG_task_get_with_time_out(m_task_t * task,
58                                        m_channel_t channel,
59                                        double max_duration)
60 {
61   return __MSG_task_get_with_time_out_from_host(task, channel, max_duration, NULL);
62 }
63
64 /** \ingroup msg_gos_functions
65  * \brief Listen on \a channel and waits for receiving a task from \a host.
66  *
67  * It takes three parameters.
68  * \param task a memory location for storing a #m_task_t. It will
69    hold a task when this function will return. Thus \a task should not
70    be equal to \c NULL and \a *task should be equal to \c NULL. If one of
71    those two condition does not hold, there will be a warning message.
72  * \param channel the channel on which the agent should be
73    listening. This value has to be >=0 and < than the maximal
74    number of channels fixed with MSG_set_channel_number().
75  * \param host the host that is to be watched.
76  * \return #MSG_FATAL if \a task is equal to \c NULL, #MSG_WARNING
77    if \a *task is not equal to \c NULL, and #MSG_OK otherwise.
78  */
79 MSG_error_t MSG_task_get_from_host(m_task_t * task, int channel, 
80                                    m_host_t host)
81 {
82   return __MSG_task_get_with_time_out_from_host(task, channel, -1, host);
83 }
84
85 /** \ingroup msg_gos_functions
86  * \brief Test whether there is a pending communication on a channel.
87  *
88  * It takes one parameter.
89  * \param channel the channel on which the agent should be
90    listening. This value has to be >=0 and < than the maximal
91    number of channels fixed with MSG_set_channel_number().
92  * \return 1 if there is a pending communication and 0 otherwise
93  */
94 int MSG_task_Iprobe(m_channel_t channel)
95 {
96         return 0;
97 }
98
99 /** \ingroup msg_gos_functions
100  * \brief Test whether there is a pending communication on a channel, and who sent it.
101  *
102  * It takes one parameter.
103  * \param channel the channel on which the agent should be
104    listening. This value has to be >=0 and < than the maximal
105    number of channels fixed with MSG_set_channel_number().
106  * \return -1 if there is no pending communication and the PID of the process who sent it otherwise
107  */
108 int MSG_task_probe_from(m_channel_t channel)
109 {
110         return 0;
111 }
112
113 /** \ingroup msg_gos_functions
114  * \brief Wait for at most \a max_duration second for a task reception
115    on \a channel. *\a PID is updated with the PID of the first process
116    that triggered this event if any.
117  *
118  * It takes three parameters:
119  * \param channel the channel on which the agent should be
120    listening. This value has to be >=0 and < than the maximal.
121    number of channels fixed with MSG_set_channel_number().
122  * \param PID a memory location for storing an int.
123  * \param max_duration the maximum time to wait for a task before
124     giving up. In the case of a reception, *\a PID will be updated
125     with the PID of the first process to send a task.
126  * \return #MSG_HOST_FAILURE if the host is shut down in the meantime
127    and #MSG_OK otherwise.
128  */
129 MSG_error_t MSG_channel_select_from(m_channel_t channel, double max_duration,
130                                     int *PID)
131 {
132         MSG_RETURN(MSG_OK);
133 }
134
135
136 /** \ingroup msg_gos_functions
137
138  * \brief Return the number of tasks waiting to be received on a \a
139    channel and sent by \a host.
140  *
141  * It takes two parameters.
142  * \param channel the channel on which the agent should be
143    listening. This value has to be >=0 and < than the maximal
144    number of channels fixed with MSG_set_channel_number().
145  * \param host the host that is to be watched.
146  * \return the number of tasks waiting to be received on \a channel
147    and sent by \a host.
148  */
149 int MSG_task_probe_from_host(int channel, m_host_t host)
150 {
151         return 0;
152 }
153
154 /** \ingroup msg_gos_functions \brief Put a task on a channel of an
155  * host (with a timeout on the waiting of the destination host) and
156  * waits for the end of the transmission.
157  *
158  * This function is used for describing the behavior of an agent. It
159  * takes four parameter.
160  * \param task a #m_task_t to send on another location. This task
161    will not be usable anymore when the function will return. There is
162    no automatic task duplication and you have to save your parameters
163    before calling this function. Tasks are unique and once it has been
164    sent to another location, you should not access it anymore. You do
165    not need to call MSG_task_destroy() but to avoid using, as an
166    effect of inattention, this task anymore, you definitely should
167    renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
168    can be transfered iff it has been correctly created with
169    MSG_task_create().
170  * \param dest the destination of the message
171  * \param channel the channel on which the agent should put this
172    task. This value has to be >=0 and < than the maximal number of
173    channels fixed with MSG_set_channel_number().
174  * \param max_duration the maximum time to wait for a task before giving
175     up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task 
176     will not be modified 
177  * \return #MSG_FATAL if \a task is not properly initialized and
178    #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
179    this function was called was shut down. Returns
180    #MSG_TRANSFER_FAILURE if the transfer could not be properly done
181    (network failure, dest failure, timeout...)
182  */
183 MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest, 
184                                       m_channel_t channel, double max_duration)
185 {
186         MSG_RETURN(MSG_OK);
187 }
188 /** \ingroup msg_gos_functions
189  * \brief Put a task on a channel of an host and waits for the end of the
190  * transmission.
191  *
192  * This function is used for describing the behavior of an agent. It
193  * takes three parameter.
194  * \param task a #m_task_t to send on another location. This task
195    will not be usable anymore when the function will return. There is
196    no automatic task duplication and you have to save your parameters
197    before calling this function. Tasks are unique and once it has been
198    sent to another location, you should not access it anymore. You do
199    not need to call MSG_task_destroy() but to avoid using, as an
200    effect of inattention, this task anymore, you definitely should
201    renitialize it with #MSG_TASK_UNINITIALIZED. Note that this task
202    can be transfered iff it has been correctly created with
203    MSG_task_create().
204  * \param dest the destination of the message
205  * \param channel the channel on which the agent should put this
206    task. This value has to be >=0 and < than the maximal number of
207    channels fixed with MSG_set_channel_number().
208  * \return #MSG_FATAL if \a task is not properly initialized and
209  * #MSG_OK otherwise. Returns #MSG_HOST_FAILURE if the host on which
210  * this function was called was shut down. Returns
211  * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
212  * (network failure, dest failure)
213  */
214 MSG_error_t MSG_task_put(m_task_t task,
215                          m_host_t dest, m_channel_t channel)
216 {
217   return MSG_task_put_with_timeout(task, dest, channel, -1.0);
218 }
219
220 /** \ingroup msg_gos_functions
221  * \brief Does exactly the same as MSG_task_put but with a bounded transmition 
222  * rate.
223  *
224  * \sa MSG_task_put
225  */
226 MSG_error_t MSG_task_put_bounded(m_task_t task,
227                                  m_host_t dest, m_channel_t channel,
228                                  double max_rate)
229 {
230   MSG_error_t res = MSG_OK;
231   task->simdata->rate=max_rate;
232   res = MSG_task_put(task, dest, channel);
233   return(res);
234 }
235
236 /** \ingroup msg_gos_functions
237  * \brief Executes a task and waits for its termination.
238  *
239  * This function is used for describing the behavior of an agent. It
240  * takes only one parameter.
241  * \param task a #m_task_t to execute on the location on which the
242    agent is running.
243  * \return #MSG_FATAL if \a task is not properly initialized and
244  * #MSG_OK otherwise.
245  */
246 MSG_error_t MSG_task_execute(m_task_t task)
247 {
248         MSG_RETURN(MSG_OK);
249 }
250
251 void __MSG_task_execute(m_process_t process, m_task_t task)
252 {
253
254 }
255
256 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task)
257 {
258         MSG_RETURN(MSG_OK);
259 }
260 /** \ingroup m_task_management
261  * \brief Creates a new #m_task_t (a parallel one....).
262  *
263  * A constructor for #m_task_t taking six arguments and returning the 
264    corresponding object.
265  * \param name a name for the object. It is for user-level information
266    and can be NULL.
267  * \param host_nb the number of hosts implied in the parallel task.
268  * \param host_list an array of \p host_nb m_host_t.
269  * \param computation_amount an array of \p host_nb
270    doubles. computation_amount[i] is the total number of operations
271    that have to be performed on host_list[i].
272  * \param communication_amount an array of \p host_nb* \p host_nb doubles.
273  * \param data a pointer to any data may want to attach to the new
274    object.  It is for user-level information and can be NULL. It can
275    be retrieved with the function \ref MSG_task_get_data.
276  * \see m_task_t
277  * \return The new corresponding object.
278  */
279 m_task_t MSG_parallel_task_create(const char *name, 
280                                   int host_nb,
281                                   const m_host_t *host_list,
282                                   double *computation_amount,
283                                   double *communication_amount,
284                                   void *data)
285 {
286   m_task_t task = xbt_new0(s_m_task_t,1);
287   return task;
288 }
289
290
291 static void __MSG_parallel_task_execute(m_process_t process, m_task_t task)
292 {
293         return;
294 }
295
296 MSG_error_t MSG_parallel_task_execute(m_task_t task)
297 {
298   m_process_t process = MSG_process_self();
299   MSG_error_t res;
300
301   DEBUG0("Computing on a tons of guys");
302   
303   __MSG_parallel_task_execute(process, task);
304
305   if(task->simdata->compute)
306     res = __MSG_wait_for_computation(process,task);
307   else 
308     res = MSG_OK;
309
310   return res;  
311 }
312
313
314 /** \ingroup msg_gos_functions
315  * \brief Sleep for the specified number of seconds
316  *
317  * Makes the current process sleep until \a time seconds have elapsed.
318  *
319  * \param nb_sec a number of second
320  */
321 MSG_error_t MSG_process_sleep(double nb_sec)
322 {
323         MSG_RETURN(MSG_OK);
324 }
325
326 /** \ingroup msg_gos_functions
327  * \brief Return the number of MSG tasks currently running on
328  * the host of the current running process.
329  */
330 static int MSG_get_msgload(void) 
331 {
332         return 0;
333 }
334
335 /** \ingroup msg_gos_functions
336  *
337  * \brief Return the last value returned by a MSG function (except
338  * MSG_get_errno...).
339  */
340 MSG_error_t MSG_get_errno(void)
341 {
342   return PROCESS_GET_ERRNO();
343 }