I would like to parallelize some pieces of a code which has this form:
function1 (arg1.1, arg1.2):
estimate some model and return it
function2 (arg2.1, arg2.2, arg2.3):
prepare some stuff
quality=[]
for i in range(1,len(previously prepared stuff):
model=function1(arg1.1=arg2.1, arg1.2=some_other_prepared_stuff_from_function2)
q=calculate some quality criterion
quality.append[q]
return(quality)
Instead of the for loop, I would like to use parallelization, but I don't know how to do this because function1 is called within function2 and the for loop iterates over the length of an object which I prepare beforehand in function2. This "prepared stuff" cannot be parallelized.
The order in quality should be kept.
I'm working on a Linux Server and it would be helpful to set the number of cores which can be used.
I know the multiprocessing
package, but I don't know how to use it on my code, as I'm rather a beginner in Python.
Some help would be great!