18
18
* This function is used for describing the behavior of a process. It
19
19
* takes only one parameter.
20
* \param task a #m_task_t to execute on the location on which the process is running.
21
* \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
22
* or #MSG_HOST_FAILURE otherwise
24
MSG_error_t MSG_task_execute(m_task_t task)
26
simdata_task_t simdata = NULL;
27
simdata_process_t p_simdata;
20
* \param task a #msg_task_t to execute on the location on which the process is running.
21
* \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
22
* or #MSG_HOST_FAILURE otherwise
24
msg_error_t MSG_task_execute(msg_task_t task)
26
return MSG_parallel_task_execute(task);
29
/** \ingroup msg_task_usage
30
* \brief Executes a parallel task and waits for its termination.
32
* \param task a #msg_task_t to execute on the location on which the process is running.
34
* \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
35
* or #MSG_HOST_FAILURE otherwise
37
msg_error_t MSG_parallel_task_execute(msg_task_t task)
40
simdata_task_t simdata = task->simdata;
41
msg_process_t self = SIMIX_process_self();
42
simdata_process_t p_simdata = SIMIX_process_self_get_data(self);
28
43
e_smx_state_t comp_state;
30
simdata = task->simdata;
32
xbt_assert(simdata->host_nb == 0,
33
"This is a parallel task. Go to hell.");
44
msg_error_t status = MSG_OK;
35
46
#ifdef HAVE_TRACING
36
47
TRACE_msg_task_execute_start(task);
39
50
xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
40
"This task is executed somewhere else. Go fix your code! %d",
41
task->simdata->isused);
51
"This task is executed somewhere else. Go fix your code! %d",
52
task->simdata->isused);
43
54
XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
45
if (simdata->computation_amount == 0) {
56
if (simdata->computation_amount == 0 && !simdata->host_nb) {
46
57
#ifdef HAVE_TRACING
47
58
TRACE_msg_task_execute_end(task);
52
m_process_t self = SIMIX_process_self();
53
p_simdata = SIMIX_process_self_get_data(self);
56
simcall_host_execute(task->name, p_simdata->m_host->smx_host,
57
simdata->computation_amount,
60
simcall_set_category(simdata->compute, task->category);
63
p_simdata->waiting_action = simdata->compute;
64
comp_state = simcall_host_execution_wait(simdata->compute);
65
p_simdata->waiting_action = NULL;
69
XBT_DEBUG("Execution task '%s' finished in state %d", task->name, (int)comp_state);
70
if (comp_state == SIMIX_DONE) {
71
/* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
72
simdata->computation_amount = 0.0;
74
simdata->compute = NULL;
76
TRACE_msg_task_execute_end(task);
79
} else if (simcall_host_get_state(SIMIX_host_self()) == 0) {
80
/* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
82
simdata->compute = NULL;
84
TRACE_msg_task_execute_end(task);
86
MSG_RETURN(MSG_HOST_FAILURE);
88
/* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
90
simdata->compute = NULL;
92
TRACE_msg_task_execute_end(task);
94
MSG_RETURN(MSG_TASK_CANCELED);
98
/** \ingroup m_task_management
99
* \brief Creates a new #m_task_t (a parallel one....).
101
* A constructor for #m_task_t taking six arguments and returning the
102
corresponding object.
103
* \param name a name for the object. It is for user-level information
105
* \param host_nb the number of hosts implied in the parallel task.
106
* \param host_list an array of \p host_nb m_host_t.
107
* \param computation_amount an array of \p host_nb
108
doubles. computation_amount[i] is the total number of operations
109
that have to be performed on host_list[i].
110
* \param communication_amount an array of \p host_nb* \p host_nb doubles.
111
* \param data a pointer to any data may want to attach to the new
112
object. It is for user-level information and can be NULL. It can
113
be retrieved with the function \ref MSG_task_get_data.
115
* \return The new corresponding object.
118
MSG_parallel_task_create(const char *name, int host_nb,
119
const m_host_t * host_list,
120
double *computation_amount,
121
double *communication_amount, void *data)
124
simdata_task_t simdata = xbt_new0(s_simdata_task_t, 1);
125
m_task_t task = xbt_new0(s_m_task_t, 1);
126
task->simdata = simdata;
129
task->name = xbt_strdup(name);
133
simdata->computation_amount = 0;
134
simdata->message_size = 0;
68
if (simdata->host_nb > 0) {
69
simdata->compute = simcall_host_parallel_execute(task->name,
75
XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
77
simdata->compute = simcall_host_execute(task->name,
79
simdata->computation_amount,
84
simcall_set_category(simdata->compute, task->category);
86
p_simdata->waiting_action = simdata->compute;
87
comp_state = simcall_host_execution_wait(simdata->compute);
89
p_simdata->waiting_action = NULL;
93
XBT_DEBUG("Execution task '%s' finished in state %d",
94
task->name, (int)comp_state);
99
status = MSG_TASK_CANCELED;
106
/* action ended, set comm and compute = NULL, the actions is already destroyed
107
* in the main function */
108
simdata->computation_amount = 0.0;
109
simdata->comm = NULL;
135
110
simdata->compute = NULL;
136
simdata->comm = NULL;
137
simdata->rate = -1.0;
139
simdata->sender = NULL;
140
simdata->receiver = NULL;
141
simdata->source = NULL;
143
simdata->host_nb = host_nb;
144
simdata->host_list = xbt_new0(smx_host_t, host_nb);
145
simdata->comp_amount = computation_amount;
146
simdata->comm_amount = communication_amount;
148
for (i = 0; i < host_nb; i++)
149
simdata->host_list[i] = host_list[i]->smx_host;
154
/** \ingroup msg_task_usage
155
* \brief Executes a parallel task and waits for its termination.
157
* \param task a #m_task_t to execute on the location on which the process is running.
159
* \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
160
* or #MSG_HOST_FAILURE otherwise
162
MSG_error_t MSG_parallel_task_execute(m_task_t task)
164
simdata_task_t simdata = NULL;
165
e_smx_state_t comp_state;
166
simdata_process_t p_simdata;
168
simdata = task->simdata;
169
p_simdata = SIMIX_process_self_get_data(SIMIX_process_self());
171
xbt_assert((!simdata->compute)
172
&& (task->simdata->isused == 0),
173
"This task is executed somewhere else. Go fix your code!");
175
xbt_assert(simdata->host_nb,
176
"This is not a parallel task. Go to hell.");
178
XBT_DEBUG("Parallel computing on %s", SIMIX_host_get_name(p_simdata->m_host->smx_host));
183
simcall_host_parallel_execute(task->name, simdata->host_nb,
185
simdata->comp_amount,
186
simdata->comm_amount, 1.0, -1.0);
187
XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
189
p_simdata->waiting_action = simdata->compute;
190
comp_state = simcall_host_execution_wait(simdata->compute);
191
p_simdata->waiting_action = NULL;
193
XBT_DEBUG("Finished waiting for execution of action %p, state = %d", simdata->compute, (int)comp_state);
197
if (comp_state == SIMIX_DONE) {
198
/* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
199
simdata->computation_amount = 0.0;
200
simdata->comm = NULL;
201
simdata->compute = NULL;
203
} else if (simcall_host_get_state(SIMIX_host_self()) == 0) {
204
/* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
205
simdata->comm = NULL;
206
simdata->compute = NULL;
207
MSG_RETURN(MSG_HOST_FAILURE);
209
/* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
210
simdata->comm = NULL;
211
simdata->compute = NULL;
212
MSG_RETURN(MSG_TASK_CANCELED);
112
TRACE_msg_task_execute_end(task);