=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2018/engine/nd.c,v retrieving revision 1.56 retrieving revision 1.64 diff -u -p -r1.56 -r1.64 --- OpenXM_contrib2/asir2018/engine/nd.c 2021/12/05 22:41:04 1.56 +++ OpenXM_contrib2/asir2018/engine/nd.c 2022/03/09 07:50:51 1.64 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.55 2021/11/29 09:19:33 noro Exp $ */ +/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.63 2022/01/13 08:15:02 noro Exp $ */ #include "nd.h" @@ -70,7 +70,7 @@ static NODE nd_tracelist; static NODE nd_alltracelist; static int nd_gentrace,nd_gensyz,nd_nora,nd_newelim,nd_intersect,nd_lf,nd_norb; static int nd_f4_td,nd_sba_f4step,nd_sba_pot,nd_sba_largelcm,nd_sba_dontsort,nd_sba_redundant_check; -static int nd_top,nd_sba_syz,nd_sba_inputisgb; +static int nd_top,nd_sba_syz,nd_sba_inputisgb,nd_sba_heu; static int *nd_gbblock; static NODE nd_nzlist,nd_check_splist; static int nd_splist; @@ -1303,6 +1303,7 @@ INLINE int ndl_find_reducer_s(UINT *dg,SIG sig) quo->pos = nd_psh[i]->sig->pos; _adddl(nd_nvar,DL(quo),nd_sba_hm[quo->pos],DL2(quo)); ret = comp_sig(sig,quo); +// if ( ret >= 0 ) { singular = 0; break; } if ( ret > 0 ) { singular = 0; break; } if ( ret == 0 ) { /* fprintf(asir_out,"s"); fflush(asir_out); */ singular = 1; } } @@ -2423,6 +2424,7 @@ int do_diagonalize(int sugar,int m) LIST l; Z iq; + if ( diag_period == 0 ) return 1; for ( i = nd_psn-1; i >= 0 && SG(nd_psh[i]) == sugar; i-- ) { if ( nd_gentrace ) { /* Trace = [1,index,1,1] */ @@ -2505,6 +2507,7 @@ void setup_hpdata(HPDATA final,HPDATA current) final->n = n = nd_nvar; final->hn = (P)BDY(nd_hpdata); +#if 0 if ( NEXT(nd_hpdata) != 0 && (weight=(LIST)BDY(NEXT(nd_hpdata))) != 0 ) { wlen = length(BDY(weight)); if ( n != wlen ) @@ -2514,6 +2517,9 @@ void setup_hpdata(HPDATA final,HPDATA current) w[i] = ZTOS((Z)BDY(nd)); } else w = 0; +#else + w = current_dl_weight_vector; +#endif MKVECT(x,n); for ( i = 0; i < n; i++ ) { NEWDL(dl,n); dl->d[i] = 1; dl->td = 1; BDY(x)[i] = dl; @@ -2541,7 +2547,7 @@ int comp_hn(P a, P b) DCP dc; subp(CO,a,b,&s); - if ( !s ) return 99999999; /* XXX */ + if ( !s ) return -1; else if ( OID(s) == 1 ) return 0; else { for ( dc = DC(s); NEXT(dc); dc = NEXT(dc) ); @@ -2584,16 +2590,20 @@ ND_pairs nd_remove_same_sugar( ND_pairs d, int sugar) { struct oND_pairs root; ND_pairs prev,cur; + int i; root.next = d; prev = &root; cur = d; + i = 0; while ( cur ) { - if ( SG(cur) == sugar ) + if ( SG(cur) == sugar ) { prev->next = cur->next; - else + i++; + } else prev = cur; cur = cur->next; } + if ( DP_Print && i ) fprintf(asir_out,"[%d]",i); return root.next; } @@ -2704,17 +2714,19 @@ get_eg(&eg2); add_eg(&eg_update,&eg1,&eg2); g = update_base(g,nh); FREENDP(l); if ( nd_hpdata ) { - int dg; + int dg,sugar0; update_hpdata(¤t_hpdata,nh); dg = comp_hn(final_hpdata.hn,current_hpdata.hn); - if ( dg > sugar ) { - printexpr(CO,(Obj)current_hpdata.hn); printf("\n"); + if ( dg < 0 ) { + int d_len; + for ( d_len = 0; d; d = d->next, d_len++); + fprintf(asir_out,"[%d] We found a gb\n",d_len); } - while ( d && dg > sugar ) { - if ( DP_Print ) fprintf(asir_out,"sugar=%d done.\n",sugar); - d = nd_remove_same_sugar(d,sugar); - sugar++; + sugar0 = sugar; + while ( d && dg > sugar0 ) { + d = nd_remove_same_sugar(d,sugar0); + sugar0++; } } } else { @@ -2726,14 +2738,14 @@ get_eg(&eg2); add_eg(&eg_update,&eg1,&eg2); MKNODE(t,list,nd_alltracelist); nd_alltracelist = t; nd_tracelist = 0; } - if ( DP_Print ) { printf("."); fflush(stdout); } + if ( DP_Print ) { fprintf(asir_out,"."); fflush(asir_out); } FREENDP(l); } } conv_ilist(nd_demand,0,g,indp); if ( !checkonly && DP_Print ) { - printf("\nnd_gb done. Nnd_add=%d,Npairs=%d, Nnfnz=%d,Nnfz=%d,",Nnd_add,Npairs,Nnfnz,Nnfz); - printf("Nremoved=%d\n",NcriB+NcriMF+Ncri2); + fprintf(asir_out,"\nnd_gb done. Nbase=%d,Nnd_add=%d,Npairs=%d, Nnfnz=%d,Nnfz=%d,",nd_psn,Nnd_add,Npairs,Nnfnz,Nnfz); + fprintf(asir_out,"Nremoved=%d\n",NcriB+NcriMF+Ncri2); fflush(asir_out); } if ( DP_Print ) { @@ -3161,13 +3173,25 @@ get_eg(&eg2); get_eg(&eg2); add_eg(&eg_updatepairs,&eg1,&eg2); nd_sba_pos[sig->pos] = append_one(nd_sba_pos[sig->pos],nh); if ( nd_hpdata ) { + int dg,sugar0; + get_eg(&eg1); update_hpdata(¤t_hpdata,nh); get_eg(&eg2); add_eg(&eg_hpdata,&eg1,&eg2); - if ( !compp(CO,final_hpdata.hn,current_hpdata.hn) ) { + dg = comp_hn(final_hpdata.hn,current_hpdata.hn); +// if ( !compp(CO,final_hpdata.hn,current_hpdata.hn) ) + if ( dg < 0 ) { if ( DP_Print ) { printf("\nWe found a gb.\n"); } break; - } + } else if ( nd_sba_heu == 1 ) { + for ( i = 0; i < ngen; i++ ) { + sugar0 = sugar; + while ( d[i] && dg > sugar0 ) { + d[i] = nd_remove_same_sugar(d[i],sugar0); + sugar0++; + } + } + } } } else { d[ind] = d[ind]->next; dlen--; @@ -3187,7 +3211,7 @@ get_eg(&eg2); add_eg(&eg_remove,&eg1,&eg2); g = conv_ilist_s(nd_demand,0,indp); if ( DP_Print ) { printf("\ndlen=%d,nd_sba done. nd_add=%d,Nsyz=%d,Nsamesig=%d,Nnominimal=%d\n",dlen,Nnd_add,Nsyz,Nsamesig,Nnominimal); - printf("Nnfnz=%d,Nnfz=%d,Nnfsingular=%d\n",Nnfnz,Nnfz,Nnfs); + printf("Nbase=%d,Nnfnz=%d,Nnfz=%d,Nnfsingular=%d\n",nd_psn,Nnfnz,Nnfz,Nnfs); fflush(stdout); if ( nd_sba_redundant_check ) printf("Nredundant=%d\n",Nredundant); @@ -3322,6 +3346,7 @@ int do_diagonalize_trace(int sugar,int m) Z iq; P cont,cont1; + if ( diag_period == 0 ) return 1; for ( i = nd_psn-1; i >= 0 && SG(nd_psh[i]) == sugar; i-- ) { if ( nd_gentrace ) { /* Trace = [1,index,1,1] */ @@ -3505,24 +3530,26 @@ again: d = update_pairs(d,g,nh,0); g = update_base(g,nh); if ( nd_hpdata ) { - int dg; + int dg,sugar0; update_hpdata(¤t_hpdata,nh); dg = comp_hn(final_hpdata.hn,current_hpdata.hn); - if ( dg > sugar ) { - printexpr(CO,(Obj)current_hpdata.hn); printf("\n"); + if ( dg < 0 ) { + int d_len; + for ( d_len = 0; d; d = d->next, d_len++); + fprintf(asir_out,"[%d] We found a gb\n",d_len); } - while ( d && dg > sugar ) { - if ( DP_Print ) fprintf(asir_out,"sugar=%d done.\n",sugar); - d = nd_remove_same_sugar(d,sugar); - sugar++; + sugar0 = sugar; + while ( d && dg > sugar0 ) { + d = nd_remove_same_sugar(d,sugar0); + sugar0++; } } } else { - if ( DP_Print ) { printf("*"); fflush(stdout); } + if ( DP_Print ) { fprintf(asir_out,"*"); fflush(asir_out); } } } else { - if ( DP_Print ) { printf("."); fflush(stdout); } + if ( DP_Print ) { fprintf(asir_out,"."); fflush(asir_out); } } FREENDP(l); } @@ -3534,7 +3561,7 @@ again: } } conv_ilist(nd_demand,1,g,indp); - if ( DP_Print ) { printf("\nnd_gb_trace done.\n"); fflush(stdout); } + if ( DP_Print ) { fprintf(asir_out,"\nnd_gb_trace done. Nbase=%d\n",nd_psn); fflush(asir_out); } return g; } @@ -5471,7 +5498,7 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int Obj obj; NumberField nf; struct order_spec *ord1; - struct oEGT eg_check,eg0,eg1; + struct oEGT eg_check,eg_gb,eg_intred,eg0,eg1; NODE tr,tl1,tl2,tl3,tl4; LIST l1,l2,l3,l4,l5; int *perm; @@ -5609,7 +5636,8 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int } if ( MaxDeg > 0 ) nocheck = 1; while ( 1 ) { - tl1 = tl2 = tl3 = tl4 = 0; + get_eg(&eg0); + tl1 = tl2 = tl3 = tl4 = 0; if ( Demand ) nd_demand = 1; ret = ndv_setup(m,1,fd0,nd_gbblock?1:0,0,0); @@ -5635,10 +5663,13 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int nd_init_ord(ord); nd_setup_parameters(nvar,0); } + get_eg(&eg1); init_eg(&eg_gb); add_eg(&eg_gb,&eg0,&eg1); nd_demand = 0; cand = ndv_reducebase(cand,perm); if ( nd_gentrace ) { tl1 = nd_alltracelist; nd_alltracelist = 0; } + get_eg(&eg0); cand = ndv_reduceall(0,cand); + get_eg(&eg1); init_eg(&eg_intred); add_eg(&eg_intred,&eg0,&eg1); cbpe = nd_bpe; if ( nd_gentrace ) { tl2 = nd_alltracelist; nd_alltracelist = 0; } get_eg(&eg0); @@ -5676,7 +5707,8 @@ void nd_gr_trace(LIST f,LIST v,int trace,int homo,int } get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); if ( DP_Print ) - fprintf(asir_out,"check=%.3fsec\n",eg_check.exectime); + fprintf(asir_out,"gb=%.3fsec,check=%.3fsec,intred=%.3fsec\n", + eg_gb.exectime,eg_check.exectime,eg_intred.exectime); /* dp->p */ nd_bpe = cbpe; nd_setup_parameters(nd_nvar,0); @@ -10658,7 +10690,7 @@ void parse_nd_option(VL vl,NODE opt) nd_f4_td = 0; nd_sba_f4step = 2; nd_sba_pot = 0; nd_sba_largelcm = 0; nd_sba_dontsort = 0; nd_top = 0; nd_sba_redundant_check = 0; nd_sba_syz = 0; nd_sba_modord = 0; nd_sba_inputisgb = 0; - nd_hpdata = 0; + nd_hpdata = 0; nd_sba_heu = 0; for ( t = opt; t; t = NEXT(t) ) { p = BDY((LIST)BDY(t)); @@ -10727,6 +10759,8 @@ void parse_nd_option(VL vl,NODE opt) nd_sba_dontsort = value?1:0; } else if ( !strcmp(key,"sba_syz") ) { nd_sba_syz = value?1:0; + } else if ( !strcmp(key,"sba_heu") ) { + nd_sba_heu = value?1:0; } else if ( !strcmp(key,"sba_modord") ) { // value=[vlist,ordspec,weight] u = BDY((LIST)value);