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 195 of file kChinese.cc.

196{
197 int cnt=0;int rw=0; int cl=0;
198 // find max. size of xx[.]:
199 for(int j=rl-1;j>=0;j--)
200 {
201 int i=IDELEMS(xx[j])*xx[j]->nrows;
202 if (i>cnt) cnt=i;
203 if (xx[j]->nrows >rw) rw=xx[j]->nrows; // for lifting matrices
204 if (xx[j]->ncols >cl) cl=xx[j]->ncols; // for lifting matrices
205 }
206 if (rw*cl !=cnt)
207 {
208 WerrorS("format mismatch in CRT");
209 return NULL;
210 }
211 int cpus=(int)(long)feOptValue(FE_OPT_CPUS);
212 if ((cpus==1) || (2*cpus>=cnt))
213 /* at least 2 polys for each process, or switch to seriell version */
214 return id_ChineseRemainder(xx,q,rl,r);
215 ideal result=idInit(cnt,xx[0]->rank);
216 result->nrows=rw; // for lifting matrices
217 result->ncols=cl; // for lifting matrices
218 int parent_pid=getpid();
219 using namespace vspace;
220 vmem_init();
221 // Create a queue of int
222 VRef<Queue<int> > queue = vnew<Queue<int> >();
223 for(int i=cnt-1;i>=0; i--)
224 {
225 queue->enqueue(i); // the tasks: construct poly p[i]
226 }
227 for(int i=cpus;i>=0;i--)
228 {
229 queue->enqueue(-1); // stop sign, one for each child
230 }
231 // Create a queue of polys
232 VRef<Queue<VRef<VString> > > rqueue = vnew<Queue<VRef<VString> > >();
233 for (int i=0;i<cpus;i++)
234 {
235 int pid = fork_process();
236 if (pid==0) break; //child
237 }
238 if (parent_pid!=getpid()) // child ------------------------------------------
239 {
240 number *x=(number *)omAlloc(rl*sizeof(number));
241 poly *p=(poly *)omAlloc(rl*sizeof(poly));
242 CFArray inv_cache(rl);
245 loop
246 {
247 int ind=queue->dequeue();
248 if (ind== -1)
249 {
250 exit(0);
251 }
252
253 for(int j=rl-1;j>=0;j--)
254 {
255 if(ind>=IDELEMS(xx[j])*xx[j]->nrows) // out of range of this ideal
256 p[j]=NULL;
257 else
258 p[j]=xx[j]->m[ind];
259 }
260 poly res=p_ChineseRemainder(p,x,q,rl,inv_cache,r);
261 long l=size_poly(res,r);
262 //printf("size: %ld kB\n",(l+1023)/1024);
263 VRef<VString> msg = vstring(l+1);
264 char *s=(char*)msg->str();
265 send_poly(s,ind,res,r);
266 rqueue->enqueue(msg);
267 if (TEST_OPT_PROT) printf(".");
268 }
269 }
270 else // parent ---------------------------------------------------
271 {
272 if (TEST_OPT_PROT) printf("%d childs created\n",cpus);
273 VRef<VString> msg;
274 while(cnt>0)
275 {
276 msg=rqueue->dequeue();
277 char *s=(char*)msg->str();
278 int ind;
279 poly p=NULL;
280 get_poly(s,ind,&p,r);
281 //printf("got res[%d]\n",ind);
282 result->m[ind]=p;
283 msg.free();
284 cnt--;
285 }
286 // removes queues
287 queue.free();
288 rqueue.free();
289 vmem_deinit();
290 }
291 return result;
292}
#define NULL
Definition: auxiliary.h:104
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
Variable x
Definition: cfModGcd.cc:4084
int p
Definition: cfModGcd.cc:4080
cl
Definition: cfModGcd.cc:4102
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:165
static long size_poly(poly p, const ring r)
Definition: kChinese.cc:184
static char * send_poly(char *s, int ind, poly p, const ring r)
Definition: kChinese.cc:146
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:3052
Definition: vspace.cc:9
pid_t fork_process()
Definition: vspace.cc:419
static void vmem_deinit()
Definition: vspace.h:407
static Status vmem_init()
Definition: vspace.h:403
static VRef< VString > vstring(const char *s)
Definition: vspace.h:766
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define TEST_OPT_PROT
Definition: options.h:103
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:80
void free()
Definition: vspace.h:470

◆ id_Farey_0()

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

Definition at line 294 of file kChinese.cc.

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