Several pyNEURON simulations via multiprocessing

When Python is the interpreter, what is a good
design for the interface to the basic NEURON

Moderator: hines

Post Reply
Posts: 15
Joined: Wed Dec 06, 2006 10:53 am

Several pyNEURON simulations via multiprocessing

Post 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)
    toc = time.time()
    l.acquire(block=True, timeout=None)
    print 'Number %s slept for %s (~%s ?) seconds (%s)' %(
        idx, toc-tic, number, 

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))
    for p in ps:
    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

Site Admin
Posts: 1600
Joined: Wed May 18, 2005 3:32 pm

Re: Several pyNEURON simulations via multiprocessing

Post 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.

Post Reply