Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: libSingular and openmp
PostPosted: Wed Jan 26, 2022 11:35 am 

Joined: Tue Feb 06, 2018 6:44 pm
Posts: 4
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: libSingular and openmp
PostPosted: Wed Jan 26, 2022 2:51 pm 

Joined: Wed May 25, 2005 4:16 pm
Posts: 275
- 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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

It is currently Fri May 13, 2022 10:54 am
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group