PythonMultiprocessingusing multiprocessing.Pool
import multiprocessing
import numpy as np
import random
import os
def one_experiment(seed=0):
# set seed
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
return np.random.normal(0, 1, 1)
if __name__ == '__main__':
experiment_num = 5
core_num = 2
with multiprocessing.Pool(processes=core_num) as pool:
results = pool.map(one_experiment, list(range(experiment_num)))
print(results)
Memory profilerhttps://pypi.org/project/memory-profiler/ This profiler works for both Python program and any other types of programs, and it can count the memory usage for each thread. |