2014-12-18 3 views
0

나는 많은 수치 데이터를 포함하는 파이썬 응용 프로그램을 만들고 있습니다. 데이터는 첫 번째 단계에서 그룹으로 분리 된 다음 그룹을 독립적으로 계산할 수 있습니다.병렬 계산을위한 파이썬

나는 threading.Thread()를 사용해 보았지만 곧 gil 때문에 사용하지 못했습니다.

class vThread(Thread): 
    def __init__(self,item): 
     Thread.__init__(self) 
     self.item = item 

    def run(self): 
     do_stuff() 

vThreads = [] 

for item in items: 
    vThreads.append(vThread(item))  
    for x in vThreads: 
     x.start() 

    for x in vThreads: 
     x.join() 

는 나 또한 (multiprocessing.Process 시도)은 보이지 않고는

다른 방법이 (단지 프로세스에 의해 스레드 교체 스레드와 비슷한 implemantation를) 내 부모 프로세스의 새로운 인스턴스를 생성하지 하위 프로세스입니다 내 상황에서 병렬 처리를 구현할 수 있습니까? 독립적 인 계산의 수는 수천입니다.

+0

도 [MKL (https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl)가있다. – Marcin

+0

typo? vThread (항목)은 무엇을 반환합니까? 편집 - 오하이오, 그것은 vThreads와는 다릅니다. 내 잘못이야. – Dinesh

+0

jst가 편집했습니다. 그것은 잘못 입력되었습니다. 그것의 jst 식별자 및 아무것도 다른 – vidit

답변

0

concurrent.futures.ProcessPoolExecutor을 사용하면 여러 독립적 인 작업을 병렬로 실행할 수 있습니다.

from concurrent.futures import ProcessPoolExecutor 

with concurrent.futures.ProcessPoolExecutor() as executor: 
    for item in items: 
     executor.submit(do_stuff, item) 

Python2에서 당신은 동일한 결과를 달성하기 위해 multiprocessing.Pool 클래스를 사용할 수 있습니다.

from multiprocessing import Pool 

pool = Pool() 

for item in items: 
    pool.apply_async(do_stuff, (item,)) 
관련 문제