Bill Allombert on Tue, 05 Nov 2019 17:06:54 +0100


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

Re: Pari Library used with Rust : help with parallelism


On Tue, Nov 05, 2019 at 05:46:50PM +0200, Omer Shlomovits wrote:
> Hello ,
> 
> What I have tried: 
> - using the Rust "parallel for" over Pari library calls to “nupow” : I am getting stack overflow every time. No mattar what is the max size of the stack

Did you read the documentation, in particular Appendix D ? 
Each threads need to set up its own PARI stack.

> - I tried Pari parfor: This option went better but I got illegal
> instruction error eventually. I think that it is because I don’t know
> how to write  “ i = 1 “ where i is a "formal variable” (I am not sure
> what is a formal variable). In my code I just use j (instead of
> writing i  = 1) as some Gen repressing a number. 

This one is not going to work, parfor is only for GP.

> - I looked into parapply but I have no idea (maybe you do?) on how to
> write the function name as a "Gen f” when trying to invoke this method
> from Rust.

See examples/pari-mt.c:

GEN
myfunc(GEN a)
{
  return muli(a,3);
}

In the initialization do:

  entree ep = {"mygpfunc",0,(void*)myfunc,20,"GL",""};
  pari_add_function(&ep); /* add Cworker function to gp */

when you need f, do

  GEN f = strtoclosure("mygpfunc");

and then

  parapply(f, V);

Cheers,
Bill.