This is fairly easy to do with @parallel:
def fast(x): return x def slow(x): sleep(x) return x def slower(x): sleep(x*x) return x algorithms = [slower, slow, fast] @parallel(len(algorithms)) def fastest(i,x): global algorithms return algorithms[i](x) def compute(x): return fastest([(i,x) for i in range(len(algorithms))]).next()[1] On Thu, Nov 3, 2011 at 11:37 AM, mmarco <mma...@unizar.es> wrote: > There are some computations for which there are several algorithms > available. Think, for example, of GTZ and SY algorithms for primary > decomposition. There is no useful criterion to determine which one > will be faster for a given case in advance. With modern computers > having multiple cores, i think it could be a good idea to run both of > them in parallel, until one of them finishes, and then stop the other. > > I still haven't thought how, but it seems reasonable that this aproach > would be doable in Sage. So, do you think we should follow this > aproach in sage? Namely, include an option algorithm='faster' (or > something like that) for functions that admit several algorithms. > > -- > To post to this group, send an email to sage-devel@googlegroups.com > To unsubscribe from this group, send an email to > sage-devel+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-devel > URL: http://www.sagemath.org > -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org