-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathring.hoc
94 lines (84 loc) · 1.74 KB
/
ring.hoc
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
{load_file("cell.hoc")}
begintemplate Ring
public cells, nclist, stim, ncstim, tvec, idvec
objref cells, nclist, stim, ncstim, tvec, idvec
objref pc
proc init() {
pc = new ParallelContext()
ncell = $1
delay = $2
mkring()
mkstim()
spike_record()
}
proc mkring() {
mkcells()
connectcells()
}
iterator pcitr() {local i
for (i = pc.id; i < ncell; i += pc.nhost) {
$&1 = i
iterator_statement
}
}
proc mkcells() {local i localobj cell, nc, nil
cells = new List()
for pcitr(&i) {
cell = new B_BallStick()
cells.append(cell)
pc.set_gid2node(i, pc.id)
nc = cell.connect2target(nil)
pc.cell(i, nc)
}
}
proc connectcells() {local i, targid localobj target, syn, nc
nclist = new List()
for i=0, ncell-1 {
targid = (i+1)%ncell
if (pc.gid_exists(targid)) {
target = pc.gid2cell(targid)
syn = target.synlist.o(0)
nc = pc.gid_connect(i, syn)
nclist.append(nc)
nc.delay = delay
nc.weight = 0.01
}
}
}
proc mkstim() {
if (pc.gid_exists(0)) {
stim = new NetStim()
stim.number = 1
stim.start = 0
ncstim = new NetCon(stim, pc.gid2cell(0).synlist.o(0))
ncstim.delay = 0
ncstim.weight = 0.01
}
}
proc spike_record() {local i
tvec = new Vector()
idvec = new Vector()
for pcitr(&i) {
pc.spike_record(i, tvec, idvec)
}
}
endtemplate Ring
func runring() {local id, n, spkcnt, tmax, idmax localobj ring, tt, idv, pc
id = hoc_ac_
ring = new Ring($1, $2)
pc = new ParallelContext()
pc.set_maxstep(10)
stdinit()
pc.psolve($3)
n = ring.tvec.size
spkcnt = pc.allreduce(n, 1)
tmax = pc.allreduce(ring.tvec.x[n-1], 2)
tt = new Vector()
idv = new Vector()
pc.allgather(ring.tvec.x[n-1], tt)
pc.allgather(ring.idvec.x[n-1], idv)
idmax = idv.x[tt.max_ind]
pc.post(id, spkcnt, tmax, idmax)
pc.gid_clear()
return id
}