version 1.77, 2003/10/08 09:09:04 |
version 1.84, 2003/10/18 01:39:42 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.76 2003/09/28 09:18:57 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.83 2003/10/17 05:15:20 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 270 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 270 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp); |
void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp); |
NODE nd_f4(int m); |
NODE nd_f4(int m); |
NODE nd_gb(int m,int ishomo,int checkonly); |
NODE nd_gb(int m,int ishomo,int checkonly); |
NODE nd_gb_trace(int m); |
NODE nd_gb_trace(int m,int ishomo); |
|
|
/* ndl functions */ |
/* ndl functions */ |
int ndl_weight(UINT *d); |
int ndl_weight(UINT *d); |
Line 784 INLINE int ndl_equal(UINT *d1,UINT *d2) |
|
Line 784 INLINE int ndl_equal(UINT *d1,UINT *d2) |
|
{ |
{ |
int i; |
int i; |
|
|
for ( i = 0; i < nd_wpd; i++ ) |
switch ( nd_wpd ) { |
if ( *d1++ != *d2++ ) |
case 2: |
return 0; |
if ( TD(d2) != TD(d1) ) return 0; |
return 1; |
if ( d2[1] != d1[1] ) return 0; |
|
return 1; |
|
break; |
|
case 3: |
|
if ( TD(d2) != TD(d1) ) return 0; |
|
if ( d2[1] != d1[1] ) return 0; |
|
if ( d2[2] != d1[2] ) return 0; |
|
return 1; |
|
break; |
|
default: |
|
for ( i = 0; i < nd_wpd; i++ ) |
|
if ( *d1++ != *d2++ ) return 0; |
|
return 1; |
|
break; |
|
} |
} |
} |
|
|
INLINE void ndl_copy(UINT *d1,UINT *d2) |
INLINE void ndl_copy(UINT *d1,UINT *d2) |
|
|
l = nd_minp(d,&d); |
l = nd_minp(d,&d); |
if ( SG(l) != sugar ) { |
if ( SG(l) != sugar ) { |
if ( ishomo ) { |
if ( ishomo ) { |
for ( i = nd_psn-1; SG(nd_ps[i]) == sugar; i-- ) { |
for ( i = nd_psn-1; SG(nd_psh[i]) == sugar; i-- ) { |
s = ndvtond(m,nd_ps[i]); |
if ( nd_demand ) |
|
nfv = ndv_load(i); |
|
else |
|
nfv = nd_ps[i]; |
|
s = ndvtond(m,nfv); |
s = nd_separate_head(s,&head); |
s = nd_separate_head(s,&head); |
nd_nf(m,s,nd_ps,1,&dn,&nf); |
nd_nf(m,s,nd_ps,1,&dn,&nf); |
if ( !m ) { mulq(HCQ(head),dn.z,&q); HCQ(head) = q; } |
if ( !m ) { mulq(HCQ(head),dn.z,&q); HCQ(head) = q; } |
nf = nd_add(m,head,nf); |
nf = nd_add(m,head,nf); |
ndv_free(nd_ps[i]); |
ndv_free(nfv); |
nd_removecont(m,nf); |
nd_removecont(m,nf); |
nd_ps[i] = ndtondv(m,nf); nd_free(nf); |
nfv = ndtondv(m,nf); |
nd_bound[i] = ndv_compute_bound(nd_ps[i]); |
nd_free(nf); |
|
nd_bound[i] = ndv_compute_bound(nfv); |
|
if ( nd_demand ) { |
|
ndv_save(nfv,i); |
|
ndv_free(nfv); |
|
} else |
|
nd_ps[i] = nfv; |
} |
} |
} |
} |
sugar = SG(l); |
sugar = SG(l); |
|
|
return g; |
return g; |
} |
} |
|
|
NODE nd_gb_trace(int m) |
NODE nd_gb_trace(int m,int ishomo) |
{ |
{ |
int i,nh,sugar,stat; |
int i,nh,sugar,stat; |
NODE r,g,t; |
NODE r,g,t; |
ND_pairs d; |
ND_pairs d; |
ND_pairs l; |
ND_pairs l; |
ND h,nf,nfq; |
ND h,nf,nfq,s,head; |
NDV nfv,nfqv; |
NDV nfv,nfqv; |
|
Q q; |
union oNDC dn; |
union oNDC dn; |
|
|
g = 0; d = 0; |
g = 0; d = 0; |
Line 1841 NODE nd_gb_trace(int m) |
|
Line 1866 NODE nd_gb_trace(int m) |
|
again: |
again: |
l = nd_minp(d,&d); |
l = nd_minp(d,&d); |
if ( SG(l) != sugar ) { |
if ( SG(l) != sugar ) { |
|
if ( ishomo ) { |
|
for ( i = nd_psn-1; SG(nd_psh[i]) == sugar; i-- ) { |
|
/* for nd_ps */ |
|
s = ndvtond(m,nd_ps[i]); |
|
s = nd_separate_head(s,&head); |
|
nd_nf_pbucket(m,s,nd_ps,1,&nf); |
|
nf = nd_add(m,head,nf); |
|
ndv_free(nd_ps[i]); |
|
nd_ps[i] = ndtondv(m,nf); |
|
nd_free(nf); |
|
|
|
/* for nd_ps_trace */ |
|
if ( nd_demand ) |
|
nfv = ndv_load(i); |
|
else |
|
nfv = nd_ps_trace[i]; |
|
s = ndvtond(0,nfv); |
|
s = nd_separate_head(s,&head); |
|
nd_nf(0,s,nd_ps_trace,1,&dn,&nf); |
|
mulq(HCQ(head),dn.z,&q); HCQ(head) = q; |
|
nf = nd_add(0,head,nf); |
|
ndv_free(nfv); |
|
nd_removecont(0,nf); |
|
nfv = ndtondv(0,nf); |
|
nd_free(nf); |
|
nd_bound[i] = ndv_compute_bound(nfv); |
|
if ( nd_demand ) { |
|
ndv_save(nfv,i); |
|
ndv_free(nfv); |
|
} else |
|
nd_ps_trace[i] = nfv; |
|
} |
|
} |
sugar = SG(l); |
sugar = SG(l); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
} |
} |
Line 2318 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2376 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
NDV b; |
NDV b; |
int ishomo; |
int ishomo; |
|
|
|
if ( !m && Demand ) nd_demand = 1; |
|
else nd_demand = 0; |
|
|
ndv_alloc = 0; |
ndv_alloc = 0; |
get_vars((Obj)f,&fv); pltovl(v,&vv); |
get_vars((Obj)f,&fv); pltovl(v,&vv); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
Line 2339 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2400 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
if ( fd0 ) NEXT(fd) = 0; |
if ( fd0 ) NEXT(fd) = 0; |
ndv_setup(m,0,fd0); |
ndv_setup(m,0,fd0); |
x = f4?nd_f4(m):nd_gb(m,ishomo,0); |
x = f4?nd_f4(m):nd_gb(m,ishomo,0); |
|
nd_demand = 0; |
x = ndv_reducebase(x); |
x = ndv_reducebase(x); |
x = ndv_reduceall(m,x); |
x = ndv_reduceall(m,x); |
for ( r0 = 0, t = x; t; t = NEXT(t) ) { |
for ( r0 = 0, t = x; t; t = NEXT(t) ) { |
Line 2360 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2422 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
NMV a; |
NMV a; |
P p; |
P p; |
EPOS oepos; |
EPOS oepos; |
int obpe,oadv,wmax,i,len,cbpe; |
int obpe,oadv,wmax,i,len,cbpe,ishomo; |
|
|
get_vars((Obj)f,&fv); pltovl(v,&vv); |
get_vars((Obj)f,&fv); pltovl(v,&vv); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
nocheck = 0; |
nocheck = 0; |
mindex = 0; |
mindex = 0; |
|
|
if ( Demand ) |
if ( Demand ) nd_demand = 1; |
nd_demand = 1; |
else nd_demand = 0; |
|
|
/* setup modulus */ |
/* setup modulus */ |
if ( trace < 0 ) { |
if ( trace < 0 ) { |
trace = -trace; |
trace = -trace; |
Line 2383 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2446 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
nd_init_ord(ord); |
nd_init_ord(ord); |
nd_setup_parameters(nvar,max); |
nd_setup_parameters(nvar,max); |
obpe = nd_bpe; oadv = nmv_adv; oepos = nd_epos; |
obpe = nd_bpe; oadv = nmv_adv; oepos = nd_epos; |
|
ishomo = 1; |
for ( in0 = 0, fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
for ( in0 = 0, fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
c = ptondv(CO,vv,(P)BDY(t)); |
c = ptondv(CO,vv,(P)BDY(t)); |
|
if ( ishomo ) |
|
ishomo = ishomo && ndv_ishomo(c); |
if ( c ) { |
if ( c ) { |
NEXTNODE(in0,in); BDY(in) = (pointer)c; |
NEXTNODE(in0,in); BDY(in) = (pointer)c; |
NEXTNODE(fd0,fd); BDY(fd) = (pointer)ndv_dup(0,c); |
NEXTNODE(fd0,fd); BDY(fd) = (pointer)ndv_dup(0,c); |
Line 2392 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2458 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
} |
} |
if ( in0 ) NEXT(in) = 0; |
if ( in0 ) NEXT(in) = 0; |
if ( fd0 ) NEXT(fd) = 0; |
if ( fd0 ) NEXT(fd) = 0; |
if ( homo ) { |
if ( !ishomo && homo ) { |
for ( t = in0, wmax = 0; t; t = NEXT(t) ) { |
for ( t = in0, wmax = 0; t; t = NEXT(t) ) { |
c = (NDV)BDY(t); len = LEN(c); |
c = (NDV)BDY(t); len = LEN(c); |
for ( a = BDY(c), i = 0; i < len; i++, NMV_ADV(a) ) |
for ( a = BDY(c), i = 0; i < len; i++, NMV_ADV(a) ) |
Line 2408 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2474 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
if ( Demand ) |
if ( Demand ) |
nd_demand = 1; |
nd_demand = 1; |
ndv_setup(m,1,fd0); |
ndv_setup(m,1,fd0); |
cand = nd_gb_trace(m); |
cand = nd_gb_trace(m,ishomo || homo); |
if ( !cand ) { |
if ( !cand ) { |
/* failure */ |
/* failure */ |
if ( trace > 1 ) { *rp = 0; return; } |
if ( trace > 1 ) { *rp = 0; return; } |
else m = get_lprime(++mindex); |
else m = get_lprime(++mindex); |
continue; |
continue; |
} |
} |
if ( homo ) { |
if ( !ishomo && homo ) { |
/* dehomogenization */ |
/* dehomogenization */ |
for ( t = cand; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); |
for ( t = cand; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord); |
nd_init_ord(ord); |
nd_init_ord(ord); |
Line 2424 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2490 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
nd_demand = 0; |
nd_demand = 0; |
cand = ndv_reducebase(cand); |
cand = ndv_reducebase(cand); |
cand = ndv_reduceall(0,cand); |
cand = ndv_reduceall(0,cand); |
|
cbpe = nd_bpe; |
if ( nocheck ) |
if ( nocheck ) |
break; |
break; |
cbpe = nd_bpe; |
|
if ( ndv_check_candidate(in0,obpe,oadv,oepos,cand) ) |
if ( ndv_check_candidate(in0,obpe,oadv,oepos,cand) ) |
/* success */ |
/* success */ |
break; |
break; |
Line 2437 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2503 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
/* try the next modulus */ |
/* try the next modulus */ |
m = get_lprime(++mindex); |
m = get_lprime(++mindex); |
/* reset the parameters */ |
/* reset the parameters */ |
if ( homo ) { |
if ( !ishomo && homo ) { |
nd_init_ord(&ord1); |
nd_init_ord(&ord1); |
nd_setup_parameters(nvar+1,wmax); |
nd_setup_parameters(nvar+1,wmax); |
} else { |
} else { |
Line 2828 int nd_get_exporigin(struct order_spec *ord) |
|
Line 2894 int nd_get_exporigin(struct order_spec *ord) |
|
} |
} |
|
|
void nd_setup_parameters(int nvar,int max) { |
void nd_setup_parameters(int nvar,int max) { |
int i,j,n,elen,ord_o,ord_l,l,s; |
int i,j,n,elen,ord_o,ord_l,l,s,wpd; |
struct order_pair *op; |
struct order_pair *op; |
int bpe; |
|
|
|
if ( !max ) bpe = nd_bpe; |
|
else if ( max < 2 ) bpe = 1; |
|
else if ( max < 4 ) bpe = 2; |
|
else if ( max < 8 ) bpe = 3; |
|
else if ( max < 16 ) bpe = 4; |
|
else if ( max < 32 ) bpe = 5; |
|
else if ( max < 64 ) bpe = 6; |
|
else if ( max < 256 ) bpe = 8; |
|
else if ( max < 1024 ) bpe = 10; |
|
else if ( max < 65536 ) bpe = 16; |
|
else bpe = 32; |
|
if ( bpe != nd_bpe || nvar != nd_nvar ) |
|
nd_free_private_storage(); |
|
nd_bpe = bpe; |
|
nd_nvar = nvar; |
nd_nvar = nvar; |
|
if ( max ) { |
|
/* XXX */ |
|
if ( do_weyl ) nd_bpe = 32; |
|
else if ( max < 2 ) nd_bpe = 1; |
|
else if ( max < 4 ) nd_bpe = 2; |
|
else if ( max < 8 ) nd_bpe = 3; |
|
else if ( max < 16 ) nd_bpe = 4; |
|
else if ( max < 32 ) nd_bpe = 5; |
|
else if ( max < 64 ) nd_bpe = 6; |
|
else if ( max < 256 ) nd_bpe = 8; |
|
else if ( max < 1024 ) nd_bpe = 10; |
|
else if ( max < 65536 ) nd_bpe = 16; |
|
else nd_bpe = 32; |
|
} |
nd_epw = (sizeof(UINT)*8)/nd_bpe; |
nd_epw = (sizeof(UINT)*8)/nd_bpe; |
elen = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0); |
elen = nd_nvar/nd_epw+(nd_nvar%nd_epw?1:0); |
|
|
nd_exporigin = nd_get_exporigin(nd_ord); |
nd_exporigin = nd_get_exporigin(nd_ord); |
nd_wpd = nd_exporigin+elen; |
wpd = nd_exporigin+elen; |
|
if ( wpd != nd_wpd ) { |
|
nd_free_private_storage(); |
|
nd_wpd = wpd; |
|
} |
if ( nd_bpe < 32 ) { |
if ( nd_bpe < 32 ) { |
nd_mask0 = (1<<nd_bpe)-1; |
nd_mask0 = (1<<nd_bpe)-1; |
} else { |
} else { |
Line 3820 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0 |
|
Line 3887 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0 |
|
NDV p; |
NDV p; |
unsigned char *ivc; |
unsigned char *ivc; |
unsigned short *ivs; |
unsigned short *ivs; |
UINT *v,*ivi; |
UINT *v,*ivi,*s0v; |
int i,j,len,prev,diff,cdiff; |
int i,j,len,prev,diff,cdiff; |
IndArray r; |
IndArray r; |
|
|
Line 3829 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0 |
|
Line 3896 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0 |
|
p = nd_ps[pair->index]; |
p = nd_ps[pair->index]; |
len = LEN(p); |
len = LEN(p); |
t = (UINT *)ALLOCA(nd_wpd*sizeof(UINT)); |
t = (UINT *)ALLOCA(nd_wpd*sizeof(UINT)); |
r = (IndArray)MALLOC(sizeof(struct oIndArray)); |
|
v = (unsigned int *)ALLOCA(len*sizeof(unsigned int)); |
v = (unsigned int *)ALLOCA(len*sizeof(unsigned int)); |
for ( i = j = 0, s = s0, mr = BDY(p); j < len; j++, NMV_ADV(mr) ) { |
for ( i = j = 0, s = s0, mr = BDY(p); j < len; j++, NMV_ADV(mr) ) { |
ndl_add(d,DL(mr),t); |
ndl_add(d,DL(mr),t); |
for ( ; !ndl_equal(t,s); s += nd_wpd, i++ ); |
for ( ; !ndl_equal(t,s); s += nd_wpd, i++ ); |
v[j] = i; |
v[j] = i; |
} |
} |
|
r = (IndArray)MALLOC(sizeof(struct oIndArray)); |
r->head = v[0]; |
r->head = v[0]; |
diff = 0; |
diff = 0; |
for ( i = 1; i < len; i++ ) { |
for ( i = 1; i < len; i++ ) { |
Line 4064 NODE nd_f4(int m) |
|
Line 4131 NODE nd_f4(int m) |
|
ND spol,red; |
ND spol,red; |
NDV nf,redv; |
NDV nf,redv; |
NM s0,s; |
NM s0,s; |
NODE rp0,sp0,srp0,nflist; |
NODE rp0,srp0,nflist; |
int nsp,nred,col,rank,len,k,j,a; |
int nsp,nred,col,rank,len,k,j,a; |
UINT c; |
UINT c; |
UINT **spmat; |
UINT **spmat; |
Line 4097 NODE nd_f4(int m) |
|
Line 4164 NODE nd_f4(int m) |
|
d = nd_reconstruct(m,0,d); |
d = nd_reconstruct(m,0,d); |
continue; |
continue; |
} |
} |
if ( !sp0 ) continue; |
|
col = nd_symbolic_preproc(bucket,&s0vect,&rp0); |
col = nd_symbolic_preproc(bucket,&s0vect,&rp0); |
if ( !col ) { |
if ( !col ) { |
for ( t = l; NEXT(t); t = NEXT(t) ); |
for ( t = l; NEXT(t); t = NEXT(t) ); |
Line 4139 NODE nd_f4_red(int m,ND_pairs sp0,UINT *s0vect,int col |
|
Line 4205 NODE nd_f4_red(int m,ND_pairs sp0,UINT *s0vect,int col |
|
int **spmat; |
int **spmat; |
UINT *svect,*v; |
UINT *svect,*v; |
int *colstat; |
int *colstat; |
struct oEGT eg0,eg1,eg_f4; |
struct oEGT eg0,eg1,eg2,eg_f4,eg_f4_1,eg_f4_2; |
NM_ind_pair *rvect; |
NM_ind_pair *rvect; |
int maxrs; |
int maxrs; |
int *spsugar; |
int *spsugar; |
Line 4181 NODE nd_f4_red(int m,ND_pairs sp0,UINT *s0vect,int col |
|
Line 4247 NODE nd_f4_red(int m,ND_pairs sp0,UINT *s0vect,int col |
|
} |
} |
nd_free(spol); |
nd_free(spol); |
} |
} |
|
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
|
fflush(asir_out); |
|
} |
/* free index arrays */ |
/* free index arrays */ |
for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c); |
for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c); |
|
|
Line 4198 NODE nd_f4_red(int m,ND_pairs sp0,UINT *s0vect,int col |
|
Line 4269 NODE nd_f4_red(int m,ND_pairs sp0,UINT *s0vect,int col |
|
GC_free(spmat[i]); |
GC_free(spmat[i]); |
} |
} |
for ( ; i < sprow; i++ ) GC_free(spmat[i]); |
for ( ; i < sprow; i++ ) GC_free(spmat[i]); |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
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 ) { |
if ( DP_Print ) { |
|
fprintf(asir_out,"elim2=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
nsp,nred,sprow,spcol,rank); |
nsp,nred,sprow,spcol,rank); |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |