I am trying to solve several linear systems using python and scipy using threads. I am an absolute newbie when it comes to python threads. I have attached code that repels what I'm trying to execute. This code works, but the execution time actually increases, since each increases totalThreads. I assume that spsolve is seen as a critical section and does not actually start at the same time.
My questions are as follows:
- Is spsolve thread safe?
- If spsolve blocks, is there a way around it?
- Is there another linear solver package I can use that is best parallelized?
- Is there a better way to write this code segment that will increase performance?
I searched the Internet for answers, but no luck. Maybe I'm just using the wrong keywords. Thanks for helping everyone.
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()
source share