Singular https://www.singular.uni-kl.de/forum/ |
|
libSingular and openmp https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=2971 |
Page 1 of 1 |
Author: | greka [ Wed Jan 26, 2022 11:35 am ] |
Post subject: | libSingular and openmp |
Hi, Is it possible to parallelize calls to functions in libSingular using openmp (or pthreads)? My naive approach, starting from the example given in https://github.com/Singular/Singular/bl ... ibsingular, had some problems: Code: #include <iostream> #include <Singular/libsingular.h> #include <omp.h> int main() { //initialize singular siInit((char *)"/usr/lib/libSingular.so"); #pragma omp parallel { // construct the ring Z/32003[x,y,z] // the variable names char **n=(char**)omalloc(3*sizeof(char*)); n[0]=omStrDup("x"); n[1]=omStrDup("y"); n[2]=omStrDup("z"); ring R=rDefault(32003,3,n); // make R the default ring: not needed if p_<...> functions are used //rChangeCurrRing(R); // create the polynomial 1 poly p1=p_ISet(1,R); // create the polynomial 2*x^3*z^2 poly p2=p_ISet(2,R); p_SetExp(p2,1,3,R); p_SetExp(p2,3,2,R); p_Setm(p2,R); // print p1 + p2 #pragma omp critical { p_Write(p1,R); printf(" + \n"); p_Write(p2,R); printf("\n"); } } return 0; } The compilation runs fine, and it produces the correct output intersected with the following error message (appearing several times): Code: // ***dError: Bug reported: p_Procs is NULL occurred at ./templates/p_Procs_Set.h,170 // ** Singular will work properly, but much slower // ** If you chose a coef ring, it may not work at all Related to this is the question why it is necessary to initialize singular if one only uses "standalone" functions (e.g. all p_<...> functions) that don't seem to rely on any global object (like the current ring) or interpreter? I tried to dig into the source code and documentation but couldn't really understand what's happening. |
Author: | hannes [ Wed Jan 26, 2022 2:51 pm ] |
Post subject: | Re: libSingular and openmp |
- the need for siInit: it initialized all parts of Singular (with the exceptions of signals): without it the interpreter can not be used, the factorization does not work, routines for memory management are not set, etc. It also sets the path to find the code parts which are not in the main program: for example all specialized p_* routines are in p_Procs_*.so - parallelization via openmp: the standard Singular is not thread-safe, you need a special version as described in README.pSingular or have a look at modstd.lib and kverify.cc how parallelization works in Singular. |
Page 1 of 1 | All times are UTC + 1 hour [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |