--- title: multirun keywords: fastai sidebar: home_sidebar nb_path: "09_utils_multirun.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

parallel_run[source]

parallel_run(func, args, thread=10)

{% endraw %} {% raw %}
{% endraw %} {% raw %}
def self_print(a):
    print('only one args:'+a+'\n')
    return f'{a}_only_one'

def self_print2(a,b):
    print('more than one args:'+a+','+b+'\n')
    return f'{a}_is_one_and_{b}_is_another_one'
{% endraw %} {% raw %}
args=[f'{i}_arg' for i in range(10)]
args2=[[f'{i}_a',f'{i}_b'] for i in range(10)]
{% endraw %} {% raw %}
args
['0_arg',
 '1_arg',
 '2_arg',
 '3_arg',
 '4_arg',
 '5_arg',
 '6_arg',
 '7_arg',
 '8_arg',
 '9_arg']
{% endraw %} {% raw %}
args2
[['0_a', '0_b'],
 ['1_a', '1_b'],
 ['2_a', '2_b'],
 ['3_a', '3_b'],
 ['4_a', '4_b'],
 ['5_a', '5_b'],
 ['6_a', '6_b'],
 ['7_a', '7_b'],
 ['8_a', '8_b'],
 ['9_a', '9_b']]
{% endraw %} {% raw %}
results=parallel_run(self_print,args)
print(results)
only one args:2_arg
only one args:1_arg
only one args:0_arg
only one args:7_arg
only one args:3_arg
only one args:4_arg
only one args:5_arg
only one args:8_arg
only one args:9_arg
only one args:6_arg










['0_arg_only_one', '1_arg_only_one', '2_arg_only_one', '3_arg_only_one', '4_arg_only_one', '5_arg_only_one', '6_arg_only_one', '7_arg_only_one', '8_arg_only_one', '9_arg_only_one']
{% endraw %} {% raw %}
results=parallel_run(self_print2,args2)
print(results)
more than one args:0_a,0_b
more than one args:1_a,1_b
more than one args:2_a,2_b
more than one args:5_a,5_b
more than one args:7_a,7_b
more than one args:4_a,4_b
more than one args:8_a,8_b
more than one args:3_a,3_b
more than one args:6_a,6_b
more than one args:9_a,9_b










['0_a_is_one_and_0_b_is_another_one', '1_a_is_one_and_1_b_is_another_one', '2_a_is_one_and_2_b_is_another_one', '3_a_is_one_and_3_b_is_another_one', '4_a_is_one_and_4_b_is_another_one', '5_a_is_one_and_5_b_is_another_one', '6_a_is_one_and_6_b_is_another_one', '7_a_is_one_and_7_b_is_another_one', '8_a_is_one_and_8_b_is_another_one', '9_a_is_one_and_9_b_is_another_one']
{% endraw %}