=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/nd.c,v retrieving revision 1.198 retrieving revision 1.203 diff -u -p -r1.198 -r1.203 --- OpenXM_contrib2/asir2000/engine/nd.c 2012/04/10 07:15:07 1.198 +++ OpenXM_contrib2/asir2000/engine/nd.c 2013/01/31 01:13:47 1.203 @@ -1,10 +1,11 @@ -/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.197 2011/08/15 09:21:00 noro Exp $ */ +/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.202 2013/01/30 08:03:18 noro Exp $ */ #include "nd.h" struct oEGT eg_search; int diag_period = 6; +int weight_check = 1; int (*ndl_compare_function)(UINT *a1,UINT *a2); int nd_dcomp; NM _nm_free_list; @@ -64,7 +65,6 @@ LIST ndvtopl(int mod,VL vl,VL dvl,NDV p,int rank); 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); -pointer GC_malloc_atomic_ignore_off_page(int); void nmtodp(int mod,NM m,DP *r); NODE reverse_node(NODE n); P ndc_div(int mod,union oNDC a,union oNDC b); @@ -92,7 +92,7 @@ void _NM_alloc() int i; for ( i = 0; i < 1024; i++ ) { - p = (NM)GC_malloc(sizeof(struct oNM)+(nd_wpd-1)*sizeof(UINT)); + p = (NM)MALLOC(sizeof(struct oNM)+(nd_wpd-1)*sizeof(UINT)); p->next = _nm_free_list; _nm_free_list = p; } } @@ -103,7 +103,7 @@ void _ND_alloc() int i; for ( i = 0; i < 1024; i++ ) { - p = (ND)GC_malloc(sizeof(struct oND)); + p = (ND)MALLOC(sizeof(struct oND)); p->body = (NM)_nd_free_list; _nd_free_list = p; } } @@ -114,7 +114,7 @@ void _NDP_alloc() int i; for ( i = 0; i < 1024; i++ ) { - p = (ND_pairs)GC_malloc(sizeof(struct oND_pairs) + p = (ND_pairs)MALLOC(sizeof(struct oND_pairs) +(nd_wpd-1)*sizeof(UINT)); p->next = _ndp_free_list; _ndp_free_list = p; } @@ -1581,7 +1581,7 @@ void free_pbucket(PGeoBucket b) { nd_free(b->body[i]); b->body[i] = 0; } - GC_free(b); + GCFREE(b); } void add_pbucket_symbolic(PGeoBucket g,ND d) @@ -2807,7 +2807,7 @@ NODE postprocess_algcoef(VL av,NODE alist,NODE r) return u0; } -void nd_gr(LIST f,LIST v,int m,int homo,int f4,struct order_spec *ord,LIST *rp) +void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int f4,struct order_spec *ord,LIST *rp) { VL tv,fv,vv,vc,av; NODE fd,fd0,r,r0,t,x,s,xx,alist; @@ -2957,7 +2957,8 @@ FINAL: for ( r0 = 0, t = x; t; t = NEXT(t) ) { NEXTNODE(r0,r); if ( nd_module ) BDY(r) = ndvtopl(m,CO,vv,BDY(t),mrank); - else BDY(r) = ndvtop(m,CO,vv,BDY(t)); + else if ( retdp ) BDY(r) = ndvtodp(m,BDY(t)); + else BDY(r) = ndvtop(m,CO,vv,BDY(t)); } if ( r0 ) NEXT(r) = 0; if ( nalg ) @@ -3841,7 +3842,7 @@ void nd_free(ND p) void ndv_free(NDV p) { - GC_free(BDY(p)); + GCFREE(BDY(p)); } void nd_append_red(UINT *d,int i) @@ -3952,6 +3953,31 @@ void nd_setup_parameters(int nvar,int max) { else if ( max < 65536 ) nd_bpe = 16; else nd_bpe = 32; } + if ( !do_weyl && weight_check && (current_dl_weight_vector || nd_matrix) ) { + UINT t; + int st; + int *v; + /* t = max(weights) */ + t = 0; + if ( current_dl_weight_vector ) + for ( i = 0, t = 0; i < nd_nvar; i++ ) { + if ( (st=current_dl_weight_vector[i]) < 0 ) st = -st; + if ( t < st ) t = st; + } + if ( nd_matrix ) + for ( i = 0; i < nd_matrix_len; i++ ) + for ( j = 0, v = nd_matrix[i]; j < nd_nvar; j++ ) { + if ( (st=v[j]) < 0 ) st = -st; + if ( t < st ) t = st; + } + /* i = bitsize of t */ + for ( i = 0; t; t >>=1, i++ ); + /* i += bitsize of nd_nvar */ + for ( t = nd_nvar; t; t >>=1, i++); + /* nd_bpe+i = bitsize of max(weights)*max(exp)*nd_nvar */ + if ( (nd_bpe+i) >= 31 ) + error("nd_setup_parameters : too large weight"); + } nd_epw = (sizeof(UINT)*8)/nd_bpe; elen = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0); nd_exporigin = nd_get_exporigin(nd_ord); @@ -4806,7 +4832,7 @@ NDV ndtondv(int mod,ND p) if ( !p ) return 0; len = LEN(p); if ( mod ) - m0 = m = (NMV)GC_malloc_atomic_ignore_off_page(len*nmv_adv); + m0 = m = (NMV)MALLOC_ATOMIC_IGNORE_OFF_PAGE(len*nmv_adv); else m0 = m = MALLOC(len*nmv_adv); #if 0 @@ -4931,6 +4957,8 @@ NODE ndv_reducebase(NODE x,int *perm) void nd_init_ord(struct order_spec *ord) { nd_module = (ord->id >= 256); + nd_matrix = 0; + nd_matrix_len = 0; switch ( ord->id ) { case 0: switch ( ord->ord.simple ) { @@ -5501,7 +5529,7 @@ NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea for ( j = 0, len = 0; j < spcol; j++ ) if ( vect[j] ) len++; if ( !len ) return 0; else { - mr0 = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len); + mr0 = (NMV)MALLOC_ATOMIC_IGNORE_OFF_PAGE(nmv_adv*len); #if 0 ndv_alloc += nmv_adv*len; #endif @@ -5531,7 +5559,7 @@ NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead for ( j = 0, len = 0; j < spcol; j++ ) if ( vect[j] ) len++; if ( !len ) return 0; else { - mr0 = (NMV)GC_malloc(nmv_adv*len); + mr0 = (NMV)MALLOC(nmv_adv*len); #if 0 ndv_alloc += nmv_adv*len; #endif @@ -5563,7 +5591,7 @@ NDV plain_vect_to_ndv_q(Q *vect,int col,UINT *s0vect) for ( j = 0, len = 0; j < col; j++ ) if ( vect[j] ) len++; if ( !len ) return 0; else { - mr0 = (NMV)GC_malloc(nmv_adv*len); + mr0 = (NMV)MALLOC(nmv_adv*len); #if 0 ndv_alloc += nmv_adv*len; #endif @@ -6004,7 +6032,7 @@ NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s fflush(asir_out); } /* free index arrays */ - for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c); + for ( i = 0; i < nred; i++ ) GCFREE(imat[i]->index.c); /* elimination (2nd step) */ colstat = (int *)ALLOCA(spcol*sizeof(int)); @@ -6017,11 +6045,11 @@ NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s NEXTNODE(r0,r); BDY(r) = (pointer)vect_to_ndv(spmat[i],spcol,col,rhead,s0vect); SG((NDV)BDY(r)) = spsugar[i]; - GC_free(spmat[i]); + GCFREE(spmat[i]); } if ( r0 ) NEXT(r) = 0; - for ( ; i < sprow; i++ ) GC_free(spmat[i]); + for ( ; i < sprow; i++ ) GCFREE(spmat[i]); get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); if ( DP_Print ) { @@ -6085,7 +6113,7 @@ NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U fflush(asir_out); } /* free index arrays */ -/* for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c); */ +/* for ( i = 0; i < nred; i++ ) GCFREE(imat[i]->index.c); */ /* elimination (2nd step) */ colstat = (int *)ALLOCA(spcol*sizeof(int)); @@ -6094,7 +6122,7 @@ NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U for ( i = 0; i < rank; i++ ) { w[rank-i-1] = (pointer)vect_to_ndv_q(spmat[i],spcol,col,rhead,s0vect); SG((NDV)w[rank-i-1]) = spsugar[i]; -/* GC_free(spmat[i]); */ +/* GCFREE(spmat[i]); */ } #if 0 qsort(w,rank,sizeof(NDV), @@ -6106,7 +6134,7 @@ NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U } if ( r0 ) NEXT(r) = 0; -/* for ( ; i < sprow; i++ ) GC_free(spmat[i]); */ +/* for ( ; i < sprow; i++ ) GCFREE(spmat[i]); */ get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); if ( DP_Print ) { @@ -6238,7 +6266,7 @@ NDV nd_recv_ndv() len = nd_recv_int(); if ( !len ) return 0; else { - m0 = m = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len); + m0 = m = (NMV)MALLOC_ATOMIC_IGNORE_OFF_PAGE(nmv_adv*len); #if 0 ndv_alloc += len*nmv_adv; #endif