bulletin board parallelization

General issues of interest both for network and
individual cell parallelization.

Moderator: hines

Post Reply
menica
Posts: 71
Joined: Wed Sep 02, 2015 11:02 am

bulletin board parallelization

Post by menica »

Hi,
I want to convert a code which performs simulations in series changing each run a parameter in a parallel simulation. I am using the ParallelContext to perform a bulletin board parallelization.
Here the serial code:

Code: Select all

//after the Model set up and simulation parameters 
//stimulus set up:
numeromax_estimulos=1000
objref stim[numeromax_estimulos]
for i=0, numeromax_estimulos-1{
psoma stim[i]=new IClamp(0.5)
}
stim[0].amp=3
stim[0].dur=1
stim[0].del=200
t_interp=0
num_estim=1

proc riordina(){
for i=1,num_estim-1{
stim[i].amp=stim[0].amp
stim[i].dur=stim[0].dur
stim[i].del=stim[0].del+(stim[0].dur+t_interp)*i
}
for i=num_estim,numeromax_estimulos-1{
stim[i].amp=0
} 
}

func round() {
  if ($1>0) {
    return int($1+0.5)
  } else {
    return int($1-0.5)
  }
}

// data recording and analysis
objref vvec, tvec, INA, IK, ICA, P
objref apic0
objref f1
strdef fa,pa,folder1,string1

proc instrum(){
tvec = new Vector()
tvec.record(&t) // record time
vvec = new Vector()
vvec.record(&L5PC.apic[0].v(0.5)) 
pa = "apic0"
f1 = new File()
}
//save in file in folder
proc savedata2() {
sprint(folder1, "%s", pa)
sprint(string1, "system(\"mkdir T-%s\")", folder1)
chdir("getcwd()")
execute(string1)
sprint(fa, "T-%s/%s_%d.dat", folder1, pa,$1)
	f1.wopen(fa)
	f1.printf("t L5PC.apic[0].v(0.5)\n") 
	f1.printf("%d\n",tvec.size())
	for i=0,tvec.size()-1 {
		f1.printf("%g %g\n", tvec.x(i), vvec.x(i)) 
	f1.close()
}
// to run
proc batrun2() { local i, freq
for i = 1,$1 { 
freq=i*$2
t_interp=(1-freq*stim[0].dur)/freq
num_estim=tstop/(t_interp+stim[0].dur)
num_estim=round(num_estim)
riordina()  
run()
savedata2(i)
}
}

proc exploreTint(){
instrum()
batrun2(5,0.001)
}
and here the parallel version:

Code: Select all

df=0.001
NRUNS = 5

func fsti() {
  return df*$1 
}

proc setparams() {
  freq = fsti($1)
  t_interp=(1-freq*stim[0].dur)/freq
  num_estim=tstop/(t_interp+stim[0].dur)
  num_estim=round(num_estim)
  riordina()  
}

// Simulation control

func fi() { // set params, execute a simulation, analyze and return results
  instrum()
  setparams($1) // set parameters for this run
  run()
  savedata2($1)
}

trun = startsw() 
{ pc.runworker() } // start execute loop on the workers

proc batchrun() { local ii, tmp
  for ii = 1, $1{
         pc.submit("fi", ii) // post all jobs to bulletin board
		}
    while (pc.working) { // if a result is ready, get it; if not, pick a job and do it
    printf(".") // indicate progress
  }
}

batchrun(NRUNS)
{ pc.done() }

print " "
print startsw() - trun, "seconds" // report run time
quit()
I have problems in write the correct code to run in parallel and to save the data as I did for the serial code, any help?
Thanks
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: bulletin board parallelization

Post by ted »

This file contains a complete example of how to do bulletin-board parallelization of a program that executes a family of simulations.
https://www.neuron.yale.edu/ftp/ted/neu ... zation.zip
The code and how to use it are described in the files bulletin_board_parallelization.html and walkthroughs.html
Be sure to read the relevant entries in the Programmer's Reference.
Post Reply