我想调用一个方法 getRecommendations,它只是将针对特定用户的建议腌制到文件中。我使用了一本有效的书中的代码。但是我看到只有一个核心可以工作,我希望我所有的核心都可以工作,因为这样会快得多。
这是方法。
def getRecommendations(prefs,person,similarity=sim_pearson):
print "working on recommendation"
totals={}
simSums={}
for other in prefs:
# don't compare me to myself
if other==person: continue
sim=similarity(prefs,person,other)
# ignore scores of zero or lower
if sim<=0: continue
for item in prefs[other]:
# only score movies I haven't seen yet
if item not in prefs[person] or prefs[person][item]==0:
# Similarity * Score
totals.setdefault(item,0)
totals[item]+=prefs[other][item]*sim
# Sum of similarities
simSums.setdefault(item,0)
simSums[item]+=sim
# Create the normalized list
rankings=[(total/simSums[item],item) for item,total in totals.items( )]
# Return the sorted list
rankings.sort( )
rankings.reverse( )
ranking_output = open("data/rankings/"+str(int(person))+".ranking.recommendations","wb")
pickle.dump(rankings,ranking_output)
return rankings
它被称为通过
for i in customerID:
print "working on ", int(i)
#Make this working with multiple CPU's
getRecommendations(pickle.load(open("data/critics.recommendations", "r")), int(i))
如您所见,我尝试向每位客户提出建议。后面会用到。
那么我怎样才能多处理这个方法呢?我没有通过阅读一些示例甚至文档来理解它