【发布时间】:2012-03-31 07:20:57
【问题描述】:
我正在尝试使用 python 和 scipy 使用线程来解决多个线性系统。当谈到 python 线程时,我是一个绝对的初学者。我附上了提炼我想要完成的代码的代码。此代码有效,但执行时间实际上会随着 totalThreads 的增加而增加。我的猜测是 spsolve 被视为关键部分,实际上并没有同时运行。
我的问题如下:
- spsolve 线程安全吗?
- 如果 spsolve 被阻塞,有没有办法绕过它?
- 我可以使用另一个线性求解器包,它可以更好地并行化吗?
- 是否有更好的方法来编写此代码段以提高性能?
我一直在网上搜索答案,但没有运气。也许,我只是使用了错误的关键字。感谢大家的帮助。
def Worker(threadnum, totalThreads):
for i in range(threadnum,N,totalThreads):
x[:,i] = sparse.linalg.spsolve( A, b[:,i] )
threads = []
for threadnum in range(totalThreads):
t = threading.Thread(target=Worker, args=(threadnum, totalThreads))
threads.append(t)
t.start()
for threadnum in range(totalThreads): threads[threadnum].join()
【问题讨论】:
-
这个问题欢迎scicomp