Multi threaded Python example in Slurm
#!/usr/bin/env python
import numpy as np
import multiprocessing as mp
if __name__ == '__main__':
np.random.seed(0);
# create two matrices to be passed
# to two different processes
mat1 = np.random.rand(3,3);
mat2 = np.random.rand(2,2);
# define number of processes
ntasks = 2;
# create a pool of processes
p = mp.Pool(ntasks);
# feed different process with same task
# but different data and print the result
print(p.map(np.linalg.eigvals, [mat1, mat2]))