Package bpm :: Module parallel
[hide private]
[frames] | no frames]

Source Code for Module bpm.parallel

 1  """ 
 2  'parallel.py' is a set of functions that make parallelizing functions much  
 3  easier. Namely, a 'pmap' function that will use the single-threaded version if  
 4  parallelization isn't available. 
 5  """ 
 6  import math 
 7  import multiprocessing as mp 
 8  import sys 
 9   
10  from bpm import conf 
11   
12  # The total number of "steps" to generate a set of BPMs 
13  steps = 10000000 
14   
15  # Costs of various things to make progress bar a little more accurate 
16  costs = { 'load_genes': 50, 
17          } 
18   
19  # A shared global variable used for visual progress 
20  counter = mp.Value('i', 0) 
21   
22 -def pmap(*args, **kargs):
23 ''' 24 This is a convenient wrapper function that will parallelize a map function 25 if the capability exists. It degrades to a regular map function if not. 26 ''' 27 if conf.processes > 1: 28 return mp.Pool(processes=conf.processes).map(*args, **kargs) 29 else: 30 return map(*args, **kargs)
31 59
60 -def inc_counter(incby=1):
61 ''' 62 Each unit this counter is increased by represents a "step" in the program. 63 It is then used to show a progress bar. 64 ''' 65 counter.value += incby
66
67 -def get_counter():
68 ''' 69 Simple accessor. 70 ''' 71 return counter.value
72