I am trying to print out all the possible outcomes of sets-sets3
values separated by elements with multi processing. The iterations tool gives out all the possible outcomes of the three values Lower,Upper,number-number3
. So for the first iteration Iteration(list_set, sets)
it will list all the numbers between (2,2,30)- (11,11,3520)
, all these values are being stored in sets-sets3
. With the multi processing tool I want to print out sets-sets3
elements asynchronously.
Getting all the possible outcomes:
from itertools import groupby
from itertools import accumulate
import itertools
from numpy import genfromtxt
import multiprocessing
def Iteration(a, b):
for element in itertools.product(*a):
b.append(element)
#Configs
Lower = [round(x * 0.5,1) for x in range(4,23)]
Upper = [round(x * 0.5,1) for x in range(4,23)]
#Number of days in chunks
number = [round(x*10,1) for x in range(3, 352)] #used for calculations with stand deriv and linear reg
number2 = [round(x*10,1) for x in range(352, 704)]
number3 = [round(x*10,1) for x in range(704, 1056)]
list_set = [Lower, Upper, number]
list_set2 = [Lower, Upper, number2]
list_set3 = [Lower, Upper, number3]
sets = []
sets2 = []
sets3 = []
#getting the iterations
Iteration(list_set, sets)
Iteration(list_set2, sets2)
Iteration(list_set3, sets3)
Implementing multi processing
def Setruns(set_number):
#function for going through all the configs
for element in set_number:
print("element 0:",element[0],"element 1:", element[1],"element 2:", element[2])
if __name__ == "__main__":
with multiprocessing.Pool(3) as pool: # 3 processes
run1, run2, run3 = pool.starmap(Setruns, [(sets),(sets2),(sets3)]) # map input & output
multiprocessing.Queue()
that you add your results into.starmap_async
what you want?