The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
core.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <log/log.h>
14 #include <mm/mm.h>
15 
16 #include <float.h>
17 #include <limits.h>
18 #include <stdbool.h>
19 #include <stdint.h>
20 
21 #ifdef max
22 #undef max
23 #endif
24 #define max(a, b) \
25 __extension__({ \
26  __typeof__ (a) _a = (a); \
27  __typeof__ (b) _b = (b); \
28  _a > _b ? _a : _b; \
29 })
30 
31 #ifdef min
32 #undef min
33 #endif
34 #define min(a, b) \
35 __extension__({ \
36  __typeof__ (a) _a = (a); \
37  __typeof__ (b) _b = (b); \
38  _a < _b ? _a : _b; \
39 })
40 
41 #ifndef CACHE_LINE_SIZE // TODO: calculate and inject at build time
42 
44 #define CACHE_LINE_SIZE 128
45 #endif
46 
47 // this definition is shared with ROOT-Sim.h
48 // TODO: generate ROOT-Sim.h at build time
49 enum rootsim_event {
50  MODEL_INIT = 65532,
51  LP_INIT,
52  LP_FINI,
53  MODEL_FINI
54 };
55 
57 #define likely(exp) __builtin_expect(!!(exp), 1)
58 #define unlikely(exp) __builtin_expect((exp), 0)
60 
62 typedef double simtime_t;
64 #define SIMTIME_MAX DBL_MAX
65 
67 
68 #define MAX_NODES (1 << 16)
69 
71 #define MAX_THREADS (1 << 10)
72 #define lid_to_nid(lid) (nid_t)(lid / n_lps_node)
73 
75 typedef uint64_t lp_id_t;
77 typedef unsigned rid_t;
79 typedef int nid_t;
80 
82 extern lp_id_t n_lps;
84 extern lp_id_t n_lps_node;
86 extern rid_t n_threads;
88 extern __thread rid_t rid;
89 
90 #ifdef ROOTSIM_MPI
91 
92 extern nid_t n_nodes;
94 extern nid_t nid;
96 
97 #else
98 enum {nid = 0, n_nodes = 1};
99 #endif
100 
101 extern void ProcessEvent(lp_id_t me, simtime_t now, unsigned event_type,
102  const void *content, unsigned size, void *state);
103 extern void ProcessEvent_pr(lp_id_t me, simtime_t now, unsigned event_type,
104  const void *content, unsigned size, void *state);
105 extern bool CanEnd(lp_id_t me, const void *state);
simtime_t
double simtime_t
The type used to represent logical time in the simulation.
Definition: core.h:62
rid_t
unsigned rid_t
Used to identify in a node the computing resources (threads at the moment)
Definition: core.h:77
nid_t
int nid_t
Used to identify MPI nodes in a distributed environment.
Definition: core.h:79
n_lps
lp_id_t n_lps
The total number of LPs in the simulation.
Definition: core.c:13
n_threads
rid_t n_threads
The total number of MPI nodes in the simulation.
Definition: core.c:15
ProcessEvent
void ProcessEvent(lp_id_t me, simtime_t now, unsigned event_type, const void *content, unsigned size, void *state)
The total number of threads running in the node.
Definition: application.c:21
rid
__thread rid_t rid
The identifier of the thread.
Definition: core.c:16
nid
nid_t nid
The node identifier of the node.
Definition: core.c:20
log.h
Logging library.
lp_id_t
uint64_t lp_id_t
Used to uniquely identify LPs in the simulation.
Definition: core.h:75
n_lps_node
lp_id_t n_lps_node
The total number of LPs hosted in the node.
Definition: lp.c:21
mm.h
Memory Manager main header.