Multiproc example

In this example we demonstrate how to use the multiproc module to parallelize the computation of the function f(x) = x^2 + c.

[ ]:
# Imports and helper functions for examples.

import numpy as np

from skyllh.core.multiproc import parallelize


def f(x, c=0.0):
    return x**2 + c

Example

[2]:
args_list = [((x,), {'c': x}) for x in np.arange(1, 10, 1)]

res = parallelize(func=f, args_list=args_list, ncpu=3)

for argument, result in zip(args_list, res, strict=True):
    print(f'{argument} -> {result}')
100%|██████████| 9/9 [00:00<00:00, 340.90it/s]
((np.int64(1),), {'c': np.int64(1)}) -> 2
((np.int64(2),), {'c': np.int64(2)}) -> 6
((np.int64(3),), {'c': np.int64(3)}) -> 12
((np.int64(4),), {'c': np.int64(4)}) -> 20
((np.int64(5),), {'c': np.int64(5)}) -> 30
((np.int64(6),), {'c': np.int64(6)}) -> 42
((np.int64(7),), {'c': np.int64(7)}) -> 56
((np.int64(8),), {'c': np.int64(8)}) -> 72
((np.int64(9),), {'c': np.int64(9)}) -> 90