Page 1 of 1

Several pyNEURON simulations via multiprocessing

Posted: Wed Jan 13, 2010 5:50 am
by PhilippRautenberg
Hello everybody,

I would like to run several NEURON simulations in parallel on distinct processes with help of the `multiprocessing` module:

Code: Select all

from multiprocessing import Process, Lock
from random import random as rand
import time

def myFunction(l, idx):
    import neuron as n
    sec = n.h.Section()
    number =  int((rand()) * 10)
    time.sleep(number)
    toc = time.time()
    l.acquire(block=True, timeout=None)
    print 'Number %s slept for %s (~%s ?) seconds (%s)' %(
        idx, toc-tic, number, sec.name) 
    l.release()

if __name__ == '__main__':
    # use `Lock` in order to ensure that only one process prints to standard
    # output at a time
    lock = Lock()
    ps = []
    tic = time.time()
    for idx in range(10):
        p = Process(target=myFunction, args=(lock, idx))
        p.start()
        ps.append(p)
    for p in ps:
      p.join()
    print "done"
The code runs fine and the neuron-module seems to be imported for each process, the processes run in parallel (see time). BUT the section is just created once (see address). Why is that? Is there a way to start the simulations in parallel processes other than via shell?

Cheers, Philipp

Re: Several pyNEURON simulations via multiprocessing

Posted: Wed Feb 03, 2010 8:56 pm
by hines
I believe that the identity of the addresses being the same may not be an indication that 10
sections were not independently created in 10 processes. At least it has nothing to
do with NEURON since adding myFunction to the list of things to print also prints identical
addresses for that. To prove that there are not in fact 10 independent processes with independent
address spaces you will have to do enough computation to establish that they interfere with
each other.