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[], simtime_t gvt)
108 {
109  int i;
110  bool check_res = true;
111  state_t temporary_log;
112 
113  (void)gvt; // This is used for state reconstruction which is currently commented out
114  //msg_t *realignment_evt;
115 
116  i = -1;
117  foreach_bound_lp(lp) {
118  i++;
119 
120  // If termination detection is incremental, we skip the current LP
122  continue;
123  }
124 
125  if (time_barrier_pointer[i] == NULL)
126  continue;
127 
128  // TODO: realign LogState and RestoreState to be compliant with the execution in the committed portion
129 
130  // Log the current state so that after we can restore it.
131  current = lp;
132  temporary_log.log = log_state(lp);
133  temporary_log.state = lp->state;
134  temporary_log.base_pointer = lp->current_base_pointer;
135 
136  // Restore the time barrier state
137  log_restore(lp, time_barrier_pointer[i]);
138  lp->state = time_barrier_pointer[i]->state;
139  lp->current_base_pointer =
140  time_barrier_pointer[i]->base_pointer;
141 
142 /*
143  // If the LP is not blocked, we can reconstruct the state exactly to the GVT
144  if(!is_blocked_state(lp->state)) {
145  // Realign the state to the current GVT value
146  if(list_next(time_barrier_pointer[i]->last_event) != NULL) {
147  realignment_evt = list_next(time_barrier_pointer[i]->last_event);
148  while(realignment_evt != NULL && realignment_evt->timestamp < gvt) {
149  realignment_evt = list_next(realignment_evt);
150  }
151  realignment_evt = list_prev(realignment_evt);
152 
153  // TODO: LPS[lid]->current_base_pointer can be removed as a parameter
154  silent_execution(lid, LPS(lid)->current_base_pointer, list_next(time_barrier_pointer[i]->last_event), realignment_evt);
155  }
156  }
157 
158 */
159  // Call the application to check termination
160  lps_termination[lp->lid.to_int] =
161  lp->OnGVT(lp->gid.to_int, lp->current_base_pointer);
162  check_res &= lps_termination[lp->lid.to_int];
163 
164  // Restore the current state
165  lp->state = temporary_log.state;
166  lp->current_base_pointer = temporary_log.base_pointer;
167  log_restore(lp, &temporary_log);
168  log_delete(temporary_log.log);
169 
170  // Early stop
172  break;
173  }
174 
175  }
176 
177  // No real LP is running now!
178  current = NULL;
179 }
180 
181 void ccgs_init(void)
182 {
183  lps_termination = rsalloc(sizeof(bool) * n_prc);
184  memset(lps_termination, 0, sizeof(bool) * n_prc);
185 }
186 
187 void ccgs_fini(void)
188 {
189  rsfree(lps_termination);
190 }
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:327
void log_delete(void *ckpt)
Definition: checkpoints.c:374
int check_termination_mode
Check termination strategy: standard or incremental.
Definition: init.h:68
Core ROOT-Sim functionalities.
The ROOT-Sim scheduler main module header.
short unsigned int state
Execution state.
Definition: state.h:64
__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.
void log_restore(struct lp_struct *lp, state_t *state_queue_node)
Definition: checkpoints.c:358
bool all_kernels_terminated(void)
Check if all kernels have reached the termination condition.
Definition: mpi.c:270
void * log_state(struct lp_struct *lp)
Definition: checkpoints.c:195
double simtime_t
This defines the type with whom timestamps are represented.
Definition: ROOT-Sim.h:55
simulation_configuration rootsim_config
This global variable holds the configuration for the current simulation.
Definition: core.c:70
void * base_pointer
This is a pointer used to keep track of changes to simulation states via SetState() ...
Definition: state.h:66
Memory Manager main header.
static bool ccgs_completed_simulation
This variable is an aggregate result for the distributed termination detection.
Definition: ccgs.c:49
void * log
A pointer to the actual log.
Definition: state.h:57
LP control blocks.
MPI Support Module.
LP state management.
void ccgs_compute_snapshot(state_t *time_barrier_pointer[], simtime_t gvt)
Definition: ccgs.c:107
unsigned int n_prc
Number of logical processes hosted by the current kernel instance.
Definition: core.c:67
#define unlikely(exp)
Optimize the branch as likely not taken.
Definition: core.h:74