=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2018/engine/nd.c,v retrieving revision 1.11 retrieving revision 1.15 diff -u -p -r1.11 -r1.15 --- OpenXM_contrib2/asir2018/engine/nd.c 2018/10/23 04:53:37 1.11 +++ OpenXM_contrib2/asir2018/engine/nd.c 2019/04/20 06:04:18 1.15 @@ -1,9 +1,9 @@ -/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.10 2018/10/19 23:27:38 noro Exp $ */ +/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.14 2019/03/03 05:21:17 noro Exp $ */ #include "nd.h" int Nnd_add,Nf4_red; -struct oEGT eg_search; +struct oEGT eg_search,f4_symb,f4_conv,f4_elim1,f4_elim2; int diag_period = 6; int weight_check = 1; @@ -78,6 +78,7 @@ NDV pltondv(VL vl,VL dvl,LIST p); void pltozpl(LIST l,Q *cont,LIST *pp); void ndl_max(UINT *d1,unsigned *d2,UINT *d); void nmtodp(int mod,NM m,DP *r); +void ndltodp(UINT *d,DP *r); NODE reverse_node(NODE n); P ndc_div(int mod,union oNDC a,union oNDC b); P ndctop(int mod,union oNDC c); @@ -1130,7 +1131,7 @@ INLINE int ndl_hash_value(UINT *d) r = 0; for ( i = 0; i < nd_wpd; i++ ) - r = (r*10007+d[i]); + r = (r*1511+d[i]); r %= REDTAB_LEN; return r; } @@ -3224,6 +3225,7 @@ void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int int *perm; EPOS oepos; int obpe,oadv,ompos,cbpe; + VECT hvect; nd_module = 0; if ( !m && Demand ) nd_demand = 1; @@ -3334,6 +3336,11 @@ void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int if ( !x ) { *rp = 0; return; } + if ( nd_gentrace ) { + MKVECT(hvect,nd_psn); + for ( i = 0; i < nd_psn; i++ ) + ndltodp(nd_psh[i]->dl,(DP *)&BDY(hvect)[i]); + } if ( !ishomo && homo ) { /* dehomogenization */ for ( t = x; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); @@ -3380,8 +3387,7 @@ FINAL: if ( f4 ) { STOZ(16,bpe); STOZ(nd_last_nonzero,last_nonzero); - tr = mknode(5,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe,last_nonzero); MKLIST(*rp,tr); - + tr = mknode(6,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe,last_nonzero,hvect); MKLIST(*rp,tr); } else { tl1 = reverse_node(tl1); tl2 = reverse_node(tl2); tl3 = reverse_node(tl3); @@ -3401,7 +3407,7 @@ FINAL: MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3); MKLIST(l5,tl4); STOZ(nd_bpe,bpe); - tr = mknode(8,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe); MKLIST(*rp,tr); + tr = mknode(9,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe,hvect); MKLIST(*rp,tr); } } #if 0 @@ -3668,6 +3674,7 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int int *perm; int j,ret; Z jq,bpe; + VECT hvect; nd_module = 0; nd_lf = 0; @@ -3785,6 +3792,11 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int else m = get_lprime(++mindex); continue; } + if ( nd_gentrace ) { + MKVECT(hvect,nd_psn); + for ( i = 0; i < nd_psn; i++ ) + ndltodp(nd_psh[i]->dl,(DP *)&BDY(hvect)[i]); + } if ( !ishomo && homo ) { /* dehomogenization */ for ( t = cand; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); @@ -3862,7 +3874,7 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3); MKLIST(l5,tl4); STOZ(nd_bpe,bpe); - tr = mknode(8,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe); MKLIST(*rp,tr); + tr = mknode(9,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5,bpe,hvect); MKLIST(*rp,tr); } } @@ -3926,6 +3938,18 @@ void nmtodp(int mod,NM m,DP *r) *r = dp; } +void ndltodp(UINT *d,DP *r) +{ + DP dp; + MP mr; + + NEWMP(mr); + mr->dl = ndltodl(nd_nvar,d); + mr->c = (Obj)ONE; + NEXT(mr) = 0; MKDP(nd_nvar,mr,dp); dp->sugar = mr->dl->td; + *r = dp; +} + void ndl_print(UINT *dl) { int n; @@ -4090,7 +4114,7 @@ void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos NMV m,mr0,mr,t; len = p->len; - for ( m = BDY(p), i = 0, max = 1; i < len; NMV_OADV(m), i++ ) + for ( m = BDY(p), i = 0, max = 0; i < len; NMV_OADV(m), i++ ) max = MAX(max,TD(DL(m))); mr0 = nmv_adv>oadv?(NMV)REALLOC(BDY(p),len*nmv_adv):BDY(p); m = (NMV)((char *)mr0+(len-1)*oadv); @@ -4235,14 +4259,18 @@ void mpz_removecont_array(mpz_t *c,int n) { mpz_t d0,a,u,u1,gcd; int i,j; - mpz_t *q,*r; + static mpz_t *q,*r; + static int c_len = 0; for ( i = 0; i < n; i++ ) if ( mpz_sgn(c[i]) ) break; if ( i == n ) return; gcdv_mpz_estimate(d0,c,n); - q = (mpz_t *)MALLOC(n*sizeof(mpz_t)); - r = (mpz_t *)MALLOC(n*sizeof(mpz_t)); + if ( n > c_len ) { + q = (mpz_t *)MALLOC(n*sizeof(mpz_t)); + r = (mpz_t *)MALLOC(n*sizeof(mpz_t)); + c_len = n; + } for ( i = 0; i < n; i++ ) { mpz_init(q[i]); mpz_init(r[i]); mpz_fdiv_qr(q[i],r[i],c[i],d0); @@ -6056,7 +6084,6 @@ int ndv_reduce_vect_q(Z *svect,int trace,int col,IndAr int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndArray *imat,NM_ind_pair *rp0,int nred) { int i,j,k,len,pos,prev; - mpz_t *svect; mpz_t cs,cr,gcd; IndArray ivect; unsigned char *ivc; @@ -6068,12 +6095,17 @@ int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndA int maxrs; double hmag; int l; + static mpz_t *svect; + static int svect_len=0; maxrs = 0; for ( i = 0; i < col && !svect0[i]; i++ ); if ( i == col ) return maxrs; hmag = p_mag((P)svect0[i])*nd_scale; - svect = (mpz_t *)MALLOC(col*sizeof(mpz_t)); + if ( col > svect_len ) { + svect = (mpz_t *)MALLOC(col*sizeof(mpz_t)); + svect_len = col; + } for ( i = 0; i < col; i++ ) { mpz_init(svect[i]); if ( svect0[i] ) @@ -6679,6 +6711,8 @@ NODE nd_f4(int m,int checkonly,int **indp) PGeoBucket bucket; struct oEGT eg0,eg1,eg_f4; Z i1,i2,sugarq; + + init_eg(&f4_symb); init_eg(&f4_conv); init_eg(&f4_conv); init_eg(&f4_elim1); init_eg(&f4_elim2); #if 0 ndv_alloc = 0; #endif @@ -6724,7 +6758,7 @@ NODE nd_f4(int m,int checkonly,int **indp) d = nd_reconstruct(0,d); continue; } - get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); + get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); add_eg(&f4_symb,&eg0,&eg1); if ( DP_Print ) fprintf(asir_out,"sugar=%d,symb=%.3fsec,", sugar,eg_f4.exectime); @@ -6773,8 +6807,11 @@ NODE nd_f4(int m,int checkonly,int **indp) #if 0 fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); #endif - if ( DP_Print ) - fprintf(asir_out,"number of red=%d\n",Nf4_red); + if ( DP_Print ) { + fprintf(asir_out,"number of red=%d,",Nf4_red); + fprintf(asir_out,"symb=%.3fsec,conv=%.3fsec,elim1=%.3fsec,elim2=%.3fsec\n", + f4_symb.exectime,f4_conv.exectime,f4_elim1.exectime,f4_elim2.exectime); + } conv_ilist(nd_demand,0,g,indp); return g; } @@ -7083,7 +7120,7 @@ NODE nd_f4_red(int m,ND_pairs sp0,int trace,UINT *s0ve rhead[imat[i]->head] = 1; start = imat[i]->head; } - get_eg(&eg1); init_eg(&eg_conv); add_eg(&eg_conv,&eg0,&eg1); + get_eg(&eg1); init_eg(&eg_conv); add_eg(&eg_conv,&eg0,&eg1); add_eg(&f4_conv,&eg0,&eg1); if ( DP_Print ) { fprintf(asir_out,"conv=%.3fsec,",eg_conv.exectime); fflush(asir_out); @@ -9088,33 +9125,27 @@ int ndv_reduce_vect64(int m,mp_limb_t *svect,mp_limb_t ivc = ivect->index.c; for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { pos = prev+ivc[j]; c1 = CM(mr); prev = pos; - if ( c1 ) { - c2 = svect[pos]+c1*c; - if ( c2 < svect[pos] ) cvect[pos]++; - svect[pos] = c2; - } + c2 = svect[pos]+c1*c; + if ( c2 < svect[pos] ) cvect[pos]++; + svect[pos] = c2; } break; case 2: ivs = ivect->index.s; for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { pos = prev+ivs[j]; c1 = CM(mr); prev = pos; - if ( c1 ) { - c2 = svect[pos]+c1*c; - if ( c2 < svect[pos] ) cvect[pos]++; - svect[pos] = c2; - } + c2 = svect[pos]+c1*c; + if ( c2 < svect[pos] ) cvect[pos]++; + svect[pos] = c2; } break; case 4: ivi = ivect->index.i; for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { pos = prev+ivi[j]; c1 = CM(mr); prev = pos; - if ( c1 ) { - c2 = svect[pos]+c1*c; - if ( c2 < svect[pos] ) cvect[pos]++; - svect[pos] = c2; - } + c2 = svect[pos]+c1*c; + if ( c2 < svect[pos] ) cvect[pos]++; + svect[pos] = c2; } break; } @@ -9170,7 +9201,7 @@ NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U } nd_free(spol); } - get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); + get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); add_eg(&f4_elim1,&eg0,&eg1); if ( DP_Print ) { fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime); fflush(asir_out); @@ -9191,7 +9222,7 @@ NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U if ( r0 ) NEXT(r) = 0; for ( ; i < sprow; i++ ) GCFREE(spmat[i]); - get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); + get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); add_eg(&f4_elim2,&eg1,&eg2); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); if ( DP_Print ) { fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime);