我正在使用 Python Multiprocessing 模块多次对角化(大而稀疏)矩阵。我必须这样做一千次,所以决定在多处理中进行,因为我有 24 个内核。
代码如下:
import numpy as np
from scipy.sparse.linalg import eigsh
from scipy import sparse
def diag(param):
wf, vf = 0, 0
for i in range(10000):
num = np.random.rand()
.... # unrelated code producing the matrix with param and num
Mat = sparse.csc_matrix((data, (row, col)), shape=(8000, 8000))
w, v = eigsh(Mat, k=12)
.... #some other unrelated process updating wf and vf using w and v
return wf, vf
def Final(temp):
print("Process " % multiprocessing.current_process().name)
print(temp)
np.random.seed() …Run Code Online (Sandbox Code Playgroud)