-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock_gen.ceu
51 lines (46 loc) · 1.76 KB
/
clock_gen.ceu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "c.ceu"
native/plain _double;
native/pure _get_next_time;
native/const _DBL_MAX;
native/const _NUM_ITERATIONS;
native/pre do
static const int NUM_ITERATIONS = 50000;
#include <float.h>;
end
#include "buffer.ceu"
#include "node.ceu"
#include "link.ceu"
pool[] NodeProcess all_processes;
pool[] Link all_links;
event _double time_delta; //simulate time passing in real world
var _double global_time = 0;
var int num_nodes = 2;
//create nodes
//'spawn' in ceu creates other synchronous logical threads - essentially abstraction of "parallel" statemnt
var& NodeProcess proc0 = spawn NodeProcess(num_nodes, 2000.0, &time_delta, 0) in all_processes;
var& NodeProcess proc1 = spawn NodeProcess(num_nodes, 2000.0, &time_delta, 1) in all_processes;
var& Buffer buff01 = spawn Buffer(1000, &proc0.local_clock_tick,0,1) in proc0.localBuffers;
var& Buffer buff10 = spawn Buffer(1000, &proc1.local_clock_tick,1,0) in proc1.localBuffers;
var& Link l_0_1 = spawn Link(&buff01, &buff10, &global_time, 0.01, &time_delta) in all_links;
loop _ in [0->_NUM_ITERATIONS] do
//find the lowest next scheduled time
var _double next_clock_tick = _DBL_MAX;
var&? NodeProcess proc_it;
loop proc_it in all_processes do
var& NodeProcess my_proc = &proc_it!;
if (my_proc.next_clock_tick_time < next_clock_tick) then
next_clock_tick = my_proc.next_clock_tick_time;
end
end
var&? Link link_it;
loop link_it in all_links do
var& Link my_link = &link_it!;
if (my_link.next_clock_tick_time < next_clock_tick) then
next_clock_tick = my_link.next_clock_tick_time;
end
end
global_time = next_clock_tick;
emit time_delta(global_time);
_printf("Global time is now: %lf\n", global_time);
end
escape 0;