Hi @stevebaer
I made a script based on your great example on parallel processing:
I am trying to project a bunch of points onto a mesh and wonder if you understand why I only get a 2.3x speed up on a machine with 12 cores/24 threads:
import rhinoscriptsyntax as rs
import random
import System.Threading.Tasks as tasks
import time
def PointsOnMesh(mesh):
# DENSITY SETTING
xNr = 200
bbox = rs.BoundingBox(mesh)
xMultiplier = rs.Distance(bbox[0],bbox[1])
yMultiplier = rs.Distance(bbox[0],bbox[3])
points = []
for i in range(xNr):
for ii in range(xNr):
point=rs.coerce3dpoint( (xMultiplier*random.random(),yMultiplier*random.random(), 0) )
point += bbox[0]
points.append(point)
return points
def ProjectPoints(parallel,points,mesh):
time1=time.time()
newPoints=[None]*len(points)
def calculus(i):
try:
projection = rs.ProjectPointToMesh(points[i], mesh, (0,0,-1))
newPoints[i] = projection[0]
except:
pass
if parallel:
tasks.Parallel.ForEach(xrange(len(points)), calculus)
else:
for i in range(len(points)):
calculus(i)
time2=time.time()
rs.AddPointCloud(newPoints)
return round(time2-time1,4)
mesh = rs.GetObject("Mesh",rs.filter.mesh)
single = None
multi = None
if mesh:
points = PointsOnMesh(mesh)
if points:
single = ProjectPoints(False,points,mesh)
if single: print "Single Core:",single
multi = ProjectPoints(True,points,mesh)
if multi: print "Multi Core:",multi
if single and multi:
print "MultiCore speed up:", round(single/multi,2),"X"
I made it with rs.ProjectPointToMesh() so the mesh isn’t a secured private copy.
Thanks
Edit: You need a mesh in the document, I just used a Heightfieldfromimage and made a 200x200 mesh.
Edit II: Note: On your example I get a 11.5X speedup on a torus. So that seems to work much better.