next up previous
Next: Hand-editing the C file Up: A gp2c tutorial Previous: Using gp2c to find


Using compiled functions in a new program

One you have successfully compiled and tested your functions you may want to reuse them in another GP program.

The best way is to copy the install commands of the functions you use at the start of the new program so that reading it will automatically load the compiled functions.

As an example, we write a simple program fact.gp that reads

install("squfof","D0,G,p","squfof","./pari/examples/squfof.gp.so");
fact_mersenne(p)=squfof(2^p-1)
and run GP:
parisize = 4000000, primelimit = 500000
? \rfact
? fact_mersenne(67)
i = 2418
Qfb(10825778209, 4021505768, -13258245519, 0.E-28)
%1 = 193707721

So all goes well. But what is even better is that gp2c understands the install command and will be able to compile this new program. However you need GP version 2.1.4 or 2.2.2 at least for it to work, unless you are on OSF1.

Also this particular example will fail because as stated above, PARI/GP has already a squfof function, and the linker will pick the wrong one, which is unfortunate.

So use -p option to gp2c-run to change squfof to my_squfof.

./gp2c-run -pmy_ -g pari/examples/squfof.gp

This option prefixes my_ to every GP name in the program so as to avoid name clashes. Change fact.gp to

install("my_squfof","D0,G,p","squfof","./pari/examples/squfof.gp.so");
fact_mersenne(p)=squfof(2^p-1)
and run

./gp2c-run -g fact.gp

parisize = 4000000, primelimit = 500000
? fact_mersenne(67)
i = 2418
Qfb(10825778209, 4021505768, -13258245519, 0.E-28)
%1 = 193707721

Nice isn't it?


next up previous
Next: Hand-editing the C file Up: A gp2c tutorial Previous: Using gp2c to find
Bill Allombert 2006-01-28