My Project
Functions
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 196 of file kChinese.cc.

197{
198 int cnt=0;int rw=0; int cl=0;
199 // find max. size of xx[.]:
200 for(int j=rl-1;j>=0;j--)
201 {
202 int i=IDELEMS(xx[j])*xx[j]->nrows;
203 if (i>cnt) cnt=i;
204 if (xx[j]->nrows >rw) rw=xx[j]->nrows; // for lifting matrices
205 if (xx[j]->ncols >cl) cl=xx[j]->ncols; // for lifting matrices
206 }
207 if (rw*cl !=cnt)
208 {
209 WerrorS("format mismatch in CRT");
210 return NULL;
211 }
212 int cpus=(int)(long)feOptValue(FE_OPT_CPUS);
215 /* start no more than MAX_PROCESS-1 children */
216 if ((cpus==1) || (2*cpus>=cnt))
217 /* at least 2 polys for each process, or switch to seriell version */
218 return id_ChineseRemainder(xx,q,rl,r);
219 ideal result=idInit(cnt,xx[0]->rank);
220 result->nrows=rw; // for lifting matrices
221 result->ncols=cl; // for lifting matrices
222 int parent_pid=getpid();
223 using namespace vspace;
224 vmem_init();
225 // Create a queue of int
226 VRef<Queue<int> > queue = vnew<Queue<int> >();
227 for(int i=cnt-1;i>=0; i--)
228 {
229 queue->enqueue(i); // the tasks: construct poly p[i]
230 }
231 for(int i=cpus;i>=0;i--)
232 {
233 queue->enqueue(-1); // stop sign, one for each child
234 }
235 // Create a queue of polys
236 VRef<Queue<VRef<VString> > > rqueue = vnew<Queue<VRef<VString> > >();
237 for (int i=0;i<cpus;i++)
238 {
239 int pid = fork_process();
240 if (pid==0) break; //child
241 }
242 if (parent_pid!=getpid()) // child ------------------------------------------
243 {
244 number *x=(number *)omAlloc(rl*sizeof(number));
245 poly *p=(poly *)omAlloc(rl*sizeof(poly));
246 CFArray inv_cache(rl);
249 loop
250 {
251 int ind=queue->dequeue();
252 if (ind== -1)
253 {
254 exit(0);
255 }
256
257 for(int j=rl-1;j>=0;j--)
258 {
259 if(ind>=IDELEMS(xx[j])*xx[j]->nrows) // out of range of this ideal
260 p[j]=NULL;
261 else
262 p[j]=xx[j]->m[ind];
263 }
264 poly res=p_ChineseRemainder(p,x,q,rl,inv_cache,r);
265 long l=size_poly(res,r);
266 //printf("size: %ld kB\n",(l+1023)/1024);
267 VRef<VString> msg = vstring(l+1);
268 char *s=(char*)msg->str();
269 send_poly(s,ind,res,r);
270 rqueue->enqueue(msg);
271 if (TEST_OPT_PROT) printf(".");
272 }
273 }
274 else // parent ---------------------------------------------------
275 {
276 if (TEST_OPT_PROT) printf("%d children created\n",cpus);
277 VRef<VString> msg;
278 while(cnt>0)
279 {
280 msg=rqueue->dequeue();
281 char *s=(char*)msg->str();
282 int ind;
283 poly p=NULL;
284 get_poly(s,ind,&p,r);
285 //printf("got res[%d]\n",ind);
286 result->m[ind]=p;
287 msg.free();
288 cnt--;
289 }
290 // removes queues
291 queue.free();
292 rqueue.free();
293 vmem_deinit();
294 }
295 return result;
296}
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
Variable x
Definition: cfModGcd.cc:4082
int p
Definition: cfModGcd.cc:4078
cl
Definition: cfModGcd.cc:4100
int int ncols
Definition: cf_linsys.cc:32
int nrows
Definition: cf_linsys.cc:32
return result
Definition: facAbsBiFact.cc:75
const CanonicalForm int s
Definition: facAbsFact.cc:51
CanonicalForm res
Definition: facAbsFact.cc:60
int j
Definition: facHensel.cc:110
void WerrorS(const char *s)
Definition: feFopen.cc:24
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
#define EXTERN_VAR
Definition: globaldefs.h:6
static char * get_poly(char *s, int &ind, poly *p, const ring r)
Definition: kChinese.cc:166
static long size_poly(poly p, const ring r)
Definition: kChinese.cc:185
static char * send_poly(char *s, int ind, poly p, const ring r)
Definition: kChinese.cc:147
poly p_ChineseRemainder(poly *xx, mpz_ptr *x, mpz_ptr *q, int rl, mpz_ptr *C, const ring R)
VAR int n_SwitchChinRem
Definition: longrat.cc:3094
static const int MAX_PROCESS
Definition: vspace.h:1419
pid_t fork_process()
Definition: vspace.cc:993
static void vmem_deinit()
Definition: vspace.h:1742
static Status vmem_init()
Definition: vspace.h:1738
static VRef< VString > vstring(const char *s)
Definition: vspace.h:2101
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define NULL
Definition: omList.c:12
#define TEST_OPT_PROT
Definition: options.h:104
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
#define IDELEMS(i)
Definition: simpleideals.h:23
#define loop
Definition: structs.h:75
void free()
Definition: vspace.h:1805

◆ id_Farey_0()

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

Definition at line 298 of file kChinese.cc.

299{
300 int cnt=IDELEMS(x)*x->nrows;
301 int cpus=(int)(long)feOptValue(FE_OPT_CPUS);
304 /* start no more than MAX_PROCESS-1 children */
305 if (2*cpus>=cnt) /* at least 2 polys for each process,
306 or switch to seriell version */
307 return id_Farey(x,N,r);
308 ideal result=idInit(cnt,x->rank);
309 result->nrows=x->nrows; // for lifting matrices
310 result->ncols=x->ncols; // for lifting matrices
311
312 int parent_pid=getpid();
313 using namespace vspace;
314 vmem_init();
315 // Create a queue of int
316 VRef<Queue<int> > queue = vnew<Queue<int> >();
317 for(int i=cnt-1;i>=0; i--)
318 {
319 queue->enqueue(i); // the tasks: construct poly p[i]
320 }
321 for(int i=cpus;i>=0;i--)
322 {
323 queue->enqueue(-1); // stop sign, one for each child
324 }
325 // Create a queue of polys
326 VRef<Queue<VRef<VString> > > rqueue = vnew<Queue<VRef<VString> > >();
327 for (int i=0;i<cpus;i++)
328 {
329 int pid = fork_process();
330 if (pid==0) break; //child
331 }
332 if (parent_pid!=getpid()) // child ------------------------------------------
333 {
334 loop
335 {
336 int ind=queue->dequeue();
337 if (ind== -1)
338 {
339 exit(0);
340 }
341
342 poly res=p_Farey(x->m[ind],N,r);
343 long l=size_poly(res,r);
344 VRef<VString> msg = vstring(l+1);
345 char *s=(char*)msg->str();
346 send_poly(s,ind,res,r);
347 rqueue->enqueue(msg);
348 if (TEST_OPT_PROT) printf(".");
349 }
350 }
351 else // parent ---------------------------------------------------
352 {
353 if (TEST_OPT_PROT) printf("%d children created\n",cpus);
354 VRef<VString> msg;
355 while(cnt>0)
356 {
357 msg=rqueue->dequeue();
358 char *s=(char*)msg->str();
359 int ind;
360 poly p=NULL;
361 get_poly(s,ind,&p,r);
362 //printf("got res[%d]\n",ind);
363 result->m[ind]=p;
364 msg.free();
365 cnt--;
366 }
367 // wait for the children to finish
368 sleep(1);
369 // removes queues
370 queue.free();
371 rqueue.free();
372 vmem_deinit();
373 }
374 return result;
375}
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
ideal id_Farey(ideal x, number N, const ring r)
Definition: ideals.cc:2848
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 
)