My Project
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.

200{
201 int cnt=0;int rw=0; int cl=0;
202 // find max. size of xx[.]:
203 for(int j=rl-1;j>=0;j--)
204 {
205 int i=IDELEMS(xx[j])*xx[j]->nrows;
206 if (i>cnt) cnt=i;
207 if (xx[j]->nrows >rw) rw=xx[j]->nrows; // for lifting matrices
208 if (xx[j]->ncols >cl) cl=xx[j]->ncols; // for lifting matrices
209 }
210 if (rw*cl !=cnt)
211 {
212 WerrorS("format mismatch in CRT");
213 return NULL;
214 }
215 int cpus=(int)(long)feOptValue(FE_OPT_CPUS);
218 /* start no more than MAX_PROCESS-1 children */
219 cpus=si_min(cpus,cnt/5);
220 if (cpus<=1)
221 /* at least 5 polys for each process, or switch to seriell version */
222 return id_ChineseRemainder(xx,q,rl,r);
223 ideal result=idInit(cnt,xx[0]->rank);
224 result->nrows=rw; // for lifting matrices
225 result->ncols=cl; // for lifting matrices
226 int parent_pid=getpid();
227 using namespace vspace;
228 vmem_init();
229 // Create a queue of int
230 VRef<Queue<int> > queue = vnew<Queue<int> >();
231 for(int i=cnt-1;i>=0; i--)
232 {
233 queue->enqueue(i); // the tasks: construct poly p[i]
234 }
235 for(int i=cpus;i>=0;i--)
236 {
237 queue->enqueue(-1); // stop sign, one for each child
238 }
239 // Create a queue of polys
241 int *pids=(int*)omAlloc0(cpus*sizeof(int));
242 for (int i=0;i<cpus;i++)
243 {
244 int pid = fork_process();
245 if (pid==0) break; //child
246 pids[i]=pid;
247 }
248 if (parent_pid!=getpid()) // child ------------------------------------------
249 {
252 feSetOptValue(FE_OPT_CPUS,0);
253 number *x=(number *)omAlloc(rl*sizeof(number));
254 poly *p=(poly *)omAlloc(rl*sizeof(poly));
255 CFArray inv_cache(rl);
258 loop
259 {
260 int ind=queue->dequeue();
261 if (ind== -1)
262 {
263 _exit(0);
264 }
265
266 for(int j=rl-1;j>=0;j--)
267 {
268 if(ind>=IDELEMS(xx[j])*xx[j]->nrows) // out of range of this ideal
269 p[j]=NULL;
270 else
271 p[j]=xx[j]->m[ind];
272 }
273 poly res=p_ChineseRemainder(p,x,q,rl,inv_cache,r);
274 long l=size_poly(res,r);
275 //printf("size: %ld kB\n",(l+1023)/1024);
276 VRef<VString> msg = vstring(l+1);
277 char *s=(char*)msg->str();
278 send_poly(s,ind,res,r);
279 rqueue->enqueue(msg);
280 if (TEST_OPT_PROT) printf(".");
281 }
282 }
283 else // parent ---------------------------------------------------
284 {
285 if (TEST_OPT_PROT) printf("%d children created\n",cpus);
286 VRef<VString> msg;
287 while(cnt>0)
288 {
289 msg=rqueue->dequeue();
290 char *s=(char*)msg->str();
291 int ind;
292 poly p=NULL;
293 get_poly(s,ind,&p,r);
294 //printf("got res[%d]\n",ind);
295 result->m[ind]=p;
296 msg.free();
297 cnt--;
298 }
299 int i=cpus-1;
300 int done=0;
301 while(done!=cpus)
302 {
303 BOOLEAN all_done=TRUE;
304 if (pids[i]>0)
305 {
306 int p=si_waitpid(pids[i],NULL,WNOHANG);
307 if (p>0)
308 {
309 pids[i]=0;
310 done++;
311 }
312 }
313 if (i==0) i=cpus;
314 i--;
315 }
316 omFreeSize(pids,cpus*sizeof(int));
317 // removes queues
318 queue.free();
319 rqueue.free();
320 vmem_deinit();
321 }
322 return result;
323}
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
static int si_min(const int a, const int b)
Definition auxiliary.h:126
Array< CanonicalForm > CFArray
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
cl
Definition cfModGcd.cc:4108
int int ncols
Definition cf_linsys.cc:32
int nrows
Definition cf_linsys.cc:32
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
void sig_term_hdl_child(int)
Definition cntrlc.cc:86
return result
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
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
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:169
static long size_poly(poly p, const ring r)
Definition kChinese.cc:188
static char * send_poly(char *s, int ind, poly p, const ring r)
Definition kChinese.cc:150
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:3086
static const int MAX_PROCESS
Definition vspace.h:1419
VRef< T > vnew()
Definition vspace.h:1872
pid_t fork_process()
Definition vspace.cc:1081
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 omFreeSize(addr, size)
#define omAlloc(size)
#define omAlloc0(size)
#define NULL
Definition omList.c:12
#define TEST_OPT_PROT
Definition options.h:105
ideal idInit(int idsize, int rank)
initialise an ideal / module
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
#define IDELEMS(i)
#define loop
Definition structs.h:71
void free()
Definition vspace.h:1805

◆ id_Farey_0()

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

Definition at line 325 of file kChinese.cc.

326{
327 int cnt=IDELEMS(x)*x->nrows;
328 int cpus=(int)(long)feOptValue(FE_OPT_CPUS);
331 /* start no more than MAX_PROCESS-1 children */
332 cpus=si_min(cpus,cnt/5);
333 if (cpus<=1) /* at least 5 polys for each process,
334 or switch to seriell version */
335 return id_Farey(x,N,r);
336 ideal result=idInit(cnt,x->rank);
337 result->nrows=x->nrows; // for lifting matrices
338 result->ncols=x->ncols; // for lifting matrices
339
340 int parent_pid=getpid();
341 using namespace vspace;
342 vmem_init();
343 // Create a queue of int
344 VRef<Queue<int> > queue = vnew<Queue<int> >();
345 for(int i=cnt-1;i>=0; i--)
346 {
347 queue->enqueue(i); // the tasks: construct poly p[i]
348 }
349 for(int i=cpus;i>=0;i--)
350 {
351 queue->enqueue(-1); // stop sign, one for each child
352 }
353 // Create a queue of polys
355 int *pids=(int*)omAlloc0(cpus*sizeof(int));
356 for (int i=0;i<cpus;i++)
357 {
358 int pid = fork_process();
359 if (pid==0) break; //child
360 pids[i]=pid;
361 }
362 if (parent_pid!=getpid()) // child ------------------------------------------
363 {
366 feSetOptValue(FE_OPT_CPUS,0);
367 loop
368 {
369 int ind=queue->dequeue();
370 if (ind== -1)
371 {
372 _exit(0);
373 }
374
375 poly res=p_Farey(x->m[ind],N,r);
376 long l=size_poly(res,r);
377 VRef<VString> msg = vstring(l+1);
378 char *s=(char*)msg->str();
379 send_poly(s,ind,res,r);
380 rqueue->enqueue(msg);
381 if (TEST_OPT_PROT) printf(".");
382 }
383 }
384 else // parent ---------------------------------------------------
385 {
386 if (TEST_OPT_PROT) printf("%d children created\n",cpus);
387 VRef<VString> msg;
388 while(cnt>0)
389 {
390 msg=rqueue->dequeue();
391 char *s=(char*)msg->str();
392 int ind;
393 poly p=NULL;
394 get_poly(s,ind,&p,r);
395 //printf("got res[%d]\n",ind);
396 result->m[ind]=p;
397 msg.free();
398 cnt--;
399 }
400 int i=cpus-1;
401 int done=0;
402 while(done!=cpus)
403 {
404 BOOLEAN all_done=TRUE;
405 if (pids[i]>0)
406 {
407 int p=si_waitpid(pids[i],NULL,WNOHANG);
408 if (p>0)
409 {
410 pids[i]=0;
411 done++;
412 }
413 }
414 if (i==0) i=cpus;
415 i--;
416 }
417 omFreeSize(pids,cpus*sizeof(int));
418 // removes queues
419 queue.free();
420 rqueue.free();
421 vmem_deinit();
422 }
423 return result;
424}
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
ideal id_Farey(ideal x, number N, const ring r)
Definition ideals.cc:3074
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 )