-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnetrpc.C
More file actions
150 lines (138 loc) · 4.82 KB
/
netrpc.C
File metadata and controls
150 lines (138 loc) · 4.82 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
/**
* Copyright (C) 2017 Felix Wang
*
* Simulation Tool for Asynchronous Cortical Streams (stacs)
*/
#include "network.h"
#include "stream.h"
#ifdef STACS_WITH_YARP
/**************************************************************************
* Charm++ Read-Only Variables
**************************************************************************/
extern /*readonly*/ tick_t tstep;
extern /*readonly*/ idx_t nevtday;
/**************************************************************************
* Network Remote Procedure Call
**************************************************************************/
// Receive and handle RPC messages
//
void Network::CommRPC(mRPC *msg) {
//CkPrintf("Received %" PRIidx" on %" PRIidx " in iteration %" PRIidx "\n", msg->command, prtidx, iter);
// Pausing/Checkpointing/Stepping
//
if (msg->command == RPCCOMMAND_PAUSE ||
msg->command == RPCCOMMAND_STOP) {
// Coordinate the synchronization iteration
// Must be done through reduction/rebroadcast
// Local variables lead to ambiguous states
synciter = iter;
cyclepart.send();
// TODO make this print with debugging flag
//CkPrintf("Messages on %" PRIidx ": c0: %d, c1: %d, pi: % " PRIidx "\n", prtidx, cadjpart[0], cadjpart[1], partiter);
//CkPrintf("Pausing %" PRIidx " in iteration %" PRIidx " (comm: %" PRIidx ", sim: %" PRIidx ")\n", prtidx, synciter, commiter, iter);
}
else if (msg->command == RPCCOMMAND_PAUSED) {
synciter = msg->nrpcdata;
cyclepart.send();
}
else if (msg->command == RPCCOMMAND_UNPAUSE) {
// Resume simulation
syncing = false;
cyclepart.send();
}
else if (msg->command == RPCCOMMAND_CHECK) {
// Coordinate the synchronization iteration
synciter = iter;
// Perform checkpointing
thisProxy(prtidx).SaveNetwork();
}
else if (msg->command == RPCCOMMAND_STEP) {
if (msg->nrpcdata == 0) {
// Step for one iteration
synciter = iter + 1;
}
else {
// Coordinate the synchronization iteration
synciter = iter + (idx_t) (((tick_t) (msg->rpcdata[0]*TICKS_PER_MS))/tstep);
}
// Resume simulation until synchronization point
cyclepart.send();
}
// Stimulation
//
else if (msg->command == RPCCOMMAND_STIM || msg->command == RPCCOMMAND_PSTIM) {
// Coordinate the syncronization iteration
synciter = iter;
if (msg->command == RPCCOMMAND_STIM) {
if (partiter % 2 == 0 && cadjpart[0] > cadjpart[1]) { ++synciter; }
if (partiter % 2 == 1 && cadjpart[1] > cadjpart[0]) { ++synciter; }
}
// Apply Stimuli (with offset)
if (msg->nrpcdata > 0) {
idx_t stimtype = (idx_t) msg->rpcdata[0];
// per neuron
if (stimtype == RPCSTIM_POINT) {
idx_t numvtx = (idx_t) msg->rpcdata[1];
idx_t pulses = (idx_t) msg->rpcdata[2];
// build stim event
evtrpc.resize(pulses*2);
for (idx_t i = 0; i < pulses; ++i) {
evtrpc[i*2 ].diffuse = ((tick_t) synciter*tstep) + ((tick_t) msg->rpcdata[3+numvtx+i*3]*TICKS_PER_MS);
evtrpc[i*2+1].diffuse = evtrpc[i*2].diffuse + ((tick_t) msg->rpcdata[3+numvtx+i*3+1]*TICKS_PER_MS);
evtrpc[i*2 ].type = EVENT_STIM;
evtrpc[i*2+1].type = EVENT_STIM;
evtrpc[i*2 ].source = -1;
evtrpc[i*2+1].source = -1;
evtrpc[i*2 ].index = 0;
evtrpc[i*2+1].index = 0;
evtrpc[i*2 ].data = msg->rpcdata[3+numvtx+i*3+2];
evtrpc[i*2+1].data = -msg->rpcdata[3+numvtx+i*3+2];
}
// add events to vertices
for (idx_t i = 3; i < 3 + numvtx; ++i) {
std::unordered_map<idx_t, idx_t>::iterator target = vtxmap.find((idx_t) msg->rpcdata[i]);
if (target != vtxmap.end()) {
for (size_t e = 0; e < evtrpc.size(); ++e) {
evtrpc[e].source -= (idx_t) msg->rpcdata[i];
if ((evtrpc[e].diffuse/tstep - synciter) < nevtday) {
evtcal[target->second][(evtrpc[e].diffuse/tstep)%nevtday].push_back(evtrpc[e]);
}
else {
evtcol[target->second].push_back(evtrpc[e]);
}
}
}
}
}
// circle
else if (stimtype == RPCSTIM_CIRCLE) {
}
else if (stimtype == RPCSTIM_SPHERE) {
}
}
// Resync if necessary
if (msg->command == RPCCOMMAND_PSTIM) {
//thisProxy(prtidx).CycleNetwork();
cyclepart.send();
}
}
// YARP Port Streams
//
else if (msg->command == RPCCOMMAND_OPEN) {
// Coordinate the syncronization iteration
synciter = iter;
// Resync
//thisProxy(prtidx).CycleNetwork();
cyclepart.send();
}
else if (msg->command == RPCCOMMAND_CLOSE) {
// Coordinate the syncronization iteration
synciter = iter;
// Resync
//thisProxy(prtidx).CycleNetwork();
cyclepart.send();
}
// cleanup
delete msg;
}
#endif //STACS_WITH_YARP