I am trying to parallelize my code. The parallelization formalism is new to me.
I am performing a parameter sweep on 17 parameters. For each parameter, I settled in a vector the 3 values I wanted to sweep. Here is the nested looping code I was using:
Code: Select all
proc batrun() { local i, j ,k,l,m,n, p, q, r, s, t, u, h,z, a, b, c
for i=0,2{
NetCon[1].weight = wE.x[i] //E->I
for j=0,2{
NetCon[0].weight = wI.x[j] //I_>E
for k = 0,2 {
Exp2Syn[0].tau1 = t1E.x[k]
for l = 0,2 {
Exp2Syn[0].tau2 = t2E.x[l]
for m = 0,2 {
is[0].tau1 = t1I.x[m]
for n = 0,2 {
is[0].tau2 = t2I.x[n]
for p = 0,2 {
somaI.gna_pnas = vna.x[p]
for q = 0,2 {
somaI.gkdr_pkdrs = vk.x[q]
for r = 0,2 {
somaI.gk_leak = lk.x[r]
for s = 0,2 {
somaI.gna_leak = lna.x[s]
for t = 0,2 {
somaI.gfix_leak = lfixi.x[t]
for u = 0,2 {
somaE.gcl_clleak = lcl.x[u]
for h = 0,2 {
somaE.gfix_clleak = lfixe.x[h]
for z = 0,2 {
somaE.tau_pump_pumpcltau = tclp.x[z]
for a = 0,2 {
somaI.tau_pump_pumpnatau2 = tnap.x[a]
for b = 0,2 {
somaE.ipumpmax_pumpcltau = maxclp.x[b]
for c = 0,2 {
somaI.ipumpmax_pumpnatau2 = maxnap.x[c]
run()
calclabel(i,j,k,l,m,n, p, q, r, s, t, u, h,z, a, b, c)
postvoltage()
}}}}}}}}}}}}}}}}}
proc sweep(){
instrum() //create vector where to save time course of v and currents in somaE and somaI
savedata() //create folders and files where to save the output
setparam() // create vectors of 3 values for each of the 17 parameters I want to sweep
batrun()
}
}
Code: Select all
strdef cmd
proc calclabel() {
sprint(cmd,"%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d\n",$1,$2,$3,$4,$5,$6, $7, $8, $9, $10, $11, $12, $13,$14, $15, $16, $17)
}
Code: Select all
// to record spike times
objref nccI,nccE, spveccI,spveccE, nilcI,nilcE
somaI nccI = new NetCon(&v(0.5), nilcI)
somaE nccE = new NetCon(&v(0.5), nilcE)
nccI.threshold = -20 // mV
nccE.threshold = -20
spveccI = new Vector()
nccI.record(spveccI)
spveccE = new Vector()
nccE.record(spveccE)
proc postvoltage() { local nspikesI, t1I, t2I,nspikesE, t1E, t2E
nspikesI = spveccI.size() //E
nspikesE = spveccE.size() //I
if (nspikesE == 0) {
f1.aopen(fa)
f1.printf("%s\n",cmd)
f1.close()
}
if (nspikesI == 0) {
f5.aopen(fe)
f5.printf("%s\n",cmd)
f5.close()
}
if (nspikesE == 1) {
calcolaE()
f2.aopen(fb)
f2.printf("%s \t%g \t%g\n",cmd,maxVE.x(0),hWE.x(0) )
f2.close()
}
if (nspikesI == 1) {
calcolaI()
f6.aopen(ff)
f6.printf("%s \t%g \t%g\n",cmd,maxVI.x(0),hWI.x(0))
f6.close()
}
if (nspikesE > 1) {
calcolaE()
calinterspikeE()
f3.aopen(fc)
for i=0,hWE.size()-1 {
f3.printf("%s \t%g \t%g\n",cmd, maxVE.x(i),hWE.x(i))
}
f3.close()
f4.aopen(fd)
for i=0,isivecE.size()-1 {
f4.printf("%s \t%g \t%gn",cmd,isivecE.x(i))
}
f4.close()
}
if (nspikesI > 1) {
calcolaI()
calinterspikeI()
f7.aopen(fg)
for i=0,hWI.size()-1 {
f7.printf("%s \t%g \t%g\n",cmd,maxVI.x(i),hWI.x(i))
}
f7.close()
f8.aopen(fh)
for i=0,isivecI.size()-1 {
f8.printf("%s \t%g\n",cmd,isivecI.x(i))
}
f8.close()
}
}
https://www.neuron.yale.edu/ftp/ted/neu ... zation.zip
I tried to parallelize the code considering only one parameter, once the code will work I will also insert the others. Here is where I arrived so far...
Code: Select all
// after cell model specification I create ParallelContext instance
objref pc
pc = new ParallelContext()
// then I specify the stimolus and simulatoions parameters
// I modify the postvoltage processes ( I am not writing on the files anymore here)
proc postvoltage() { local nspikesI, t1I, t2I,nspikesE, t1E, t2E
nspikesI = spveccI.size() //E
nspikesE = spveccE.size() //I
if (nspikesE == 1) {
calcolaE()
}
if (nspikesI == 1) {
calcolaI()
}
if (nspikesE > 1) {
calcolaE()
calinterspikeE()
}
if (nspikesI > 1) {
calcolaI()
calinterspikeI()
}
}
proc setlopar(){ local i
for i=0,2{
NetCon[1].weight = wE.x[i] //E->I
}}
func fi() {
instrum()
//savedata() // I should not create folders and files here, right?
setlopar($1)
run()
calclabel($1)
print cmd
postvoltage()
}
trun = startsw()
pc.runworker()
objref svec
proc batchrun() { tmp
svec = new Vector()
pc.submit("fi") // post all jobs to bulletin board
while (pc.working) {
pc.unpack(&tmp)
svec.append(tmp) // get job number
printf(".") // indicate progress
}
}
batchrun()
pc.done()
// I should here rearrange the output of each job and save the results in files
print " "
print startsw() - trun, "seconds" // report run time
quit()