Changeset 2441


Ignore:
Timestamp:
Mar 12, 2010 11:43:43 AM (9 years ago)
Author:
jwatson
Message:

"Manually" controlling garbage collection in PH - Python does it stupidly and too often. Basically, there isn't any real good reason to do it more frequently than after every PH iteration, which is what I am now doing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/ph.py

    r2406 r2441  
    2323import types
    2424import pickle
     25import gc
    2526from math import fabs, log, exp
    2627
     
    11121113         raise RuntimeError, "PH is not initialized - cannot invoke solve() method"
    11131114
     1115      # garbage collection noticeably slows down PH when dealing with
     1116      # large numbers of scenarios. fortunately, there are well-defined
     1117      # points at which garbage collection makes sense (and there isn't a
     1118      # lot of collection to do). namely, after each PH iteration.
     1119      re_enable_gc = gc.isenabled()
     1120      gc.disable()
     1121
    11141122      print "Initiating PH iteration=" + `self._current_iteration`
    11151123
     
    11591167         self.checkpoint(0)
    11601168
     1169      # garbage-collect if it wasn't disabled entirely.
     1170      if re_enable_gc is True:
     1171         gc.collect()
     1172
    11611173      # there is an upper bound on the number of iterations to execute -
    11621174      # the actual bound depends on the converger supplied by the user.
     
    12321244         if i == self._max_iterations:
    12331245            print "Halting PH - reached maximal iteration count="+str(self._max_iterations)
     1246
     1247         # garbage-collect if it wasn't disabled entirely.
     1248         if re_enable_gc is True:
     1249            gc.collect()
     1250
     1251      # re-enable the normal garbage collection mode.
     1252      if re_enable_gc is True:
     1253         gc.enable()
    12341254
    12351255      if self._verbose is True:
Note: See TracChangeset for help on using the changeset viewer.