libSingular and openmp
greka · Wed Jan 26, 2022 11:35 am
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:
The compilation runs fine, and it produces the correct output intersected with the following error message (appearing several times):
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.
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;
}
#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
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.