#!/usr/bin/env python3
from itertools import product
from multiprocessing import Pool
# 並列処理したい関数
def multi_test(arg1, arg2, arg3):
return(arg1+arg2+arg3)
# 並列数を決めて、Poolを用意
pool = Pool(3)
# 引数のバリエーションをタプルのリストで用意
multi_args = []
for iter1, iter2, iter3 in product(range(1,4), range(1,4), range(1,4)):
multi_args.append((iter1,iter2,iter3))
print(multi_args)
[(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 3, 1), (1, 3, 2), (1, 3, 3), (2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 3, 1), (2, 3, 2), (2, 3, 3), (3, 1, 1), (3, 1, 2), (3, 1, 3), (3, 2, 1), (3, 2, 2), (3, 2, 3), (3, 3, 1), (3, 3, 2), (3, 3, 3)]
# 並列処理実行
results = pool.starmap(multi_test, multi_args)
print(results)
[3, 4, 5, 4, 5, 6, 5, 6, 7, 4, 5, 6, 5, 6, 7, 6, 7, 8, 5, 6, 7, 6, 7, 8, 7, 8, 9]