-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#imp_bench_core_neuron_main.hoc#
378 lines (325 loc) · 10.8 KB
/
#imp_bench_core_neuron_main.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
//{chdir("./hoc/bench")}
{load_file("nrngui.hoc")}
load_file("stdrun.hoc")
CACHE_EFFICIENT=1
if (!name_declared("MODEL")) { MODEL=0 }
if (!name_declared("NSTIM_POS")) { NSTIM_POS=1 }
if (!name_declared("NSTIM_NUM")) { NSTIM_NUM=2 }
if (!name_declared("NCELLS")) { NCELLS=2 }
if (!name_declared("NSYNAPSE")) { NSYNAPSE=2 }
if (!name_declared("SYNAPSE_RANGE")) { SYNAPSE_RANGE=1 }
if (!name_declared("STOPTIME")) { STOPTIME=100 }
if (!name_declared("NETWORK")) { NETWORK=0 }
if (!name_declared("NTHREAD")) { NTHREAD=1 }
if (!name_declared("MULTISPLIT")) { MULTISPLIT=0 }
if (!name_declared("SPIKE_COMPRESS")) { CACHE_EFFICIENT=1 }
if (!name_declared("SPIKE_COMPRESS")) { SPIKE_COMPRESS=1 }
if (!name_declared("SHOW_SPIKE")) { SHOW_SPIKE=1 }
if (!name_declared("DBG_PRINT")) { DBG_PRINT=1 }
printf("STOPTIME=%lf\n",STOPTIME)
print STOPTIME
{load_file("CellTemplate_BN_1056_Parallel3.hoc")}
{load_file("CellSwc2_nrn8.hoc")}
{load_file("CellTemplate_LineCell_091002.hoc")}
objref pc
objref cells, nclist
objref stim, ncstim, ncstimlist, stimlist, synlist
objref tvec, idvec
// core
// make sure NEURON is compiled with Python
// chk 1
// dt=0.025
// if(pc.id == 0){ printf("check1 * NSTEP=%d (STOPTIME=%lf / dt=%lf)\n", STOPTIME/dt, STOPTIME, dt)}
// dt is not defined
// if (!nrnpython("from neuron import coreneuron")) {
// printf("NEURON not compiled with Python support\n")
// return
// }
// access coreneuron module via Python object
//tstop = STOPTIME
// objref cvode
// cvode = new CVode()
// mode = cvode.cache_efficient(1)
objref py_obj
py_obj = new PythonObject()
nrnpython("from neuron import coreneuron")
//nrnpython("from strtobool import strtobool; import os")
//py_obj.coreneuron.enable = True
//nrnpython("from distutils.util import strtobool; import os; coreneuron.gpu=bool(strtobool(os.environ.get('CORENRN_ENABLE_GPU', 'false')))")
//nrnpython("from distutils.util import strtobool; import os; coreneuron.gpu=bool(strtobool(os.environ.get('CORENRN_ENABLE_GPU', 'false')))")
//printf("nrncore_arg: |%s|\n", py_obj.coreneuron.nrncore_arg(STOPTIME))
//printf("core neuron on.\n")
proc mkcells () { local i, n, j, num_cell localobj cell, nc, syn, nil
cells = new List()
tvec = new Vector()
idvec = new Vector()
nclist = new List()
synlist = new List()
num_cell = $1
n = int(num_cell/pc.nhost)
for(i=0; i<n; i+=1){
// cell = new Cell_BN_1056()
cell = new CellSwc("Swc_BN_1056.swc")
// cell = new Cell_Line(0,0,0,3000)
cells.append(cell)
pc.set_gid2node(i + (n * pc.id), pc.id)
nc = cell.makeNetCon(2500, nil, 0, 0, 1.0) //2500->2300
pc.cell(i + (n * pc.id), nc)
nc.delay = 0.1 // 0.6
nc.weight = 0.05
nc.record(tvec, idvec, nc.srcgid)
nclist.append(nc)
syn = cell.makeSyn(300, 1, 5, 0)
synlist.append(syn)
}
pc.barrier()
}
tmp_pre=0
tmp_post=0
proc connectcells(){ local i, target_id, network_type, num_cell, num_synapse, num_comp, synapse_range localobj src, target, syn, nc, cell, rnd, nil
pc.barrier()
num_cell = $1
network_type = $2
num_synapse = $3
synapse_range = $4
num_comp = 3800
rnd = new Random()
rnd.uniform(0, num_cell-1)
if(network_type == 0 || network_type == 1 || network_type==2){
for(i=0; i<num_cell; i=i+1){
if(pc.gid_exists(i)){
for(j=0; j<num_synapse; j=j+1){
cell = pc.gid2obj(i)
pc.set_gid2node(3.2e5+i*num_synapse+j, pc.id)
if(network_type==2){
nc = cell.makeNetCon((1+i*num_synapse+j)%num_comp, nil, 0, 0, 0.1)
}else{
nc = cell.makeNetCon(-1, nil, 0, 0, 0.1)
}
pc.cell(3.2e5+i*num_synapse+j, nc)
nclist.append(nc)
nc.delay = 0.5 // 0.6
nc.weight = 0.05
tmp_pre=tmp_pre+1
}
}
}
pc.barrier()
for(i=0; i<num_cell; i=i+1){
for(j=0; j<num_synapse; j=j+1){
if(network_type==0){
target_id = (1+i+j*synapse_range)%num_cell
}else if(network_type==1 || network_type==2){
target_id = int(rnd.repick())
}
if(pc.gid_exists(target_id) && i!=target_id){
target = pc.gid2cell(target_id)
if(network_type==2){
syn = target.makeSyn((100+i*num_synapse+j)%num_comp, 1, 5, 0)
}else{
syn = target.makeSyn(-1, 1, 5, 0)
}
nc = pc.gid_connect(32000000+i*num_synapse+j, syn)
nclist.append(nc)
nc.delay = 0.5 // 0.6
nc.weight = 0.05
synlist.append(syn)
tmp_post=tmp_post+1
}
}
}
}else{
printf("ERROR : invalid network type.\n")
quit()
}
}
proc setModel(){
model = $1
if(model==1){
forall { insert pas }
}else if(model==2){
forall { insert hh }
// }else if(model==3){
// forall {insert hh_euler }
// }else if(model==4){
// forall {insert hh_runge }
// }else if(model==5){
// forall {insert hh_impl }
// }else if(model==6){
// forall {insert hh_cnexp }
// }else if(model==7){
// forall {insert hh_runge_notable }
// }else if(model==8){
// forall {insert hh_cnexp_notable }
// }else if(model==9){
// forall {insert hh2CW }
// }else if(model==10){
// forall {insert hh2F }
// }else if(model==11){
// forall {insert hh2CW_many }
}else{
forall { insert hh }
}
}
proc print_stat() {
for i = 0, cells.count-1 {
printf("[proc:%02d] synlist %d\n", pc.id, cells.object(i).synlist.count())
}
}
// $1 : cell id for stimulate
proc mkstim() { local i, num_stim_pos, stim_cell, num_cell, num_stim
num_cell = $1
num_stim_pos = $2
num_stim = $3
ncstimlist = new List()
stimlist = new List()
for(i=0; i<num_stim; i=i+1){
stim_cell = i * (num_cell/(num_stim+1))
if(pc.gid_exists(stim_cell)){
//printf("[makestim:%d] CELL %d\n", pc.id, stim_cell)
stim = new NetStim()
stim.number = 10
stim.start = 0
stim.interval = 50
ncstim = new NetCon(stim, pc.gid2cell(stim_cell).synlist.object(0))
ncstim.delay = 1
ncstim.weight = 0.1
stimlist.append(stim)
ncstimlist.append(ncstim)
}
}
}
proc spikeout() { local i, count, rank localobj fobj, tmpmt
printf("check size spikeout\n")
printf("tvec size: %d, idvec size: %d\n", tvec.size(), idvec.size())
strdef filename
count = 0
fobj = new File()
tmpmt = new Matrix()
sprint(filename, "./result/spike_%010d.txt", pc.id)
fobj.wopen(filename)
fobj.printf("time [ms]\t cell_id\n")
if (tvec.size() > 0) {
tmpmt.resize(tvec.size(),2)
tmpmt.setcol(0, tvec)
tmpmt.setcol(1, idvec)
} else {
printf("Warning: tvec is empty, skipping matrix resize.\n")
}
tmpmt.fprint(0, fobj, "\t%g\t")
fobj.close
if(pc.id == 0){ printf("\n\ttime [ms]\t cell_id\n") }
pc.barrier()
for i=0, tvec.size()-1{
printf("SPIKE : \t %f\t %d\n", tvec.x[i], idvec.x[i])
}
}
proc printSpikeStat() { local nsendmax, nsend, nrecv, nrecv_useful
nsendmax = pc.spike_statistics(&nsend, &nrecv, &nrecv_useful)
printf("[%d] nsendmax=%d nsend=%d nrecv=%d nrecv_useful=%d\n", pc.id, nsendmax, nsend,nrecv, nrecv_useful)
}
// start main
{printf("main-STOPTIME=%lf\n",STOPTIME)
/// test coreneuron-2
// access coreneuron module via Python object
//py_obj.coreneuron.enable = 1
objref cvode
cvode = new CVode()
mode = cvode.cache_efficient(1)
// objref py_obj
py_obj = new PythonObject()
//py_obj.coreneuron.enable = 1
//0919 need?
//finitialize?
//stdinit()
//nrnpython("from neuron.tests.utils.strtobool import strtobool; import os; coreneuron.gpu=bool(strtobool(os.environ.get('CORENRN_ENABLE_GPU', 'false')))")
nrnpython("from distutils.util import strtobool; import os; coreneuron.gpu=bool(strtobool(os.environ.get('CORENRN_ENABLE_GPU', 'false')))")
nrnpython("coreneuron.gpu=bool(strtobool(os.environ.get('CORENRN_ENABLE_GPU', 'false')))")
printf("nrncore_arg: |%s|\n", py_obj.coreneuron.nrncore_arg(STOPTIME))
printf("core neuron on.\n")
// test end
// if(pc.id == 0){ printf("check2 * NSTEP=%d (STOPTIME=%lf / dt=%lf)\n", STOPTIME/dt, STOPTIME, dt)}
pc = new ParallelContext()
if(NTHREAD != 0){ pc.nthread(NTHREAD) }
if(SPIKE_COMPRESS==1){
if(pc.id ==0){ printf("pc.spike_compress(1, 0)\n") }
pc.spike_compress(1, 0)
}else if(SPIKE_COMPRESS==2){
pc.spike_compress(0, 1, 1)
}
printf("id %d",pc.id)
if(pc.id == 0){
printf("\nCondition : \n")
printf(" * Process=%d, Thread=%d\n", pc.nhost, NTHREAD)
printf(" * NSTEP=%d (STOPTIME=%lf / dt=%lf)\n", STOPTIME/dt, STOPTIME, dt)
printf(" * Model=%s, nCELLS=%d, nSYNAPSE=%d\n", "BN_1056", NCELLS, NSYNAPSE)
printf(" * NSTIM_POS=%d, NSTIM_NUM=%d, SYNAPSE_RANGE=%d\n", NSTIM_POS, NSTIM_NUM, SYNAPSE_RANGE)
printf(" * CacheEfficient=%d, SpikeCompressMode=%d\n\n", CACHE_EFFICIENT, SPIKE_COMPRESS)
printf("[id:0] start modeling\n")
}
start_time = pc.time
mkcells(NCELLS)
printf("mkcell-finished\n")
connectcells(NCELLS, NETWORK, NSYNAPSE, SYNAPSE_RANGE)
printf("connetcel-finished\n")
setModel(MODEL)
printf("setmode-finished\n")
//if(pc.id == 0){ print_stat() }
mkstim(NCELLS, NSTIM_POS, NSTIM_NUM)
// spikerecord()
pc.barrier()
//if(MULTISPLIT==1){ pc.multisplit() }
//if(CACHE_EFFICIENT==1){ pc.cache_efficient(1) }
//if(CACHE_EFFICIENT==1){ pc.multisplit() }
pc.set_maxstep(5)
{load_file("recorder.hoc")}
// setVoltageRecord()
spikerecord()
// tstop = STOPTIME
// stdinit()
// tstop = STOPTIME
if(pc.id == 0){ printf("[id:0] Modeling Finished.\n") }
if(pc.id == 0){ printf("[id:0] Calculation Starts\n") }
pc.barrier()
// print startsw()
modelfin_time = pc.time
start_waittime = pc.wait_time
if(pc.id == 0){startsw()}
if(pc.id == 0){
printf("pre-psolve\n")
printf("check3 * NSTEP=%d (STOPTIME=%lf / dt=%lf)\n", STOPTIME/dt, STOPTIME, dt)}
//0919 need?
//finitialize?
stdinit()
// start sim
pc.psolve(tstop)
if(pc.id == 0){ printf("[id:0] Calculation Finished !!\n") }
pc.barrier()
if(pc.id == 0){startsw()}
stop_time = pc.time
stop_waittime = pc.wait_time()
stop_steptime = pc.step_time()
stop_sendtime = pc.send_time()
// fprintVoltageRecord()
// fprintVoltageVecRecord()
pc.barrier()
if(pc.id ==0){
printf("\nRESULT : \n")
printf(" * SpikeSendMax=%d\n", pc.spike_statistics() )
printf(" * step=%lf sec, wait=%lf sec, send=%f sec\n", stop_steptime, stop_waittime-start_waittime, stop_sendtime)
printf(" * modeling time : %f sec\n", modelfin_time - start_time)
printf(" * core time : %f sec\n", stop_time-modelfin_time)
}
pc.barrier()
printf("[%d] NC = %d, SYN = %d, tmp_pre = %d, tmp_post = %d\n", pc.id, nclist.count(), synlist.count(), tmp_pre, tmp_post)
if(SHOW_SPIKE==1){ spikeout() }
printSpikeStat()
//quit()
//pc.max_histogram()
if(pc.id == 0){printf("finished all check")}
pc.runworker()
pc.done()
}
// change the place
//{chdir("../f_job")}
quit()