The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
ccgs.c
Go to the documentation of this file.
1 
37 #include <stdbool.h>
38 #include <core/core.h>
39 #include <core/init.h>
40 #include <mm/mm.h>
41 #include <mm/state.h>
43 #include <communication/mpi.h>
44 #include <gvt/ccgs.h>
45 #include <scheduler/scheduler.h>
46 #include <scheduler/process.h>
47 
49 static bool ccgs_completed_simulation = false;
50 
52 static bool *lps_termination;
53 
54 inline bool ccgs_can_halt_simulation(void)
55 {
56 #ifdef HAVE_MPI
58 #else
60 #endif
61 }
62 
63 // Deve essere chiamata da un solo thread al GVT
64 void ccgs_reduce_termination(void)
65 {
66  register unsigned int i;
67  bool termination = true;
68 
69  /* Local termination: all LPs need to be terminated */
70  for (i = 0; i < n_prc; i++) {
71  termination &= lps_termination[i];
72  }
73 
74 #ifdef HAVE_MPI
75  /* If terminated locally check for global termination
76  * All other kernel need to terminated
77  */
78  if (unlikely(!ccgs_completed_simulation && termination)) {
80  }
81 #endif
82 
83  ccgs_completed_simulation = termination;
84 }
85 
107 void ccgs_compute_snapshot(state_t *time_barrier_pointer[])
108 {
109  int i = -1;
110  bool check_res = true;
111 
112  foreach_bound_lp(lp) {
113  i++;
114 
115  // If termination detection is incremental, we skip the current LP
117  continue;
118  }
119 
120  if (time_barrier_pointer[i] == NULL)
121  continue;
122 
123  // Call the application to check termination
124  lps_termination[lp->lid.to_int] = time_barrier_pointer[i]->simulation_completed;
125  check_res &= lps_termination[lp->lid.to_int];
126 
127  // Early stop
129  break;
130  }
131 
132  }
133 
134  // No real LP is running now!
135  current = NULL;
136 }
137 
138 
153 bool ccgs_lp_can_halt(struct lp_struct *lp)
154 {
155  bool ret;
157  return true;
158  }
159  current = lp;
160  ret = lp->OnGVT(lp->gid.to_int, lp->current_base_pointer);
161  current = NULL;
162 
163  return ret;
164 }
165 
166 void ccgs_init(void)
167 {
168  lps_termination = rsalloc(sizeof(bool) * n_prc);
169  memset(lps_termination, 0, sizeof(bool) * n_prc);
170 }
171 
172 void ccgs_fini(void)
173 {
174  rsfree(lps_termination);
175 }
Communication Routines.
static bool * lps_termination
In case termination detection is incremental, this array keeps track of LPs that think the simulation...
Definition: ccgs.c:52
Initialization routines.
Structure for LP&#39;s state.
Definition: state.h:49
void broadcast_termination(void)
Notify all the kernels about local termination.
Definition: mpi.c:329
int check_termination_mode
Check termination strategy: standard or incremental.
Definition: init.h:67
Core ROOT-Sim functionalities.
bool ccgs_lp_can_halt(struct lp_struct *lp)
Evaluate if the simulation can be halted according to some LP.
Definition: ccgs.c:153
unsigned int to_int
The LID numerical value.
Definition: core.h:145
unsigned int to_int
The GID numerical value.
Definition: core.h:133
The ROOT-Sim scheduler main module header.
__thread struct lp_struct * current
This is a per-thread variable pointing to the block state of the LP currently scheduled.
Definition: scheduler.c:72
Consistent and Committed Global State.
bool all_kernels_terminated(void)
Check if all kernels have reached the termination condition.
Definition: mpi.c:272
simulation_configuration rootsim_config
This global variable holds the configuration for the current simulation.
Definition: core.c:70
Memory Manager main header.
bool(* OnGVT)(unsigned int me, void *snapshot)
Definition: process.h:130
static bool ccgs_completed_simulation
This variable is an aggregate result for the distributed termination detection.
Definition: ccgs.c:49
void ccgs_compute_snapshot(state_t *time_barrier_pointer[])
Definition: ccgs.c:107
LP control blocks.
GID_t gid
Global ID of the LP.
Definition: process.h:82
MPI Support Module.
LP state management.
unsigned int n_prc
Number of logical processes hosted by the current kernel instance.
Definition: core.c:67
bool simulation_completed
Termination predicate for this LP.
Definition: state.h:70
LID_t lid
Local ID of the LP.
Definition: process.h:79
void * current_base_pointer
The current state base pointer (updated by SetState())
Definition: process.h:100
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:74