Skip to content

Instantly share code, notes, and snippets.

@mstimberg
Created March 19, 2020 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstimberg/fd8ccc63183c1f74e6d771be084f0a9b to your computer and use it in GitHub Desktop.
Save mstimberg/fd8ccc63183c1f74e6d771be084f0a9b to your computer and use it in GitHub Desktop.
Parallelization issues
from brian2 import *
# The following example is very contrived, but writing to a variable that is linked with repeating indices
# might come up in some contexts. It's clearly a cornercase, but one that we should handle.
set_device('cpp_standalone')
prefs.devices.cpp_standalone.openmp_threads = 8 # number of threads
group1 = NeuronGroup(2, 'x : integer')
group2 = NeuronGroup(1000, 'y : integer (linked)')
group2.y = linked_var(group1, 'x', index=np.arange(2).repeat(500))
obj = group2.run_regularly('y += 1')
run(defaultclock.dt)
print(group1.x[:])
# This should print "[500 500]", but will typically print lower numbers if the number of threads set
# above is > 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment