Вот, например, суммирование элементов массива в несколько процессов (и без всяких C-расширений) :
# -*- coding: utf-8 -*-
import numpy
import multiprocessing
def sub_sum(z):
return numpy.sum(z)
def parallel_sum(values, cpuz):
boundaries = [i for i in range(0, len(values), len(values)//cpuz)]
boundaries[-1] = len(values)
with multiprocessing.Pool(cpuz) as pool:
rc = pool.starmap(sub_sum, [(values[c1:c2],) for c1, c2 in zip(boundaries[: -1], boundaries[1:])])
return sum(rc)
if __name__ == '__main__':
cpuz = multiprocessing.cpu_count()
n = 999
values = numpy.array([i for i in range(n)])
print('cpuz =', cpuz)
print('sum =', parallel_sum(values, cpuz))
print('sum =', n*(n-1)//2)