本文介绍了scipy.sparse软件包是否为多线程/多进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用scipy.sparse.linalg.spiluscipy.sparse.linalg.bicgstab来求解Ax = b.我观察到我的CPU使用率有时约为50%.我的CPU是Intel®Xeon®CPU E3-1245 [email protected],它具有4个内核和8个逻辑处理器.我想知道我使用的这两个函数是否是多线程/多处理器,因为如果是单线程/核心,则CPU使用率应该在12.5%左右,对吗?谢谢!

I am using scipy.sparse.linalg.spilu and 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 [email protected] 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?Thanks!

我的代码如下:

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[1])*0.99
b = np.dot( A.todense(), np.ones(A.shape[1]) ) 

lu=spla.spilu(A=A)

M_x = lambda x: lu.solve(x)

ndim = x.shape[0]
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)

推荐答案

@ p.v是正确的.您必须将scipy/numpy链接到多线程blas库,才能利用多个内核.

@p.v is correct. You must link scipy/numpy to a multithreaded blas library to take advantage of your multiple cores.

另一方面,我假设您正在使用Linux.在Linux中,当观察CPU使用率时,您看到的百分比是每个内核. 50%表示正在使用一个核心的一半.如果您有8个内核,那么如果全部8个内核都被完全使用,则应该看到大约800%的CPU使用率.

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.

这篇关于scipy.sparse软件包是否为多线程/多进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 20:50