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"
Cheers, Philipp