#!/usr/bin/env python
import multiprocessing
def tempx((the_time)):
return int(the_time)*int(the_time)
def tempy((the_time, foobar)):
return int(the_time)/(float(foobar))+100
def mp_handler():
p = multiprocessing.Pool(2)
foo = p.map(tempx, [('2')])
print foo
foo = p.map(tempy, [('100', '100000')])
print foo
if __name__ == '__main__':
mp_handler()
I have two methods with different input parameters. The first method with only: the_time and the second with the_time and foobar
I need the results in a particular order, and therefore I have used the map function. However, the above code does not use the multiprocess module at-all as i understand because i am using two map functions. am I right?
The end goal is to have two methods running simultaneously.
What am I missing here?
Dano, this is an exmaple of what i am doing
import multiprocessing
def print_timing(func):
def wrapper(*arg):
t1 = time.time()
res = func(*arg)
t2 = time.time()
print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0)
return res
return wrapper
@print_timing
def case_one(power_pred, power_core, num_thrs, possible_frequency, clamp_range):
ds1_cur_freq = list()
ds1_freq_index = list()
ds1_cur_clamp = list()
return ds1_cur_freq, ds1_freq_index, ds1_cur_clamp
@print_timing
def case_two(cpower_pred, power_core, num_thrs, possible_frequency, TT_index, DT_index, clamp_range):
ds2_cur_freq = list()
ds2_freq_index = list()
ds2_cur_clamp = list()
return ds2_cur_freq, ds2_freq_index, ds2_cur_clamp
def defs_finder():
cpower_pred = list()
power_pred = list()
power_core = list()
num_thrs = 3
possible_frequency = list()
clamp_range= list()
DT_index =1
TT_index = 0
p = multiprocessing.Pool(2)
#Case 1: DS1
# ds1_cur_freq, ds1_freq_index, ds1_cur_clamp =
ds1 = p.apply_async(case_one, args=(power_pred, power_core, num_thrs, possible_frequency))
#Case 1: DS1
# ds1_cur_freq, ds1_freq_index, ds1_cur_clamp = case_one(power_pred, power_core, num_thrs, possible_frequency, clamp_range)
#Case 2: DS2
# ds2_cur_freq, ds2_freq_index, ds2_cur_clamp = case_two(cpower_pred, power_core, num_thrs, possible_frequency, TT_index, DT_index, clamp_range)
ds2 = p.apply_async(case_two, args=(cpower_pred, power_core, num_thrs, possible_frequency, TT_index, DT_index))
print ds1
print ds2
print ds1.get()
print ds2.get()
# ds1_cur_freq = ds1.get()[0]
# ds1_freq_index = ds1.get()[1]
# ds1_cur_clamp = ds1.get()[2]
# ds2_cur_freq = ds2.get()[0]
# ds2_freq_index = ds2.get()[1]
# ds2_cur_clamp = ds2.get()[2]
defs_finder()
This is how it is implemented right now and the bug is reproduced