From: Ian Jackson Date: Sun, 8 Apr 2018 13:05:48 +0000 (+0100) Subject: curveopt: parallelise findcurve processes X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=7dee260ab0c5dcca005f532adcd0ee6e6547bb5f;p=moebius3.git curveopt: parallelise findcurve processes Signed-off-by: Ian Jackson --- diff --git a/curveopt.py b/curveopt.py index 8743889..e07e725 100644 --- a/curveopt.py +++ b/curveopt.py @@ -64,6 +64,14 @@ class OptimisedCurve(): print(s, file=subproc.stdin) subproc.stdin.flush() + oc.subproc = subproc + oc.nt = nt + + def _await_subproc(oc): + subproc = oc.subproc + if subproc is None: return + + dbg('(awaiting)') commentary = '' while True: @@ -87,14 +95,15 @@ class OptimisedCurve(): subproc.stdin.close() subproc.wait() assert(subproc.returncode == 0) + oc.subproc = None - oc.nt = nt oc._result = np.reshape(findcurve_result, (-1,3), 'C') dbg(repr(oc._result)) vdbg().curve( oc.point_at_t ) def point_at_it(oc, it): + oc._await_subproc() dbg(repr((it,))) return oc._result[it] diff --git a/moebius.py b/moebius.py index fa182f2..0c4330b 100644 --- a/moebius.py +++ b/moebius.py @@ -62,9 +62,12 @@ class MoebiusHalf: m._cp2b = BezierSegment([ (c,) for c in [0.33,0.33, 1.50]]) m._dbeziers = [ m._dbezier(theta) for theta in m._thetas ] check = int(nu/3)-1 - m._dbezier(m._thetas[check], OptimisedCurve) - m._dbezier(m._thetas[check+1], OptimisedCurve) - m._dbezier(m._thetas[check+2], OptimisedCurve) + checks = ( + m._dbezier(m._thetas[check], OptimisedCurve), + m._dbezier(m._thetas[check+1], OptimisedCurve), + m._dbezier(m._thetas[check+2], OptimisedCurve), + ) + for c in checks: c.point_at_it(0) def _dbezier(m, theta, dconstructor=DiscreteBezier): cp = [None] * 4 cp[0] = m.edge .point(theta)