Ask Your Question

Revision history [back]

Problem with precompute and append in parallel computing

Here is a parallel computation involving precompute and append:

sage: L=[]
sage: @cached_function
....: def function(i):
....:     print([i])
....:     L.append(i)
....:
sage: function.precompute(range(10),num_processes=2)
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]

The problem is that the list L is still empty, the action L.append(i) was not done as expected.

sage: L
[]

How to solve this problem?

Problem with precompute and append in parallel computing

Here is a parallel computation involving precompute and append:

sage: L=[]
sage: @cached_function
....: def function(i):
....:     print([i])
L.append(i)
....:     L.append(i)
print(L)
....:
sage: function.precompute(range(10),num_processes=2)
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]

The problem is that the list L is still empty, empty at the end, the action L.append(i) was not done as expected.globally.

sage: L
[]

How to solve this problem?

Problem with precompute and append in parallel computing

Here is a parallel computation involving precompute and append:

sage: L=[]
sage: @cached_function
....: def function(i):
....:     L.append(i)
....:     print(L)
....:
sage: function.precompute(range(10),num_processes=2)
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]

The problem is that the list L is still empty at the end, the action L.append(i) was not done globally.globally, whereas the list L is global.

sage: L
[]

How to solve this problem?

Problem with precompute and append in parallel computing

Here is a parallel computation involving precompute and append:

sage: L=[]
sage: @cached_function
....: def function(i):
....:     L.append(i)
....:     print(L)
....:
sage: function.precompute(range(10),num_processes=2)
function.precompute(range(5),num_processes=2)
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]

The problem is that the list L is still empty at the end, the action L.append(i) was not done globally, whereas the list L is global.

sage: L
[]

How to solve this problem?