Loading...
Searching...
No Matches
kChinese.h File Reference
`#include "misc/auxiliary.h"`
`#include "misc/intvec.h"`
`#include "polys/monomials/p_polys.h"`
`#include "polys/matpol.h"`
`#include "polys/simpleideals.h"`
`#include <gmp.h>`

Go to the source code of this file.

## Functions

poly | p_ChineseRemainder (poly *xx, mpz_ptr *x, mpz_ptr *q, int rl, mpz_ptr *C, const ring R)
ideal | id_ChineseRemainder_0 (ideal *xx, number *q, int rl, const ring r)
ideal | id_Farey_0 (ideal xx, number N, const ring r)

## Function Documentation

## id_ChineseRemainder_0()

ideal id_ChineseRemainder_0 | ( | ideal * | xx,
|  | number * | q,
|  | int | rl,
|  | const ring | r )

Definition at line 199 of file kChinese.cc.

{
int cpus = (long) feOptValue(FE_OPT_CPUS);
if (cpus<1)
{
WerrorS("no sub-processes allowed");
return NULL;
}
int cnt=0;int rw=0; int cl=0;
// find max. size of xx[.]:
for(int j=rl-1;j>=0;j--)
{
int i=IDELEMS(xx[j])*xx[j]->nrows;
if (i>cnt) cnt=i;
if (xx[j]->nrows >rw) rw=xx[j]->nrows; // for lifting matrices
if (xx[j]->ncols >cl) cl=xx[j]->ncols; // for lifting matrices
}
if (rw*cl !=cnt)
{
WerrorS("format mismatch in CRT");
return NULL;
}
if (cpus>=vspace::internals::MAX_PROCESS)
cpus=vspace::internals::MAX_PROCESS-1;
/* start no more than MAX_PROCESS-1 children */
cpus=si_min(cpus,cnt/5);
if (cpus<=1)
/* at least 5 polys for each process, or switch to seriell version */
return id_ChineseRemainder(xx,q,rl,r);
ideal result=idInit(cnt,xx[0]->rank);
result->nrows=rw; // for lifting matrices
result->ncols=cl; // for lifting matrices
int parent_pid=getpid();
using namespace vspace;
vmem_init();
// Create a queue of int
VRef<Queue<int> > queue = vnew<Queue<int> >();
for(int i=cnt-1;i>=0; i--)
{
queue->enqueue(i); // the tasks: construct poly p[i]
}
for(int i=cpus;i>=0;i--)
{
queue->enqueue(-1); // stop sign, one for each child
}
// Create a queue of polys
VRef<Queue<VRef<VString> > > rqueue = vnew<Queue<VRef<VString> > >();
int *pids=(int*)omAlloc0(cpus*sizeof(int));
for (int i=0;i<cpus;i++)
{
int pid = fork_process();
if (pid==0) break; //child
pids[i]=pid;
}
if (parent_pid!=getpid()) // child ------------------------------------------
{
si_set_signal(SIGTERM,sig_term_hdl_child);
singular_close_links();
feSetOptValue(FE_OPT_CPUS,0);
number *x=(number *)omAlloc(rl*sizeof(number));
poly *p=(poly *)omAlloc(rl*sizeof(poly));
CFArray inv_cache(rl);
EXTERN_VAR int n_SwitchChinRem;
n_SwitchChinRem=1;
loop
{
int ind=queue->dequeue();
if (ind== -1)
{
_exit(0);
}
for(int j=rl-1;j>=0;j--)
{
if(ind>=IDELEMS(xx[j])*xx[j]->nrows) // out of range of this ideal
p[j]=NULL;
else
p[j]=xx[j]->m[ind];
}
poly res=p_ChineseRemainder(p,x,q,rl,inv_cache,r);
long l=size_poly(res,r);
//printf("size: %ld kB\n",(l+1023)/1024);
VRef<VString> msg = vstring(l+1);
char *s=(char*)msg->str();
send_poly(s,ind,res,r);
rqueue->enqueue(msg);
if (TEST_OPT_PROT) printf(".");
}
}
else // parent ---------------------------------------------------
{
if (TEST_OPT_PROT) printf("%d children created\n",cpus);
VRef<VString> msg;
while(cnt>0)
{
msg=rqueue->dequeue();
char *s=(char*)msg->str();
int ind;
poly p=NULL;
get_poly(s,ind,&p,r);
//printf("got res[%d]\n",ind);
result->m[ind]=p;
msg.free();
cnt--;
}
int i=cpus-1;
int done=0;
while(done!=cpus)
{
BOOLEAN all_done=TRUE;
if (pids[i]>0)
{
int p=si_waitpid(pids[i],NULL,WNOHANG);
if (p>0)
{
pids[i]=0;
done++;
}
}
if (i==0) i=cpus;
i--;
}
omFreeSize(pids,cpus*sizeof(int));
// removes queues
queue.free();
rqueue.free();
vmem_deinit();
}
return result;
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
si_min
static int si_min(const int a, const int b)
Definition auxiliary.h:126
CFArray
Array< CanonicalForm > CFArray
Definition canonicalform.h:397
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
x
Variable x
Definition cfModGcd.cc:4090
p
int p
Definition cfModGcd.cc:4086
cl
cl
Definition cfModGcd.cc:4108
ncols
int int ncols
Definition cf_linsys.cc:32
nrows
int nrows
Definition cf_linsys.cc:32
si_set_signal
si_hdl_typ si_set_signal(int sig, si_hdl_typ signal_handler)
meta function for binding a signal to an handler
Definition cntrlc.cc:121
sig_term_hdl_child
void sig_term_hdl_child(int)
Definition cntrlc.cc:86
result
return result
Definition facAbsBiFact.cc:76
s
const CanonicalForm int s
Definition facAbsFact.cc:51
res
CanonicalForm res
Definition facAbsFact.cc:60
j
int j
Definition facHensel.cc:110
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
feSetOptValue
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
feOptValue
static void * feOptValue(feOptIndex opt)
Definition feOpt.h:40
EXTERN_VAR
#define EXTERN_VAR
Definition globaldefs.h:6
get_poly
static char * get_poly(char *s, int &ind, poly *p, const ring r)
Definition kChinese.cc:169
size_poly
static long size_poly(poly p, const ring r)
Definition kChinese.cc:188
send_poly
static char * send_poly(char *s, int ind, poly p, const ring r)
Definition kChinese.cc:150
p_ChineseRemainder
poly p_ChineseRemainder(poly *xx, mpz_ptr *x, mpz_ptr *q, int rl, mpz_ptr *C, const ring R)
n_SwitchChinRem
VAR int n_SwitchChinRem
Definition longrat.cc:3074
vspace::internals::MAX_PROCESS
static const int MAX_PROCESS
Definition vspace.h:1419
vspace
Definition vspace.cc:615
vspace::vnew
VRef< T > vnew()
Definition vspace.h:1872
vspace::fork_process
pid_t fork_process()
Definition vspace.cc:1081
vspace::vmem_deinit
static void vmem_deinit()
Definition vspace.h:1742
vspace::vmem_init
static Status vmem_init()
Definition vspace.h:1738
vspace::vstring
static VRef< VString > vstring(const char *s)
Definition vspace.h:2101
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211
NULL
#define NULL
Definition omList.c:12
TEST_OPT_PROT
#define TEST_OPT_PROT
Definition options.h:105
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition simpleideals.cc:35
id_ChineseRemainder
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
Definition simpleideals.cc:2147
IDELEMS
#define IDELEMS(i)
Definition simpleideals.h:23
singular_close_links
void singular_close_links()
Definition ssiLink.cc:3455
loop
#define loop
Definition structs.h:71
vspace::VRef
Definition vspace.h:1747
vspace::VRef::free
void free()
Definition vspace.h:1805

## id_Farey_0()

ideal id_Farey_0 | ( | ideal | xx,
|  | number | N,
|  | const ring | r )

Definition at line 330 of file kChinese.cc.

{
int cnt=IDELEMS(x)*x->nrows;
int cpus=(int)(long)feOptValue(FE_OPT_CPUS);
if (cpus>=vspace::internals::MAX_PROCESS)
cpus=vspace::internals::MAX_PROCESS-1;
/* start no more than MAX_PROCESS-1 children */
cpus=si_min(cpus,cnt/5);
if (cpus<=1) /* at least 5 polys for each process,
or switch to seriell version */
return id_Farey(x,N,r);
ideal result=idInit(cnt,x->rank);
result->nrows=x->nrows; // for lifting matrices
result->ncols=x->ncols; // for lifting matrices
int parent_pid=getpid();
using namespace vspace;
vmem_init();
// Create a queue of int
VRef<Queue<int> > queue = vnew<Queue<int> >();
for(int i=cnt-1;i>=0; i--)
{
queue->enqueue(i); // the tasks: construct poly p[i]
}
for(int i=cpus;i>=0;i--)
{
queue->enqueue(-1); // stop sign, one for each child
}
// Create a queue of polys
VRef<Queue<VRef<VString> > > rqueue = vnew<Queue<VRef<VString> > >();
int *pids=(int*)omAlloc0(cpus*sizeof(int));
for (int i=0;i<cpus;i++)
{
int pid = fork_process();
if (pid==0) break; //child
pids[i]=pid;
}
if (parent_pid!=getpid()) // child ------------------------------------------
{
si_set_signal(SIGTERM,sig_term_hdl_child);
singular_close_links();
feSetOptValue(FE_OPT_CPUS,0);
loop
{
int ind=queue->dequeue();
if (ind== -1)
{
_exit(0);
}
poly res=p_Farey(x->m[ind],N,r);
long l=size_poly(res,r);
VRef<VString> msg = vstring(l+1);
char *s=(char*)msg->str();
send_poly(s,ind,res,r);
rqueue->enqueue(msg);
if (TEST_OPT_PROT) printf(".");
}
}
else // parent ---------------------------------------------------
{
if (TEST_OPT_PROT) printf("%d children created\n",cpus);
VRef<VString> msg;
while(cnt>0)
{
msg=rqueue->dequeue();
char *s=(char*)msg->str();
int ind;
poly p=NULL;
get_poly(s,ind,&p,r);
//printf("got res[%d]\n",ind);
result->m[ind]=p;
msg.free();
cnt--;
}
int i=cpus-1;
int done=0;
while(done!=cpus)
{
BOOLEAN all_done=TRUE;
if (pids[i]>0)
{
int p=si_waitpid(pids[i],NULL,WNOHANG);
if (p>0)
{
pids[i]=0;
done++;
}
}
if (i==0) i=cpus;
i--;
}
omFreeSize(pids,cpus*sizeof(int));
// removes queues
queue.free();
rqueue.free();
vmem_deinit();
}
return result;
}
N
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
id_Farey
ideal id_Farey(ideal x, number N, const ring r)
Definition ideals.cc:3103
p_Farey
poly p_Farey(poly p, number N, const ring r)
Definition p_polys.cc:54

## p_ChineseRemainder()

poly p_ChineseRemainder | ( | poly * | xx,
|  | mpz_ptr * | x,
|  | mpz_ptr * | q,
|  | int | rl,
|  | mpz_ptr * | C,
|  | const ring | R )