Fix multiprocessing example when using Python 3

In Python 3, 'map' returns an object which evalutes the function as it is
consumed, not when 'map' is called. Therefore, the correct comparison to
pool.map(...) is list(map(...)).
This commit is contained in:
Ray Speth 2015-08-03 23:00:54 -04:00
parent a79ee8e07a
commit ffb703ecfd

View file

@ -64,13 +64,13 @@ def serial(mech, predicate, nTemps):
P = ct.one_atm
X = 'CH4:1.0, O2:1.0, N2:3.76'
init_process(mech)
y = map(predicate,
zip(itertools.repeat(mech),
np.linspace(300, 900, nTemps),
itertools.repeat(P),
itertools.repeat(X)))
y = list(map(predicate,
zip(itertools.repeat(mech),
np.linspace(300, 900, nTemps),
itertools.repeat(P),
itertools.repeat(X))))
return y
if __name__ == '__main__':
# For functions where the work done in each subprocess is substantial,
# significant speedup can be obtained using the multiprocessing module.