The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
parallel.c
Go to the documentation of this file.
1 
9 #include <parallel/parallel.h>
10 
11 #include <arch/thread.h>
12 #include <core/core.h>
13 #include <core/init.h>
14 #include <core/sync.h>
15 #include <datatypes/msg_queue.h>
17 #include <distributed/mpi.h>
18 #include <gvt/fossil.h>
19 #include <gvt/gvt.h>
20 #include <gvt/termination.h>
21 #include <lib/lib.h>
22 #include <log/stats.h>
23 #include <lp/lp.h>
24 #include <mm/msg_allocator.h>
25 
26 static thr_ret_t THREAD_CALL_CONV parallel_thread_run(void *rid_arg)
27 {
28  rid = (uintptr_t)rid_arg;
29  stats_init();
30  msg_allocator_init();
33  lp_init();
34 
35 #ifdef ROOTSIM_MPI
36  if (sync_thread_barrier())
38 #endif
39  if (sync_thread_barrier()) {
40  log_log(LOG_INFO, "Starting simulation");
41  stats_global_time_take(STATS_GLOBAL_EVENTS_START);
42  }
43 
44  while (likely(termination_cant_end())) {
45 #ifdef ROOTSIM_MPI
47 #endif
48  unsigned i = 8;
49  while (i--) {
50  process_msg();
51  }
52 
53  simtime_t current_gvt;
54  if (unlikely(current_gvt = gvt_phase_run())) {
55  termination_on_gvt(current_gvt);
56  fossil_collect(current_gvt);
57  stats_on_gvt(current_gvt);
58  }
59  }
60 
61  if (sync_thread_barrier()) {
62  stats_dump();
63  stats_global_time_take(STATS_GLOBAL_EVENTS_END);
64  log_log(LOG_INFO, "Finalizing simulation");
65  }
66 
67  lp_fini();
70  msg_allocator_fini();
71 
72  return THREAD_RET_SUCCESS;
73 }
74 
75 static void parallel_global_init(void)
76 {
78  lib_global_init();
79  process_global_init();
80  lp_global_init();
82  termination_global_init();
84 #ifdef ROOTSIM_MPI
85  remote_msg_map_global_init();
86 #endif
87 }
88 
89 static void parallel_global_fini(void)
90 {
91 #ifdef ROOTSIM_MPI
92  remote_msg_map_global_fini();
93 #endif
95  lp_global_fini();
96  process_global_fini();
97  lib_global_fini();
99 }
100 
101 void parallel_simulation(void)
102 {
103  log_log(LOG_INFO, "Initializing parallel simulation");
104  parallel_global_init();
105  stats_global_time_take(STATS_GLOBAL_INIT_END);
106 
107  thr_id_t thrs[n_threads];
108  rid_t i = n_threads;
109  while (i--) {
110  if (thread_start(&thrs[i], parallel_thread_run,
111  (void *)(uintptr_t)i)) {
112  log_log(LOG_FATAL, "Unable to create a thread!");
113  abort();
114  }
116  thread_affinity_set(thrs[i], i)) {
117  log_log(LOG_FATAL, "Unable to set a thread affinity!");
118  abort();
119  }
120  }
121 
122  i = n_threads;
123  while (i--)
124  thread_wait(thrs[i], NULL);
125 
126  stats_global_time_take(STATS_GLOBAL_FINI_START);
127  parallel_global_fini();
128 }
stats_init
void stats_init(void)
Initializes the stats subsystem in the current thread.
Definition: stats.c:179
simtime_t
double simtime_t
The type used to represent logical time in the simulation.
Definition: core.h:62
lib.h
Model library main header.
parallel.h
Concurrent simulation engine.
mpi_remote_msg_handle
void mpi_remote_msg_handle(void)
Empties the queue of incoming MPI messages, doing the right thing for each one of them.
Definition: mpi.c:218
rid_t
unsigned rid_t
Used to identify in a node the computing resources (threads at the moment)
Definition: core.h:77
sync.h
Easier Synchronization primitives.
simulation_configuration::core_binding
bool core_binding
If set, worker threads are bound to physical cores.
Definition: init.h:30
stats_global_fini
void stats_global_fini(void)
Finalizes the stats subsystem in the node.
Definition: stats.c:273
msg_queue_init
void msg_queue_init(void)
Initializes the message queue for the current thread.
Definition: msg_queue.c:54
mpi_node_barrier
void mpi_node_barrier(void)
A node barrier.
Definition: mpi.c:365
n_threads
rid_t n_threads
The total number of MPI nodes in the simulation.
Definition: core.c:15
msg_allocator.h
Memory management functions for messages.
thread_wait
int thread_wait(thr_id_t thr, thr_ret_t *ret)
Wait for specified thread to complete execution.
msg_queue_global_init
void msg_queue_global_init(void)
Initializes the message queue at the node level.
Definition: msg_queue.c:46
termination.h
Termination detection module.
stats.h
Statistics module.
init.h
Initialization routines.
log_log
#define log_log(lvl,...)
Produces a log.
Definition: log.h:49
lp.h
LP construction functions.
mpi.h
MPI Support Module.
rid
__thread rid_t rid
The identifier of the thread.
Definition: core.c:16
sync_thread_barrier
bool sync_thread_barrier(void)
Synchronizes threads on a barrier.
Definition: sync.c:19
LOG_FATAL
#define LOG_FATAL
The logging level reserved to unexpected, fatal conditions.
Definition: log.h:35
msg_queue.h
Message queue datatype.
thread_affinity_set
int thread_affinity_set(thr_id_t thr, unsigned core)
Sets a core affinity for a thread.
LOG_INFO
#define LOG_INFO
The logging level reserved to useful runtime messages.
Definition: log.h:29
fossil.h
Housekeeping operations.
likely
#define likely(exp)
Optimize the branch as likely taken.
Definition: core.h:57
thread_start
int thread_start(thr_id_t *thr_p, thr_run_fnc t_fnc, void *t_fnc_arg)
Creates a thread.
remote_msg_map.h
Message map datatype.
core.h
Core ROOT-Sim functionalities.
msg_queue_fini
void msg_queue_fini(void)
Finalizes the message queue for the current thread.
Definition: msg_queue.c:66
unlikely
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:59
global_config
struct simulation_configuration global_config
The configuration filled in by init_args_parse()
Definition: init.c:27
stats_global_init
void stats_global_init(void)
Initializes the stats subsystem in the node.
Definition: stats.c:162
msg_queue_global_fini
void msg_queue_global_fini(void)
Finalizes the message queue at the node level.
Definition: msg_queue.c:85
stats_global_time_take
void stats_global_time_take(enum stats_global_time this_stat)
Initializes the internal timer used to take accurate measurements.
Definition: stats.c:154
gvt.h
Global Virtual Time.
thread.h
Generic architecture management facilities.
gvt_global_init
void gvt_global_init(void)
Initializes the gvt module in the node.
Definition: gvt.c:56