|
37 | 37 | import numpy
|
38 | 38 | import os
|
39 | 39 | import os.path
|
| 40 | +import multiprocessing |
40 | 41 |
|
41 | 42 | from rmgpy.quantity import Quantity, constants
|
42 | 43 | import rmgpy.species
|
@@ -552,6 +553,17 @@ def __init__(self, species=None, reactions=None):
|
552 | 553 |
|
553 | 554 | ################################################################################
|
554 | 555 |
|
| 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 | + |
555 | 567 | class CoreEdgeReactionModel:
|
556 | 568 | """
|
557 | 569 | Represent a reaction model constructed using a rate-based screening
|
@@ -606,6 +618,7 @@ def __init__(self, core=None, edge=None):
|
606 | 618 | self.reactionCounter = 0
|
607 | 619 | self.newSpeciesList = []
|
608 | 620 | self.newReactionList = []
|
| 621 | + self.pool = None |
609 | 622 |
|
610 | 623 | def checkForExistingSpecies(self, molecule):
|
611 | 624 | """
|
@@ -853,6 +866,11 @@ def enlarge(self, newObject, database):
|
853 | 866 | numOldEdgeReactions = len(self.edge.reactions)
|
854 | 867 |
|
855 | 868 | 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,)) |
856 | 874 |
|
857 | 875 | if isinstance(newObject, Species):
|
858 | 876 |
|
@@ -908,8 +926,13 @@ def enlarge(self, newObject, database):
|
908 | 926 |
|
909 | 927 | # Generate thermodynamics of new species
|
910 | 928 | 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) |
913 | 936 |
|
914 | 937 | # Update unimolecular (pressure dependent) reaction networks
|
915 | 938 | if settings.pressureDependence:
|
|
0 commit comments