Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge msg_vm.c - adrien (please note that there is one line (destruction of the tx_pr...
[simgrid.git] / src / msg / msg_actions.c
1 /* Copyright (c) 2009-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "msg_private.h"
8 #include "xbt/str.h"
9 #include "xbt/dynar.h"
10 #include "xbt/replay.h"
11
12 #include <errno.h>
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_action, msg,
15                                 "MSG actions for trace driven simulation");
16
17
18 void MSG_action_init()
19 {
20   _xbt_replay_action_init();
21   MSG_function_register_default(xbt_replay_action_runner);
22 }
23
24 void MSG_action_exit()
25 {
26   _xbt_replay_action_exit();
27 }
28
29
30
31 /** \ingroup msg_trace_driven
32  * \brief A trace loader
33  *
34  *  If path!=NULL, load a trace file containing actions, and execute them.
35  *  Else, assume that each process gets the path in its deployment file
36  */
37 msg_error_t MSG_action_trace_run(char *path)
38 {
39   msg_error_t res;
40   char *name;
41   xbt_dynar_t todo;
42   xbt_dict_cursor_t cursor;
43
44   action_fp=NULL;  
45   if (path) {
46     action_fp = fopen(path, "r");
47     if (action_fp == NULL)
48       xbt_die("Cannot open %s: %s", path, strerror(errno));
49   }
50   res = MSG_main();
51
52   if (!xbt_dict_is_empty(action_queues)) {
53     XBT_WARN
54         ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file.");
55
56
57     xbt_dict_foreach(action_queues, cursor, name, todo) {
58       XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
59     }
60   }
61
62   if (path)
63     fclose(action_fp);
64   xbt_dict_free(&action_queues);
65   action_queues = xbt_dict_new_homogeneous(NULL);
66
67   return res;
68 }