-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimulate_gpu.C
More file actions
210 lines (178 loc) · 5.57 KB
/
simulate_gpu.C
File metadata and controls
210 lines (178 loc) · 5.57 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* Copyright (C) 2017 Felix Wang
*
* Simulation Tool for Asynchronous Cortical Streams (stacs)
*/
#include "network.h"
/**************************************************************************
* Charm++ Read-Only Variables
**************************************************************************/
extern /*readonly*/ tick_t tstep;
extern /*readonly*/ idx_t nevtday;
extern /*readonly*/ idx_t intdisp;
extern /*readonly*/ idx_t intrec;
extern /*readonly*/ idx_t intsave;
extern /*readonly*/ tick_t tmax;
extern /*readonly*/ tick_t tepisode;
extern /*readonly*/ idx_t episodes;
/**************************************************************************
* Charm++ Reduction
**************************************************************************/
// Reduction for type idx_t
//
extern CkReduction::reducerType max_idx;
/**************************************************************************
* Network Simulation Cycle
**************************************************************************/
// Main control flow
//
void Network::CycleSimGPU() {
// Check if simulation time is complete
if (tsim >= tmax && !episodic) {
// return control to main
contribute(0, NULL, CkReduction::nop);
}
// Recording
else if (iter == reciter && !episodic) {
// Bookkeeping
reciter += intrec;
// Send records
thisProxy(prtidx).SaveRecord();
}
// Check if episode is complete
else if (tsim >= teps && episodic) {
// Check if all episodes are complete
if (++epsidx >= episodes) {
// return control to main
contribute(0, NULL, CkReduction::nop);
}
else {
teps = tsim + tepisode;
// Renew any episodic models
for (std::size_t i = 0; i < vtxmodidx.size(); ++i) {
model[vtxmodidx[i]]->Renew(state[i][0], stick[i][0]);
}
// Start a new cycle (after checked data sent)
thisProxy(prtidx).SaveRecord();
}
}
// Saving
else if (iter == saveiter) {
// Bookkeeping
saveiter += intsave;
// Display checkpointing information
if (prtidx == 0) {
CkPrintf(" Saving network at iteration %" PRIidx "\n", iter);
}
// Checkpoint
thisProxy(prtidx).SaveNetwork();
}
#ifdef STACS_WITH_YARP
else if (syncing && synciter == IDX_T_MAX) {
// nop
}
else if (iter == synciter) {
if (!syncing) {
// Bookkkeeping
synciter = IDX_T_MAX;
syncing = true;
idx_t contiter = iter;
// move control to sychronization callback
contribute(sizeof(idx_t), &contiter, max_idx);
}
else {
// Bookkkeeping
synciter = IDX_T_MAX;
// Display synchronization information
if (prtidx == 0) {
CkPrintf(" Synchronized at iteration %" PRIidx "\n", iter);
}
// move control to sychronization callback
contribute(0, NULL, CkReduction::nop);
}
}
#endif
// Simulate next cycle
else {
// Display iteration information
if (iter >= dispiter && prtidx == 0) {
dispiter += intdisp;
if (episodic) {
CkPrintf(" Simulating episode %" PRIidx "\n", epsidx);
}
else {
CkPrintf(" Simulating iteration %" PRIidx "\n", iter);
//CkPrintf(" Simulating time %" PRIrealsec " seconds\n", ((real_t) tsim)/(TICKS_PER_MS*1000));
}
}
// Bookkeeping
idx_t evtday = iter%nevtday;
tick_t tstop = tsim + tstep;
// Clear event buffer
evtext.clear();
// Redistribute any events (on new year)
if (evtday == 0) {
SortEventCalendar();
}
// Check for periodic events
if (tsim >= tleap) {
LeapEvent();
}
// Perform computation
for (std::size_t i = 0; i < vtxmodidx.size(); ++i) {
// Timing
tick_t tdrift = tsim;
// Sort events
std::sort(evtcal[i][evtday].begin(), evtcal[i][evtday].end());
// Perform events starting at beginning of step
std::vector<event_t>::iterator event = evtcal[i][evtday].begin();
while (event != evtcal[i][evtday].end() && event->diffuse <= tdrift) {
// edge events
if (event->index) {
model[edgmodidx[i][event->index-1]]->Jump(*event, state[i], stick[i], edgaux[edgmodidx[i][event->index-1]][vtxmodidx[i]]);
}
// vertex events
else {
model[vtxmodidx[i]]->Jump(*event, state[i], stick[i], vtxaux[i]);
}
++event;
}
// Computation
while (tdrift < tstop) {
// Step through model drift (vertex)
tdrift += model[vtxmodidx[i]]->Step(tdrift, tstop - tdrift, state[i][0], stick[i][0], events);
// Handle generated events (if any)
if (events.size()) {
for (std::size_t e = 0; e < events.size(); ++e) {
HandleEvent(events[e], i);
}
// clear log for next time
events.clear();
}
// Perform events up to tdrift
while (event != evtcal[i][evtday].end() && event->diffuse <= tdrift) {
// edge events
if (event->index) {
model[edgmodidx[i][event->index-1]]->Jump(*event, state[i], stick[i], edgaux[edgmodidx[i][event->index-1]][vtxmodidx[i]]);
}
// vertex events
else {
model[vtxmodidx[i]]->Jump(*event, state[i], stick[i], vtxaux[i]);
}
++event;
}
}
// Clear event queue
evtcal[i][evtday].clear();
}
// Send messages to neighbors
mEvent *mevent = BuildEvent();
netcomm.CommEvent(mevent);
// Increment simulated time
tsim += tstep;
// Add new records
AddRecord();
// Increment iteration
++iter;
}
}