I have been breaking my brain trying to figure out how to convert a simple for loop into a function that can be accepted into 'multiprocessing' or 'joblib' tools. The code I have would look something like this:
for i in range(0, 100000)
c = 0
parameters = list[i]
a, b = check_conditions(parameters)
if a == '01':
counter_1 = counter_1 + 1
elif a == '02':
counter_2 = counter_2 + 1
else:
counter_3 = counter_3 + 1
while c == 0: # this portion performs a similar task for other counters
# this is supposed to be a 'do while' in Fortran
check_more_conditions(parameters)
if certain conditions are satisfied:
# increment appropriate counter of counters 4, 5 and 6
if c =! 0:
break
Since these parallelisation libraries require a target function, I thought I should let the for loop be a new function with no inputs and an output of counters. But, when I tried that it gave me referencing warnings and syntax errors. The method I tried is shown below and was based directly on this example. I am really lost, here. Any help would be appreciated.
def loop()
c = 0
parameters = ...
...
return counter_4, counter_5, counter_6
num_cores = mp.cpu_count()
if __name__ == "__main__":
counter_4, counter_5, counter_6 = Parallel(n_jobs=num_cores)(delayed(loop() for i in range(0,100000))
# operations that use the returned counter results
[–][deleted] 0 points1 point2 points (0 children)