Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b166e7e5592dc77c02ffb545ad9459deacbf1ece
[simgrid.git] / src / msg_simix / task.c
1 #include "private.h"
2 #include "xbt/sysdep.h"
3 #include "xbt/log.h"
4
5 /** \defgroup m_task_management Managing functions of Tasks
6  *  \brief This section describes the task structure of MSG
7  *  (#m_task_t) and the functions for managing it.
8  *    \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Tasks" --> \endhtmlonly
9  * 
10  *  Since most scheduling algorithms rely on a concept of task
11  *  that can be either <em>computed</em> locally or
12  *  <em>transferred</em> on another processor, it seems to be the
13  *  right level of abstraction for our purposes. A <em>task</em>
14  *  may then be defined by a <em>computing amount</em>, a
15  *  <em>message size</em> and some <em>private data</em>.
16  */
17
18 /********************************* Task **************************************/
19 /** \ingroup m_task_management
20  * \brief Creates a new #m_task_t.
21  *
22  * A constructor for #m_task_t taking four arguments and returning the 
23    corresponding object.
24  * \param name a name for the object. It is for user-level information
25    and can be NULL.
26  * \param compute_duration a value of the processing amount (in flop)
27    needed to process this new task. If 0, then it cannot be executed with
28    MSG_task_execute(). This value has to be >=0.
29  * \param message_size a value of the amount of data (in bytes) needed to
30    transfer this new task. If 0, then it cannot be transfered with
31    MSG_task_get() and MSG_task_put(). This value has to be >=0.
32  * \param data a pointer to any data may want to attach to the new
33    object.  It is for user-level information and can be NULL. It can
34    be retrieved with the function \ref MSG_task_get_data.
35  * \see m_task_t
36  * \return The new corresponding object.
37  */
38 m_task_t MSG_task_create(const char *name, double compute_duration,
39                          double message_size, void *data)
40 {
41   m_task_t task = xbt_mallocator_get(msg_global->task_mallocator);
42
43   return task;
44 }
45
46 /** \ingroup m_task_management
47  * \brief Return the user data of a #m_task_t.
48  *
49  * This functions checks whether \a task is a valid pointer or not and return
50    the user data associated to \a task if it is possible.
51  */
52 void *MSG_task_get_data(m_task_t task)
53 {
54   xbt_assert0((task != NULL), "Invalid parameter");
55
56   return (task->data);
57 }
58
59 /** \ingroup m_task_management
60  * \brief Return the sender of a #m_task_t.
61  *
62  * This functions returns the #m_process_t which sent this task
63  */
64 m_process_t MSG_task_get_sender(m_task_t task)
65 {
66    xbt_assert0(task, "Invalid parameters");
67    return ((simdata_task_t) task->simdata)->sender;
68 }
69
70 /** \ingroup m_task_management
71  * \brief Return the source of a #m_task_t.
72  *
73  * This functions returns the #m_host_t from which this task was sent
74  */
75 m_host_t MSG_task_get_source(m_task_t task)
76 {
77    xbt_assert0(task, "Invalid parameters");
78    return ((simdata_task_t) task->simdata)->source;
79 }
80
81 /** \ingroup m_task_management
82  * \brief Return the name of a #m_task_t.
83  *
84  * This functions returns the name of a #m_task_t as specified on creation
85  */
86 const char *MSG_task_get_name(m_task_t task)
87 {
88    xbt_assert0(task, "Invalid parameters");
89    return task->name;
90 }
91
92
93 /** \ingroup m_task_management
94  * \brief Destroy a #m_task_t.
95  *
96  * Destructor for #m_task_t. Note that you should free user data, if any, \b 
97    before calling this function.
98  */
99 MSG_error_t MSG_task_destroy(m_task_t task)
100 {
101   return MSG_OK;
102 }
103
104
105 /** \ingroup m_task_management
106  * \brief Cancel a #m_task_t.
107  * \param task the taskt to cancel. If it was executed or transfered, it 
108           stops the process that were working on it.
109  */
110 MSG_error_t MSG_task_cancel(m_task_t task)
111 {
112   return MSG_FATAL;
113 }
114
115 /** \ingroup m_task_management
116  * \brief Returns the computation amount needed to process a task #m_task_t.
117  *        Once a task has been processed, this amount is thus set to 0...
118  */
119 double MSG_task_get_compute_duration(m_task_t task) 
120 {
121         return 0.0;
122 }
123
124 /** \ingroup m_task_management
125  * \brief Returns the remaining computation amount of a task #m_task_t.
126  *
127  */
128 double MSG_task_get_remaining_computation(m_task_t task)
129 {
130         return 0.0;
131 }
132
133 /** \ingroup m_task_management
134  * \brief Returns the size of the data attached to a task #m_task_t.
135  *
136  */
137 double MSG_task_get_data_size(m_task_t task) 
138 {
139   xbt_assert0((task != NULL) && (task->simdata != NULL), "Invalid parameter");
140
141   return task->simdata->message_size;
142 }
143
144 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task)
145 {
146   return MSG_OK;
147 }
148
149
150 /** \ingroup m_task_management
151  * \brief Changes the priority of a computation task. This priority doesn't affect 
152  *        the transfer rate. A priority of 2 will make a task receive two times more
153  *        cpu power than the other ones.
154  *
155  */
156 void MSG_task_set_priority(m_task_t task, double priority) 
157 {
158
159 }
160
161 /* Mallocator functions */
162 m_task_t task_mallocator_new_f(void) 
163 {
164   m_task_t task = xbt_new(s_m_task_t, 1);
165   simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1);
166   task->simdata = simdata;
167   return task;
168 }
169
170 void task_mallocator_free_f(m_task_t task) 
171 {
172   xbt_assert0((task != NULL), "Invalid parameter");
173
174   xbt_free(task->simdata);
175   xbt_free(task);
176
177   return;
178 }
179
180 void task_mallocator_reset_f(m_task_t task) 
181 {
182   memset(task->simdata, 0, sizeof(s_simdata_task_t));  
183 }