Skip to content

Commit 92093d5

Browse files
committed
A new attempt at multiprocessing when generating thermo data.
A recent run spent quite a lot of time generating thermo data, and this seems reasonably parallelizable (each species is independent). The overheads may still be large, but this is a start to try experimenting with.
1 parent 9dc2df7 commit 92093d5

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

rmgpy/rmg/model.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import numpy
3838
import os
3939
import os.path
40+
import multiprocessing
4041

4142
from rmgpy.quantity import Quantity, constants
4243
import rmgpy.species
@@ -552,6 +553,17 @@ def __init__(self, species=None, reactions=None):
552553

553554
################################################################################
554555

556+
## for multiprocessing pools
557+
def initializer(database):
558+
global __database
559+
__database = database
560+
print "Setting global database in {0}".format(multiprocessing.current_process().name)
561+
def makeThermoForSpecies(spec):
562+
global __database
563+
#logging.info("Generating thermo for {0} on {1}".format(spec.label,multiprocessing.current_process().name))
564+
spec.generateThermoData(__database)
565+
return spec.thermo
566+
555567
class CoreEdgeReactionModel:
556568
"""
557569
Represent a reaction model constructed using a rate-based screening
@@ -606,6 +618,7 @@ def __init__(self, core=None, edge=None):
606618
self.reactionCounter = 0
607619
self.newSpeciesList = []
608620
self.newReactionList = []
621+
self.pool = None
609622

610623
def checkForExistingSpecies(self, molecule):
611624
"""
@@ -853,6 +866,11 @@ def enlarge(self, newObject, database):
853866
numOldEdgeReactions = len(self.edge.reactions)
854867

855868
pdepNetwork = None
869+
870+
# Set up pool of worker processes (number depends on number of cores)
871+
# and set each with the database
872+
if self.pool is None:
873+
self.pool = multiprocessing.Pool(initializer=initializer,initargs=(database,))
856874

857875
if isinstance(newObject, Species):
858876

@@ -908,8 +926,13 @@ def enlarge(self, newObject, database):
908926

909927
# Generate thermodynamics of new species
910928
logging.info('Generating thermodynamics for new species...')
911-
for spec in self.newSpeciesList:
912-
spec.generateThermoData(database)
929+
outputs = self.pool.map(makeThermoForSpecies, self.newSpeciesList)
930+
for spec, thermo in zip(self.newSpeciesList, outputs):
931+
spec.thermo = thermo
932+
#pool.close()
933+
#assert all(outputs)
934+
#for spec in self.newSpeciesList:
935+
# spec.generateThermoData(database)
913936

914937
# Update unimolecular (pressure dependent) reaction networks
915938
if settings.pressureDependence:

0 commit comments

Comments
 (0)