Note
Go to the end to download the full example code.
Parallel Processing¶
You should be able to treat models like any other function in terms of
parallelization. This example shows using the built-in multiprocessing
to do
process-based parallelization of an explicit system.
from multiprocessing import Pool
import condor
class Model(condor.ExplicitSystem):
x = input()
output.y = -x**2 + 2*x + 1
with Pool(5) as p:
models = p.map(Model, [1, 2, 3])
for model in models:
print(model.input, model.output)
ModelInput(x=1) ModelOutput(y=array([2.]))
ModelInput(x=2) ModelOutput(y=array([1.]))
ModelInput(x=3) ModelOutput(y=array([-2.]))
Total running time of the script: (0 minutes 0.240 seconds)