Bill Allombert on Thu, 22 Nov 2018 23:50:24 +0100

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

New parallel interface: export

Dear PARI developers,

We have made a new attempt to make writing parallel GP code easier.
Currently global variables are not accessible in parallel code.
In this new interface there is a dedicated namespace (the 'parallel
world') that is used to assign values to global variables in parallel

This is done using the new export() command, which allow the main
thread to set the values of global variables in the 'parallel

a silly example to see what it does:

? export(f=25);
? f
%2 = f
? parsum(i=1,1,f)
%3 = 25

So the global variable f in the main thread is not affected, while it
takes the values 25 in the secondary threads.
Without export GP would issue an error:

? f=25
%1 = 25
? parsum(i=1,1,f)
  ***   at top-level: parsum(i=1,1,f)
  ***                 ^---------------
  *** parsum: mt: global variable not supported: f.

A more natural example:

? f(x)=x^-2;
? export(f); /*implicitely: f=f */
? parsum(i=1,10000,f(i),0.)
%10 = 1.6448340718480597698060818333103109040

export() allows the function f to be usable in the threads.

A more complex example
? \rmyscript
? exportall();
? parfor(i=1,100,myfun(i))

exportall() is a variant of export() that export all current global
variables with their current values.

We also provide unexport/unexportall() to allow to remove a variable
from the 'parallel world'.

Variables in the 'parallel world' are read-only.

Note that when using MPI, export()/exportall() actually require to send
the values of the exported() variables through the networks to the other
node and so can take a bit of time to complete if some variables are

When using pthread, a single copy of the values of the exported()
variables is shared across all threads.