~ubuntu-branches/ubuntu/raring/simgrid/raring

« back to all changes in this revision

Viewing changes to src/msg/msg_gos.c

  • Committer: Package Import Robot
  • Author(s): Martin Quinson
  • Date: 2013-01-31 00:24:51 UTC
  • mfrom: (10.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130131002451-krejhf7w7h24lpsc
Tags: 3.9~rc1-1
* New upstream release: the "Grasgory" release. Major changes:
  - Gras was completely removed from this version.
  - Documentation reorganization to ease browsing it.
  - New default value for the TCP_gamma parameter: 4MiB

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2004-2011. The SimGrid Team. All rights reserved.          */
 
1
/* Copyright (c) 2004-2012. The SimGrid Team. All rights reserved.          */
2
2
 
3
3
/* This program is free software; you can redistribute it and/or modify it
4
4
 * under the terms of the license (GNU LGPL) which comes with this package. */
17
17
 *
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
23
 
 */
24
 
MSG_error_t MSG_task_execute(m_task_t task)
25
 
{
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
 
23
 */
 
24
msg_error_t MSG_task_execute(msg_task_t task)
 
25
{
 
26
  return MSG_parallel_task_execute(task);
 
27
}
 
28
 
 
29
/** \ingroup msg_task_usage
 
30
 * \brief Executes a parallel task and waits for its termination.
 
31
 *
 
32
 * \param task a #msg_task_t to execute on the location on which the process is running.
 
33
 *
 
34
 * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
 
35
 * or #MSG_HOST_FAILURE otherwise
 
36
 */
 
37
msg_error_t MSG_parallel_task_execute(msg_task_t task)
 
38
{
 
39
  xbt_ex_t e;
 
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;
29
 
 
30
 
  simdata = task->simdata;
31
 
 
32
 
  xbt_assert(simdata->host_nb == 0,
33
 
              "This is a parallel task. Go to hell.");
 
44
  msg_error_t status = MSG_OK;
34
45
 
35
46
#ifdef HAVE_TRACING
36
47
  TRACE_msg_task_execute_start(task);
37
48
#endif
38
49
 
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);
42
53
 
43
54
  XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
44
55
 
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);
48
59
#endif
49
60
    return MSG_OK;
50
61
  }
51
62
 
52
 
  m_process_t self = SIMIX_process_self();
53
 
  p_simdata = SIMIX_process_self_get_data(self);
54
 
  simdata->isused=1;
55
 
  simdata->compute =
56
 
      simcall_host_execute(task->name, p_simdata->m_host->smx_host,
57
 
                           simdata->computation_amount,
58
 
                           simdata->priority);
59
 
#ifdef HAVE_TRACING
60
 
  simcall_set_category(simdata->compute, task->category);
61
 
#endif
62
 
 
63
 
  p_simdata->waiting_action = simdata->compute;
64
 
  comp_state = simcall_host_execution_wait(simdata->compute);
65
 
  p_simdata->waiting_action = NULL;
66
 
 
67
 
  simdata->isused=0;
68
 
 
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;
73
 
    simdata->comm = NULL;
74
 
    simdata->compute = NULL;
75
 
#ifdef HAVE_TRACING
76
 
    TRACE_msg_task_execute_end(task);
77
 
#endif
78
 
    MSG_RETURN(MSG_OK);
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 */
81
 
    simdata->comm = NULL;
82
 
    simdata->compute = NULL;
83
 
#ifdef HAVE_TRACING
84
 
    TRACE_msg_task_execute_end(task);
85
 
#endif
86
 
    MSG_RETURN(MSG_HOST_FAILURE);
87
 
  } else {
88
 
    /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
89
 
    simdata->comm = NULL;
90
 
    simdata->compute = NULL;
91
 
#ifdef HAVE_TRACING
92
 
    TRACE_msg_task_execute_end(task);
93
 
#endif
94
 
    MSG_RETURN(MSG_TASK_CANCELED);
95
 
  }
96
 
}
97
 
 
98
 
/** \ingroup m_task_management
99
 
 * \brief Creates a new #m_task_t (a parallel one....).
100
 
 *
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
104
 
 and can be NULL.
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.
114
 
 * \see m_task_t
115
 
 * \return The new corresponding object.
116
 
 */
117
 
m_task_t
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)
122
 
{
123
 
  int i;
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;
127
 
 
128
 
  /* Task structure */
129
 
  task->name = xbt_strdup(name);
130
 
  task->data = data;
131
 
 
132
 
  /* Simulator Data */
133
 
  simdata->computation_amount = 0;
134
 
  simdata->message_size = 0;
 
63
 
 
64
  TRY {
 
65
 
 
66
    simdata->isused=1;
 
67
 
 
68
    if (simdata->host_nb > 0) {
 
69
      simdata->compute = simcall_host_parallel_execute(task->name,
 
70
                                                       simdata->host_nb,
 
71
                                                       simdata->host_list,
 
72
                                                       simdata->comp_amount,
 
73
                                                       simdata->comm_amount,
 
74
                                                       1.0, -1.0);
 
75
      XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
 
76
    } else {
 
77
      simdata->compute = simcall_host_execute(task->name,
 
78
                                              p_simdata->m_host,
 
79
                                              simdata->computation_amount,
 
80
                                              simdata->priority);
 
81
 
 
82
    }
 
83
#ifdef HAVE_TRACING
 
84
    simcall_set_category(simdata->compute, task->category);
 
85
#endif
 
86
    p_simdata->waiting_action = simdata->compute;
 
87
    comp_state = simcall_host_execution_wait(simdata->compute);
 
88
 
 
89
    p_simdata->waiting_action = NULL;
 
90
 
 
91
    simdata->isused=0;
 
92
 
 
93
    XBT_DEBUG("Execution task '%s' finished in state %d",
 
94
              task->name, (int)comp_state);
 
95
  }
 
96
  CATCH(e) {
 
97
    switch (e.category) {
 
98
    case cancel_error:
 
99
      status = MSG_TASK_CANCELED;
 
100
      break;
 
101
    default:
 
102
      RETHROW;
 
103
    }
 
104
    xbt_ex_free(e);
 
105
  }
 
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;
138
 
  simdata->isused = 0;
139
 
  simdata->sender = NULL;
140
 
  simdata->receiver = NULL;
141
 
  simdata->source = NULL;
142
 
 
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;
147
 
 
148
 
  for (i = 0; i < host_nb; i++)
149
 
    simdata->host_list[i] = host_list[i]->smx_host;
150
 
 
151
 
  return task;
152
 
}
153
 
 
154
 
/** \ingroup msg_task_usage
155
 
 * \brief Executes a parallel task and waits for its termination.
156
 
 *
157
 
 * \param task a #m_task_t to execute on the location on which the process is running.
158
 
 *
159
 
 * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
160
 
 * or #MSG_HOST_FAILURE otherwise
161
 
 */
162
 
MSG_error_t MSG_parallel_task_execute(m_task_t task)
163
 
{
164
 
  simdata_task_t simdata = NULL;
165
 
  e_smx_state_t comp_state;
166
 
  simdata_process_t p_simdata;
167
 
 
168
 
  simdata = task->simdata;
169
 
  p_simdata = SIMIX_process_self_get_data(SIMIX_process_self());
170
 
 
171
 
  xbt_assert((!simdata->compute)
172
 
              && (task->simdata->isused == 0),
173
 
              "This task is executed somewhere else. Go fix your code!");
174
 
 
175
 
  xbt_assert(simdata->host_nb,
176
 
              "This is not a parallel task. Go to hell.");
177
 
 
178
 
  XBT_DEBUG("Parallel computing on %s", SIMIX_host_get_name(p_simdata->m_host->smx_host));
179
 
 
180
 
  simdata->isused=1;
181
 
 
182
 
  simdata->compute =
183
 
      simcall_host_parallel_execute(task->name, simdata->host_nb,
184
 
                                  simdata->host_list,
185
 
                                  simdata->comp_amount,
186
 
                                  simdata->comm_amount, 1.0, -1.0);
187
 
  XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
188
 
 
189
 
  p_simdata->waiting_action = simdata->compute;
190
 
  comp_state = simcall_host_execution_wait(simdata->compute);
191
 
  p_simdata->waiting_action = NULL;
192
 
 
193
 
  XBT_DEBUG("Finished waiting for execution of action %p, state = %d", simdata->compute, (int)comp_state);
194
 
 
195
 
  simdata->isused=0;
196
 
 
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;
202
 
    MSG_RETURN(MSG_OK);
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);
208
 
  } else {
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);
213
 
  }
 
111
#ifdef HAVE_TRACING
 
112
  TRACE_msg_task_execute_end(task);
 
113
#endif
 
114
 
 
115
  MSG_RETURN(status);
214
116
}
215
117
 
216
118
 
221
123
 *
222
124
 * \param nb_sec a number of second
223
125
 */
224
 
MSG_error_t MSG_process_sleep(double nb_sec)
 
126
msg_error_t MSG_process_sleep(double nb_sec)
225
127
{
226
 
  e_smx_state_t state;
227
 
  /*m_process_t proc = MSG_process_self();*/
 
128
  msg_error_t status = MSG_OK;
 
129
  /*msg_process_t proc = MSG_process_self();*/
228
130
 
229
131
#ifdef HAVE_TRACING
230
132
  TRACE_msg_process_sleep_in(MSG_process_self());
231
133
#endif
232
134
 
233
135
  /* create action to sleep */
234
 
  state = simcall_process_sleep(nb_sec);
235
136
 
236
137
  /*proc->simdata->waiting_action = act_sleep;
237
138
 
238
139
  FIXME: check if not setting the waiting_action breaks something on msg
239
140
  
240
141
  proc->simdata->waiting_action = NULL;*/
241
 
  
242
 
  if (state == SIMIX_DONE) {
243
 
#ifdef HAVE_TRACING
244
 
  TRACE_msg_process_sleep_out(MSG_process_self());
245
 
#endif
246
 
    MSG_RETURN(MSG_OK);
247
 
  } else {
248
 
#ifdef HAVE_TRACING
 
142
 
 
143
  simcall_process_sleep(nb_sec);
 
144
 
 
145
  #ifdef HAVE_TRACING
249
146
    TRACE_msg_process_sleep_out(MSG_process_self());
250
 
#endif
251
 
    MSG_RETURN(MSG_HOST_FAILURE);
252
 
  }
 
147
  #endif
 
148
  MSG_RETURN(status);
253
149
}
254
150
 
255
151
/** \ingroup msg_task_usage
275
171
 *    simply compare the host names, for example. After sufficient testing, provide an example that
276
172
 *    we could add to the distribution, and your first contribution to SimGrid is ready. Thanks in advance.
277
173
 *
278
 
 * \param task a memory location for storing a #m_task_t.
 
174
 * \param task a memory location for storing a #msg_task_t.
279
175
 * \param alias name of the mailbox to receive the task from
280
 
 * \param host a #m_host_t host from where the task was sent
 
176
 * \param host a #msg_host_t host from where the task was sent
281
177
 *
282
178
 * \return Returns
283
179
 * #MSG_OK if the task was successfully received,
284
180
 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
285
181
 */
286
 
MSG_error_t
287
 
MSG_task_receive_from_host(m_task_t * task, const char *alias,
288
 
                           m_host_t host)
 
182
msg_error_t
 
183
MSG_task_receive_from_host(msg_task_t * task, const char *alias,
 
184
                           msg_host_t host)
289
185
{
290
186
  return MSG_task_receive_ext(task, alias, -1, host);
291
187
}
297
193
 * until the task is received. See #MSG_task_irecv
298
194
 * for receiving tasks asynchronously.
299
195
 *
300
 
 * \param task a memory location for storing a #m_task_t.
 
196
 * \param task a memory location for storing a #msg_task_t.
301
197
 * \param alias name of the mailbox to receive the task from
302
198
 *
303
199
 * \return Returns
304
200
 * #MSG_OK if the task was successfully received,
305
201
 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
306
202
 */
307
 
MSG_error_t MSG_task_receive(m_task_t * task, const char *alias)
 
203
msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
308
204
{
309
205
  return MSG_task_receive_with_timeout(task, alias, -1);
310
206
}
317
213
 * for receiving tasks asynchronously.  You can provide a -1 timeout
318
214
 * to obtain an infinite timeout.
319
215
 *
320
 
 * \param task a memory location for storing a #m_task_t.
 
216
 * \param task a memory location for storing a #msg_task_t.
321
217
 * \param alias name of the mailbox to receive the task from
322
218
 * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
323
219
 *
325
221
 * #MSG_OK if the task was successfully received,
326
222
 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
327
223
 */
328
 
MSG_error_t
329
 
MSG_task_receive_with_timeout(m_task_t * task, const char *alias,
 
224
msg_error_t
 
225
MSG_task_receive_with_timeout(msg_task_t * task, const char *alias,
330
226
                              double timeout)
331
227
{
332
228
  return MSG_task_receive_ext(task, alias, timeout, NULL);
340
236
 * for receiving tasks asynchronously. You can provide a -1 timeout
341
237
 * to obtain an infinite timeout.
342
238
 *
343
 
 * \param task a memory location for storing a #m_task_t.
 
239
 * \param task a memory location for storing a #msg_task_t.
344
240
 * \param alias name of the mailbox to receive the task from
345
241
 * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
346
 
 * \param host a #m_host_t host from where the task was sent
 
242
 * \param host a #msg_host_t host from where the task was sent
347
243
 *
348
244
 * \return Returns
349
245
 * #MSG_OK if the task was successfully received,
350
246
* #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
351
247
 */
352
 
MSG_error_t
353
 
MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout,
354
 
                     m_host_t host)
 
248
msg_error_t
 
249
MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout,
 
250
                     msg_host_t host)
355
251
{
356
252
  XBT_DEBUG
357
253
      ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
366
262
 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
367
263
 * to end the communication.
368
264
 *
369
 
 * \param task a #m_task_t to send on another location.
 
265
 * \param task a #msg_task_t to send on another location.
370
266
 * \param alias name of the mailbox to sent the task to
371
267
 * \return the msg_comm_t communication created
372
268
 */
373
 
msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
 
269
msg_comm_t MSG_task_isend(msg_task_t task, const char *alias)
374
270
{
375
271
  return MSG_task_isend_with_matching(task,alias,NULL,NULL);
376
272
}
381
277
 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
382
278
 * to end the communication.
383
279
 *
384
 
 * \param task a #m_task_t to send on another location.
 
280
 * \param task a #msg_task_t to send on another location.
385
281
 * \param alias name of the mailbox to sent the task to
386
282
 * \param match_fun boolean function which parameters are:
387
283
 *        - match_data_provided_here
390
286
 * \param match_data user provided data passed to match_fun
391
287
 * \return the msg_comm_t communication created
392
288
 */
393
 
XBT_INLINE msg_comm_t MSG_task_isend_with_matching(m_task_t task, const char *alias,
 
289
XBT_INLINE msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char *alias,
394
290
    int (*match_fun)(void*,void*, smx_action_t),
395
291
    void *match_data)
396
292
{
397
293
  simdata_task_t t_simdata = NULL;
398
 
  m_process_t process = MSG_process_self();
 
294
  msg_process_t process = MSG_process_self();
399
295
  msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
400
296
 
401
 
  /* FIXME: these functions are not traceable */
 
297
#ifdef HAVE_TRACING
 
298
  int call_end = TRACE_msg_task_put_start(task);
 
299
#endif
402
300
 
403
301
  /* Prepare the task to send */
404
302
  t_simdata = task->simdata;
421
319
    simcall_comm_isend(mailbox, t_simdata->message_size,
422
320
                         t_simdata->rate, task, sizeof(void *), match_fun, NULL, match_data, 0);
423
321
  t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
 
322
#ifdef HAVE_TRACING
 
323
    if (TRACE_is_enabled()) {
 
324
      simcall_set_category(comm->s_comm, task->category);
 
325
    }
 
326
#endif
 
327
 
 
328
#ifdef HAVE_TRACING
 
329
  if (call_end)
 
330
    TRACE_msg_task_put_end();
 
331
#endif
424
332
 
425
333
  return comm;
426
334
}
436
344
 * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
437
345
 * in the SimGrid-user mailing list archive.
438
346
 *
439
 
 * \param task a #m_task_t to send on another location.
 
347
 * \param task a #msg_task_t to send on another location.
440
348
 * \param alias name of the mailbox to sent the task to
441
349
 * \param cleanup a function to destroy the task if the
442
350
 * communication fails, e.g. MSG_task_destroy
443
351
 * (if NULL, no function will be called)
444
352
 */
445
 
void MSG_task_dsend(m_task_t task, const char *alias, void_f_pvoid_t cleanup)
 
353
void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup)
446
354
{
447
355
  simdata_task_t t_simdata = NULL;
448
 
  m_process_t process = MSG_process_self();
 
356
  msg_process_t process = MSG_process_self();
449
357
  msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
450
358
 
451
 
  /* FIXME: these functions are not traceable */
452
 
 
453
359
  /* Prepare the task to send */
454
360
  t_simdata = task->simdata;
455
361
  t_simdata->sender = process;
462
368
  t_simdata->comm = NULL;
463
369
  msg_global->sent_msg++;
464
370
 
 
371
#ifdef HAVE_TRACING
 
372
  int call_end = TRACE_msg_task_put_start(task);
 
373
#endif
 
374
 
465
375
  /* Send it by calling SIMIX network layer */
466
376
  smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size,
467
377
                       t_simdata->rate, task, sizeof(void *), NULL, cleanup, NULL, 1);
468
378
  t_simdata->comm = comm;
 
379
#ifdef HAVE_TRACING
 
380
    if (TRACE_is_enabled()) {
 
381
      simcall_set_category(comm, task->category);
 
382
    }
 
383
#endif
 
384
 
 
385
#ifdef HAVE_TRACING
 
386
  if (call_end)
 
387
    TRACE_msg_task_put_end();
 
388
#endif
469
389
}
470
390
 
471
391
/** \ingroup msg_task_usage
474
394
 * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
475
395
 * to end the communication.
476
396
 * 
477
 
 * \param task a memory location for storing a #m_task_t. has to be valid until the end of the communication.
 
397
 * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
478
398
 * \param name of the mailbox to receive the task on
479
399
 * \return the msg_comm_t communication created
480
400
 */
481
 
msg_comm_t MSG_task_irecv(m_task_t *task, const char *name)
 
401
msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
482
402
{
483
403
  smx_rdv_t rdv = MSG_mailbox_get_by_alias(name);
484
404
 
513
433
{
514
434
  xbt_ex_t e;
515
435
  int finished = 0;
 
436
 
516
437
  TRY {
517
438
    finished = simcall_comm_test(comm->s_comm);
518
439
 
523
444
  }
524
445
  CATCH(e) {
525
446
    switch (e.category) {
526
 
 
527
 
      case host_error:
528
 
        comm->status = MSG_HOST_FAILURE;
529
 
        finished = 1;
530
 
        break;
531
 
 
532
447
      case network_error:
533
448
        comm->status = MSG_TRANSFER_FAILURE;
534
449
        finished = 1;
568
483
    xbt_dynar_push(s_comms, &comm->s_comm);
569
484
  }
570
485
 
571
 
  MSG_error_t status = MSG_OK;
 
486
  msg_error_t status = MSG_OK;
572
487
  TRY {
573
488
    finished_index = simcall_comm_testany(s_comms);
574
489
  }
575
490
  CATCH(e) {
576
491
    switch (e.category) {
577
 
 
578
 
      case host_error:
579
 
        finished_index = e.value;
580
 
        status = MSG_HOST_FAILURE;
581
 
        break;
582
 
 
583
492
      case network_error:
584
493
        finished_index = e.value;
585
494
        status = MSG_TRANSFER_FAILURE;
625
534
 *
626
535
 * It takes two parameters.
627
536
 * \param comm the communication to wait.
628
 
 * \param timeout Wait until the communication terminates or the timeout occurs
629
 
 * \return MSG_error_t
 
537
 * \param timeout Wait until the communication terminates or the timeout 
 
538
 * occurs. You can provide a -1 timeout to obtain an infinite timeout.
 
539
 * \return msg_error_t
630
540
 */
631
 
MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
 
541
msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
632
542
{
633
543
  xbt_ex_t e;
634
544
  TRY {
643
553
  }
644
554
  CATCH(e) {
645
555
    switch (e.category) {
646
 
    case host_error:
647
 
      comm->status = MSG_HOST_FAILURE;
648
 
      break;
649
556
    case network_error:
650
557
      comm->status = MSG_TRANSFER_FAILURE;
651
558
      break;
695
602
    xbt_dynar_push(s_comms, &comm->s_comm);
696
603
  }
697
604
 
698
 
  MSG_error_t status = MSG_OK;
 
605
  msg_error_t status = MSG_OK;
699
606
  TRY {
700
607
    finished_index = simcall_comm_waitany(s_comms);
701
608
  }
702
609
  CATCH(e) {
703
610
    switch (e.category) {
704
 
 
705
 
      case host_error:
706
 
        finished_index = e.value;
707
 
        status = MSG_HOST_FAILURE;
708
 
        break;
709
 
 
710
611
      case network_error:
711
612
        finished_index = e.value;
712
613
        status = MSG_TRANSFER_FAILURE;
745
646
 * \return the status of the communication, or #MSG_OK if no error occured
746
647
 * during the communication
747
648
 */
748
 
MSG_error_t MSG_comm_get_status(msg_comm_t comm) {
 
649
msg_error_t MSG_comm_get_status(msg_comm_t comm) {
749
650
 
750
651
  return comm->status;
751
652
}
752
653
 
753
654
/** \ingroup msg_task_usage
754
 
 * \brief Get a task (#m_task_t) from a communication
 
655
 * \brief Get a task (#msg_task_t) from a communication
755
656
 *
756
657
 * \param comm the communication where to get the task
757
658
 * \return the task from the communication
758
659
 */
759
 
m_task_t MSG_comm_get_task(msg_comm_t comm)
 
660
msg_task_t MSG_comm_get_task(msg_comm_t comm)
760
661
{
761
662
  xbt_assert(comm, "Invalid parameter");
762
663
 
764
665
}
765
666
 
766
667
/**
767
 
 * \brief This function is called by SIMIX to copy the data of a comm.
 
668
 * \brief This function is called by SIMIX in kernel mode to copy the data of a comm.
768
669
 * \param comm the comm
769
670
 * \param buff the data copied
770
671
 * \param buff_size size of the buffer
776
677
 
777
678
  // notify the user callback if any
778
679
  if (msg_global->task_copy_callback) {
779
 
    m_task_t task = buff;
 
680
    msg_task_t task = buff;
780
681
    msg_global->task_copy_callback(task,
781
682
        simcall_comm_get_src_proc(comm), simcall_comm_get_dst_proc(comm));
782
683
  }
795
696
 * \return Returns #MSG_OK if the task was successfully sent,
796
697
 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
797
698
 */
798
 
MSG_error_t MSG_task_send(m_task_t task, const char *alias)
 
699
msg_error_t MSG_task_send(msg_task_t task, const char *alias)
799
700
{
800
701
  XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
801
702
  return MSG_task_send_with_timeout(task, alias, -1);
815
716
 * \return Returns #MSG_OK if the task was successfully sent,
816
717
 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
817
718
 */
818
 
MSG_error_t
819
 
MSG_task_send_bounded(m_task_t task, const char *alias, double maxrate)
 
719
msg_error_t
 
720
MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate)
820
721
{
821
722
  task->simdata->rate = maxrate;
822
723
  return MSG_task_send(task, alias);
835
736
 * \return Returns #MSG_OK if the task was successfully sent,
836
737
 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
837
738
 */
838
 
MSG_error_t
839
 
MSG_task_send_with_timeout(m_task_t task, const char *alias,
 
739
msg_error_t
 
740
MSG_task_send_with_timeout(msg_task_t task, const char *alias,
840
741
                           double timeout)
841
742
{
842
743
  return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
865
766
 * given mailbox, 0 if there is no pending communication actions.
866
767
 *
867
768
 */
868
 
int MSG_task_listen_from_host(const char *alias, m_host_t host)
 
769
int MSG_task_listen_from_host(const char *alias, msg_host_t host)
869
770
{
870
771
  return
871
772
      MSG_mailbox_get_count_host_waiting_tasks(MSG_mailbox_get_by_alias
883
784
 */
884
785
int MSG_task_listen_from(const char *alias)
885
786
{
886
 
  m_task_t task;
 
787
  msg_task_t task;
887
788
 
888
789
  if (NULL ==
889
790
      (task = MSG_mailbox_get_head(MSG_mailbox_get_by_alias(alias))))
903
804
 * previously declared with the function #TRACE_category
904
805
 * (or with #TRACE_category_with_color).
905
806
 *
906
 
 * See \ref tracing_tracing for details on how to trace
 
807
 * See \ref tracing for details on how to trace
907
808
 * the (categorized) resource utilization.
908
809
 *
909
810
 * \param task the task that is going to be categorized
911
812
 *
912
813
 * \see MSG_task_get_category, TRACE_category, TRACE_category_with_color
913
814
 */
914
 
void MSG_task_set_category (m_task_t task, const char *category)
 
815
void MSG_task_set_category (msg_task_t task, const char *category)
915
816
{
916
817
#ifdef HAVE_TRACING
917
818
  TRACE_msg_set_task_category (task, category);
928
829
 *
929
830
 * \return Returns the name of the tracing category of the given task, NULL otherwise
930
831
 */
931
 
const char *MSG_task_get_category (m_task_t task)
 
832
const char *MSG_task_get_category (msg_task_t task)
932
833
{
933
834
#ifdef HAVE_TRACING
934
835
  return task->category;
937
838
#endif
938
839
}
939
840
 
 
841
/**
 
842
 * \brief Returns the value of a given AS or router property
 
843
 *
 
844
 * \param asr the name of a router or AS
 
845
 * \param name a property name
 
846
 * \return value of a property (or NULL if property not set)
 
847
 */
 
848
const char *MSG_as_router_get_property_value(const char* asr, const char *name)
 
849
{
 
850
  return xbt_dict_get_or_null(MSG_as_router_get_properties(asr), name);
 
851
}
 
852
 
 
853
/**
 
854
 * \brief Returns a xbt_dict_t consisting of the list of properties assigned to
 
855
 * a the AS or router
 
856
 *
 
857
 * \param asr the name of a router or AS
 
858
 * \return a dict containing the properties
 
859
 */
 
860
xbt_dict_t MSG_as_router_get_properties(const char* asr)
 
861
{
 
862
  return (simcall_asr_get_properties(asr));
 
863
}
 
864
 
 
865
/**
 
866
 * \brief Change the value of a given AS or router
 
867
 *
 
868
 * \param asr the name of a router or AS
 
869
 * \param name a property name
 
870
 * \param value what to change the property to
 
871
 * \param free_ctn the freeing function to use to kill the value on need
 
872
 */
 
873
void MSG_as_router_set_property_value(const char* asr, const char *name, char *value,void_f_pvoid_t free_ctn) {
 
874
  xbt_dict_set(MSG_as_router_get_properties(asr), name, value,free_ctn);
 
875
}
 
876
 
940
877
#ifdef MSG_USE_DEPRECATED
941
878
/** \ingroup msg_deprecated_functions
942
879
 *
943
880
 * \brief Return the last value returned by a MSG function (except
944
881
 * MSG_get_errno...).
945
882
 */
946
 
MSG_error_t MSG_get_errno(void)
 
883
msg_error_t MSG_get_errno(void)
947
884
{
948
885
  return PROCESS_GET_ERRNO();
949
886
}
954
891
 *
955
892
 * This function is used for describing the behavior of a process. It
956
893
 * takes three parameter.
957
 
 * \param task a #m_task_t to send on another location. This task
 
894
 * \param task a #msg_task_t to send on another location. This task
958
895
 will not be usable anymore when the function will return. There is
959
896
 no automatic task duplication and you have to save your parameters
960
897
 before calling this function. Tasks are unique and once it has been
973
910
 * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
974
911
 * (network failure, dest failure) or #MSG_OK if it succeeded.
975
912
 */
976
 
MSG_error_t MSG_task_put(m_task_t task, m_host_t dest, m_channel_t channel)
 
913
msg_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel)
977
914
{
978
915
  XBT_WARN("DEPRECATED! Now use MSG_task_send");
979
916
  return MSG_task_put_with_timeout(task, dest, channel, -1.0);
985
922
 *
986
923
 * \sa MSG_task_put
987
924
 */
988
 
MSG_error_t
989
 
MSG_task_put_bounded(m_task_t task, m_host_t dest, m_channel_t channel,
 
925
msg_error_t
 
926
MSG_task_put_bounded(msg_task_t task, msg_host_t dest, m_channel_t channel,
990
927
                     double maxrate)
991
928
{
992
929
  XBT_WARN("DEPRECATED! Now use MSG_task_send_bounded");
1002
939
 *
1003
940
 * This function is used for describing the behavior of a process. It
1004
941
 * takes four parameter.
1005
 
 * \param task a #m_task_t to send on another location. This task
 
942
 * \param task a #msg_task_t to send on another location. This task
1006
943
 will not be usable anymore when the function will return. There is
1007
944
 no automatic task duplication and you have to save your parameters
1008
945
 before calling this function. Tasks are unique and once it has been
1024
961
#MSG_TRANSFER_FAILURE if the transfer could not be properly done
1025
962
(network failure, dest failure, timeout...) or #MSG_OK if the communication succeeded.
1026
963
 */
1027
 
MSG_error_t
1028
 
MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
 
964
msg_error_t
 
965
MSG_task_put_with_timeout(msg_task_t task, msg_host_t dest,
1029
966
                          m_channel_t channel, double timeout)
1030
967
{
1031
968
  XBT_WARN("DEPRECATED! Now use MSG_task_send_with_timeout");
1051
988
int MSG_task_probe_from(m_channel_t channel)
1052
989
{
1053
990
  XBT_WARN("DEPRECATED! Now use MSG_task_listen_from");
1054
 
  m_task_t task;
 
991
  msg_task_t task;
1055
992
 
1056
993
  xbt_assert((channel >= 0)
1057
994
              && (channel < msg_global->max_channel), "Invalid channel %d",
1100
1037
 * \return the number of tasks waiting to be received on \a channel
1101
1038
 and sent by \a host.
1102
1039
 */
1103
 
int MSG_task_probe_from_host(int channel, m_host_t host)
 
1040
int MSG_task_probe_from_host(int channel, msg_host_t host)
1104
1041
{
1105
1042
  XBT_WARN("DEPRECATED! Now use MSG_task_listen_from_host");
1106
1043
  xbt_assert((channel >= 0)
1118
1055
 * \brief Listen on \a channel and waits for receiving a task from \a host.
1119
1056
 *
1120
1057
 * It takes three parameters.
1121
 
 * \param task a memory location for storing a #m_task_t. It will
 
1058
 * \param task a memory location for storing a #msg_task_t. It will
1122
1059
 hold a task when this function will return. Thus \a task should not
1123
1060
 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1124
1061
 those two condition does not hold, there will be a warning message.
1126
1063
 listening. This value has to be >=0 and < than the maximal
1127
1064
 number of channels fixed with MSG_set_channel_number().
1128
1065
 * \param host the host that is to be watched.
1129
 
 * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
 
1066
 * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1130
1067
 */
1131
 
MSG_error_t
1132
 
MSG_task_get_from_host(m_task_t * task, m_channel_t channel, m_host_t host)
 
1068
msg_error_t
 
1069
MSG_task_get_from_host(msg_task_t * task, m_channel_t channel, msg_host_t host)
1133
1070
{
1134
1071
  XBT_WARN("DEPRECATED! Now use MSG_task_receive_from_host");
1135
1072
  return MSG_task_get_ext(task, channel, -1, host);
1139
1076
 * \brief Listen on a channel and wait for receiving a task.
1140
1077
 *
1141
1078
 * It takes two parameters.
1142
 
 * \param task a memory location for storing a #m_task_t. It will
 
1079
 * \param task a memory location for storing a #msg_task_t. It will
1143
1080
 hold a task when this function will return. Thus \a task should not
1144
1081
 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1145
1082
 those two condition does not hold, there will be a warning message.
1146
1083
 * \param channel the channel on which the process should be
1147
1084
 listening. This value has to be >=0 and < than the maximal
1148
1085
 number of channels fixed with MSG_set_channel_number().
1149
 
 * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
 
1086
 * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1150
1087
 */
1151
 
MSG_error_t MSG_task_get(m_task_t * task, m_channel_t channel)
 
1088
msg_error_t MSG_task_get(msg_task_t * task, m_channel_t channel)
1152
1089
{
1153
1090
  XBT_WARN("DEPRECATED! Now use MSG_task_receive");
1154
1091
  return MSG_task_get_with_timeout(task, channel, -1);
1158
1095
 * \brief Listen on a channel and wait for receiving a task with a timeout.
1159
1096
 *
1160
1097
 * It takes three parameters.
1161
 
 * \param task a memory location for storing a #m_task_t. It will
 
1098
 * \param task a memory location for storing a #msg_task_t. It will
1162
1099
 hold a task when this function will return. Thus \a task should not
1163
1100
 be equal to \c NULL and \a *task should be equal to \c NULL. If one of
1164
1101
 those two condition does not hold, there will be a warning message.
1169
1106
 up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
1170
1107
 will not be modified and will still be
1171
1108
 equal to \c NULL when returning.
1172
 
 * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
 
1109
 * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
1173
1110
 */
1174
 
MSG_error_t
1175
 
MSG_task_get_with_timeout(m_task_t * task, m_channel_t channel,
 
1111
msg_error_t
 
1112
MSG_task_get_with_timeout(msg_task_t * task, m_channel_t channel,
1176
1113
                          double max_duration)
1177
1114
{
1178
1115
  XBT_WARN("DEPRECATED! Now use MSG_task_receive_with_timeout");
1179
1116
  return MSG_task_get_ext(task, channel, max_duration, NULL);
1180
1117
}
1181
1118
 
1182
 
MSG_error_t
1183
 
MSG_task_get_ext(m_task_t * task, m_channel_t channel, double timeout,
1184
 
                 m_host_t host)
 
1119
msg_error_t
 
1120
MSG_task_get_ext(msg_task_t * task, m_channel_t channel, double timeout,
 
1121
                 msg_host_t host)
1185
1122
{
1186
1123
  XBT_WARN("DEPRECATED! Now use MSG_task_receive_ext");
1187
1124
  xbt_assert((channel >= 0)