그라데이션 디센트 (정확히 100 번 반복)를 수행하고 있습니다. 각 데이터 포인트를 병렬로 분석 할 수 있으며 50 개의 데이터 포인트가 있습니다. 4 코어가 있으므로 multiprocessing.Pool
을 사용하여 4 명의 직원 풀을 만듭니다. 기능 train_go_crf
에 대한멀티 프로세싱을 사용할 때 잘못된 출력이 발생했습니다.
# Read the sgf files (total 50)
(intermediateBoards, finalizedBoards) = read_sgf_files()
# Create a pool of processes to analyze game boards in parallel with as
# many processes as number of cores
pool = Pool(processes=cpu_count())
# Initialize the parameter object
param = Param()
# maxItr = 100 iterations of gradient descent
for itr in range(maxItr):
args = []
# Prepare argument vector for each file
for i in range(len(intermediateBoards)):
args.append((intermediateBoards[i], finalizedBoards[i], param))
# 4 processes analyze 50 data points in parallel in each iteration of
# gradient descent
result = pool.map_async(train_go_crf_mcmc, args)
지금, 나는이 포함되지 않은 정의를하지만, 함수의 첫 번째 줄은 인쇄 성명 :이 프로그램의 핵심은 다음과 같습니다. 그래서이 함수를 실행할 때 print 문은 100 * 50 번 실행되어야합니다. 하지만 그런 일은 일어나지 않습니다. 더 많은 것은 인 무엇, 나는 다른 수의 콘솔 출력을 다른 횟수로 얻는다.
은 어떤 문제가 있습니까?
문제가'map_ascync '이 (가) 비 차단이라고 의심됩니다. 'map'을 대신 사용하면 제대로 동작합니까? – tacaswell
@tcaswell : 당신이 옳다고 생각합니다. 그런 다음 모든 비동기 호출이 실행을 끝내는 동안 몇 초 동안 주 프로세스를 일시 중단하는 간단한 sleep() 함수를 추가하면됩니다. – abhinavkulkarni
표시하지 않는 코드 줄에서'AsyncResult' 객체에 대해'get'을 호출합니까? – Jared