added fall-back to non-multithreading execution when using only single CPU.
This commit is contained in:
parent
31f6d22d89
commit
57dfa6a87e
|
@ -81,15 +81,16 @@ def laguerreTessellation(undeformed, coords, weights, grains, nonperiodic = Fals
|
||||||
|
|
||||||
arguments = [[arg] + [seeds,squaredweights] for arg in list(undeformed)]
|
arguments = [[arg] + [seeds,squaredweights] for arg in list(undeformed)]
|
||||||
|
|
||||||
# Initialize workers
|
if cpus > 1: # use multithreading
|
||||||
pool = multiprocessing.Pool(processes = cpus)
|
pool = multiprocessing.Pool(processes = cpus) # initialize workers
|
||||||
|
result = pool.map_async(findClosestSeed, arguments) # evaluate function in parallel
|
||||||
# Evaluate function
|
|
||||||
result = pool.map_async(findClosestSeed, arguments)
|
|
||||||
pool.close()
|
pool.close()
|
||||||
pool.join()
|
pool.join()
|
||||||
|
|
||||||
closestSeeds = np.array(result.get()).flatten()
|
closestSeeds = np.array(result.get()).flatten()
|
||||||
|
else:
|
||||||
|
closestSeeds = np.zeros(len(arguments),dtype='i')
|
||||||
|
for i,arg in enumerate(arguments):
|
||||||
|
closestSeeds[i] = findClosestSeed(arg)
|
||||||
|
|
||||||
return grains[closestSeeds%coords.shape[0]] # closestSeed is modulo number of original seed points (i.e. excluding periodic copies)
|
return grains[closestSeeds%coords.shape[0]] # closestSeed is modulo number of original seed points (i.e. excluding periodic copies)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue