Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using @parallel in creating a list

The question is how to create a list one element at a time using a parallel defined function. I do NOT want to use list comprehension like [f(i) for i in [1..100]] with a parallel defined f. I want to create a list that will still exist in Sage even if I interrupt its calculation before it's done.

It doesn't matter what my function is here. The point is what I'm trying to do here.

sage: @parallel(2)
....: def GMP(n): return (n,GetMinPerimAndSequence(n))
sage: L = []
sage: L.append(GMP([1..100]))

What I intended was that I wanted to run this command with parallel execution, but create a list that would exist even if I interrupt the calculation (such as if it takes a looong time).

sage: L
[<generator object __call__ at 0x4964050>]
sage: L[0]
<generator object __call__ at 0x4964050>

which of course is the same as just making a generator in the first place and using it. So this strategy doesn't work.