|Bill Allombert on Sat, 13 Apr 2013 16:15:44 +0200|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|Re: Updated branch bill-mt for parallel pari|
On Wed, Apr 10, 2013 at 02:15:45PM +0200, Bill Allombert wrote: > Dear PARI developers, > > I have updated again the branch bill-mt for parallel pari to match > the current PARI GIT version. Andreas has experimented a bit with this branch. The result is that the system works but the requirement not to use global variables leads to a user interface problem. Indeed, traditionallly all GP functions are global variables. So for example: sinc(x)=if(x,sin(x)/x,1) fun(a)=intnum(x=0,a,sinc(x)) parvector(100,i,fun(i)) is not valid because the expression 'fun(i)' uses the global variable 'fun', and fun() itself use the global variable sinc. One way to work around this difficulty is to write sinc(x)=if(x,sin(x)/x,1) my(sinc=sinc); fun(a)=intnum(x=0,a,sinc(x)) my(fun=fun); parvector(100,i,fun(i)) which works, but is far from natural, and require to make extraneous copy of functions. One alternative which works with MPI, is sinc(x)=if(x,sin(x)/x,1) fun(a)=intnum(x=0,a,sinc(x)) my(fun=fun,sinc=sinc); parvector(100,i,local(sinc=sinc);fun(i)) which is sligthly nicer (by a small margin). Unfortunately, using POSIX threads, currently entree* are shared across threads and so local() does not work. (Also the locking of user functions while they run is not thread-safe, which prevent using global variables). So I am looking at ways to imporve the interface. One solution would be to add a new default() that cause the compiler to automatically inline all functions (thought this is problematic for recursive functions) Another is to add an explicit export() declaration. How this would work in detail is still unclear. In any case, I like to thanks Andreas for experimenting the parallel code. Cheers, Bill.