The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
fossil.c
Go to the documentation of this file.
1 
10 #include <gvt/fossil.h>
11 
13 #include <gvt/gvt.h>
14 #include <lp/lp.h>
15 #include <lp/process.h>
16 #include <mm/model_allocator.h>
17 #include <mm/msg_allocator.h>
18 
19 #include <memory.h>
20 
21 #define cant_discard_ref_i(ref_i) \
22  array_get_at(proc_p->past_msgs, ref_i)->dest_t >= current_gvt
23 
24 static inline array_count_t first_discardable_ref(simtime_t current_gvt,
25  struct process_data *proc_p)
26 {
27  array_count_t j = array_count(proc_p->past_msgs) - 1;
28  while(cant_discard_ref_i(j)){
29  --j;
30  }
31  return j;
32 }
33 
34 static inline void fossil_lp_collect(simtime_t current_gvt)
35 {
36  struct process_data *proc_p = &current_lp->p;
37  array_count_t past_i = first_discardable_ref(current_gvt, proc_p);
38  past_i = model_allocator_fossil_lp_collect(past_i);
39  array_count_t sent_i = array_count(proc_p->sent_msgs);
40  array_count_t j = array_count(proc_p->past_msgs);
41  do{
42  --sent_i;
43  j -= (array_get_at(proc_p->sent_msgs, sent_i) == NULL);
44  } while(j > past_i);
45  array_truncate_first(proc_p->sent_msgs, sent_i);
46 
47  while(j--){
48  msg_allocator_free(array_get_at(proc_p->past_msgs, j));
49  }
50  array_truncate_first(proc_p->past_msgs, past_i);
51 }
52 
53 void fossil_collect(simtime_t current_gvt)
54 {
55 #ifdef ROOTSIM_MPI
56  remote_msg_map_fossil_collect(current_gvt);
57  msg_allocator_fossil_collect(current_gvt);
58 #endif
59 
60  for (uint64_t i = lp_id_first; i < lp_id_end; ++i) {
61  current_lp = &lps[i];
62  fossil_lp_collect(current_gvt);
63  }
64 }
simtime_t
double simtime_t
The type used to represent logical time in the simulation.
Definition: core.h:62
process_data
The message processing data produced by the LP.
Definition: process.h:17
lp_ctx::p
struct process_data p
The message processing context of this LP.
Definition: lp.h:27
msg_allocator.h
Memory management functions for messages.
process.h
LP state management functions.
lp.h
LP construction functions.
array_count_t
uint_fast32_t array_count_t
The type used to handle dynamic arrays count of elements and capacity.
Definition: array.h:21
fossil.h
Housekeeping operations.
remote_msg_map.h
Message map datatype.
array_count
#define array_count(self)
Gets the count of contained element in a dynamic array.
Definition: array.h:47
model_allocator.h
Memory management functions for simulation models.
gvt.h
Global Virtual Time.