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);
213 if ((cpus==1) || (2*cpus>=cnt))
214 /* at least 2 polys for each process, or switch to seriell version */
215 return id_ChineseRemainder(xx,q,rl,r);
216 ideal result=idInit(cnt,xx[0]->rank);
217 result->nrows=rw; // for lifting matrices
218 result->ncols=cl; // for lifting matrices
219 int parent_pid=getpid();
220 using namespace vspace;
221 vmem_init();
222 // Create a queue of int
223 VRef<Queue<int> > queue = vnew<Queue<int> >();
224 for(int i=cnt-1;i>=0; i--)
225 {
226 queue->enqueue(i); // the tasks: construct poly p[i]
227 }
228 for(int i=cpus;i>=0;i--)
229 {
230 queue->enqueue(-1); // stop sign, one for each child
231 }
232 // Create a queue of polys
233 VRef<Queue<VRef<VString> > > rqueue = vnew<Queue<VRef<VString> > >();
234 for (int i=0;i<cpus;i++)
235 {
236 int pid = fork_process();
237 if (pid==0) break; //child
238 }
239 if (parent_pid!=getpid()) // child ------------------------------------------
240 {
241 number *x=(number *)omAlloc(rl*sizeof(number));
242 poly *p=(poly *)omAlloc(rl*sizeof(poly));
243 CFArray inv_cache(rl);
246 loop
247 {
248 int ind=queue->dequeue();
249 if (ind== -1)
250 {
251 exit(0);
252 }
253
254 for(int j=rl-1;j>=0;j--)
255 {
256 if(ind>=IDELEMS(xx[j])*xx[j]->nrows) // out of range of this ideal
257 p[j]=NULL;
258 else
259 p[j]=xx[j]->m[ind];
260 }
261 poly res=p_ChineseRemainder(p,x,q,rl,inv_cache,r);
262 long l=size_poly(res,r);
263 //printf("size: %ld kB\n",(l+1023)/1024);
264 VRef<VString> msg = vstring(l+1);
265 char *s=(char*)msg->str();
266 send_poly(s,ind,res,r);
267 rqueue->enqueue(msg);
268 if (TEST_OPT_PROT) printf(".");
269 }
270 }
271 else // parent ---------------------------------------------------
272 {
273 if (TEST_OPT_PROT) printf("%d children created\n",cpus);
274 VRef<VString> msg;
275 while(cnt>0)
276 {
277 msg=rqueue->dequeue();
278 char *s=(char*)msg->str();
279 int ind;
280 poly p=NULL;
281 get_poly(s,ind,&p,r);
282 //printf("got res[%d]\n",ind);
283 result->m[ind]=p;
284 msg.free();
285 cnt--;
286 }
287 // removes queues
288 queue.free();
289 rqueue.free();
290 vmem_deinit();
291 }
292 return result;
293}
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
Variable x
Definition: cfModGcd.cc:4081
int p
Definition: cfModGcd.cc:4077
cl
Definition: cfModGcd.cc:4099
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:3095
pid_t fork_process()
Definition: vspace.cc:977
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: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:75
void free()
Definition: vspace.h:1805

◆ id_Farey_0()

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

Definition at line 295 of file kChinese.cc.

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