I am looking for help since it seems I can't find any solutions.
The task I am interested in is to diagonalize (large) matrices that depend on a parameter (let's call it m
). I first did the calculations on my Mac laptop by using a simple for
loop and it seems to use all the availbale cores (4) by default. But now I want to do the same thing on my Linux machine (Ubuntu 18.04) with 16 cores but due to the GIL, the program only uses one core.
First question, is the difference coming from the Mac Python interpreter or the linear algebra libraries used by numpy/scipy that are automatically parallelized on Mac and not on Linux? For the moment, I didn't look into the library (LAPACK, BLAS) problem.
Then, using Python's multiprocessing
, I have no problems doing it but where I am stuck is the data structure. Indeed, for all these matrices, I need both the eigenvalues and eigenvectors (and the m
label but the order of inputs is automatically kept) but due to the structure of pool.map
(or pool.starmap
in the case of multiple arguments) I can't seem to find the most efficient way of collecting the whole set of eigenvalues and eigenvectors.
Do you have any idea of how to do it or any good reference? I would appreciate help on this BLAS/LAPACK issue too.
Thanks in advance,
PS : see below for a naive code sample.
def Diagonalize(m):
Mat = np.array([[0, m+1],[m+1, 0]])
eigenvalues, eigenvectors = np.linalg.eigh(Mat)
return list([eigenvalues, eigenvectors]) # using list() was one of my attempts
Nprocesses = 4 # or whatever number
if __name__ == '__main__':
with Pool(processes = Nprocesses) as pool:
pool.map(Diagonalize, m_values) # EDIT m_values being whatever list