I am using
scipy.sparse.linalg.bicgstab to solve Ax=b. I observed my CPU usage sometimes is around 50%. My CPU is Intel(R) Xeon(R) CPU E3-1245 V2@3.40GHZ which has 4 cores and 8 logical processors. I would like to know whether those two functions I use is multithread/multiprocessor, since if it is single thread/core, the CPU usage should be around 12.5%, right?
My code is below:
import scipy.sparse.linalg as spla import scipy import scipy.io as io import numpy as np import time from scipy.sparse import csr_matrix f="memplus.mtx" A=io.mmread(f) x=np.ones(A.shape)*0.99 b = np.dot( A.todense(), np.ones(A.shape) ) lu=spla.spilu(A=A) M_x = lambda x: lu.solve(x) ndim = x.shape M = scipy.sparse.linalg.LinearOperator((ndim, ndim), M_x) a, info=spla.bicgstab(A, b.T, x0=x, tol=1e-12, maxiter=10000, M=M)Answer1:
These routines are not themselves parallelized. However, if you are using a multithreaded BLAS library such as ATLAS or Openblas, which is likely, several linear algebra operations in the routines are parallelized. Therefore, they benefit from multiple cores.Answer2:
@p.v is correct. You must link scipy/numpy to a multithreaded blas library to take advantage of your multiple cores.
On a side note, I'm assuming that you are using Linux. Within Linux, when watching CPU utilization, the percentage you see is per core. 50% would mean that half of one core is being used. If you have 8 cores, then you should see CPU usage around 800% if all 8 are being used fully.