===================================================================
RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/nd.c,v
retrieving revision 1.35
retrieving revision 1.40
diff -u -p -r1.35 -r1.40
--- OpenXM_contrib2/asir2000/engine/nd.c 2003/08/20 07:04:31 1.35
+++ OpenXM_contrib2/asir2000/engine/nd.c 2003/08/21 04:44:36 1.40
@@ -1,4 +1,4 @@
-/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.34 2003/08/20 06:06:07 noro Exp $ */
+/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.39 2003/08/21 03:13:01 noro Exp $ */
#include "ca.h"
#include "inline.h"
@@ -15,11 +15,14 @@
#define REDTAB_LEN 32003
+/* GeoBucket for polynomial addition */
+
typedef struct oPGeoBucket {
int m;
struct oND *body[32];
} *PGeoBucket;
+/* distributed polynomial; linked list rep. */
typedef struct oND {
struct oNM *body;
int nv;
@@ -27,6 +30,7 @@ typedef struct oND {
int sugar;
} *ND;
+/* distributed polynomial; array rep. */
typedef struct oNDV {
struct oNMV *body;
int nv;
@@ -34,6 +38,7 @@ typedef struct oNDV {
int sugar;
} *NDV;
+/* monomial; linked list rep. */
typedef struct oNM {
struct oNM *next;
union {
@@ -43,6 +48,7 @@ typedef struct oNM {
unsigned int dl[1];
} *NM;
+/* monomial; array rep. */
typedef struct oNMV {
union {
int m;
@@ -51,6 +57,7 @@ typedef struct oNMV {
unsigned int dl[1];
} *NMV;
+/* history of reducer */
typedef struct oRHist {
struct oRHist *next;
int index;
@@ -58,6 +65,7 @@ typedef struct oRHist {
unsigned int dl[1];
} *RHist;
+/* S-pair list */
typedef struct oND_pairs {
struct oND_pairs *next;
int i1,i2;
@@ -85,7 +93,6 @@ RHist *nd_psh;
int nd_psn,nd_pslen;
RHist *nd_red;
-int nd_red_len;
int nd_found,nd_create,nd_notfirst;
int nm_adv;
@@ -94,6 +101,7 @@ int nd_dcomp;
extern int Top,Reverse,dp_nelim;
+/* fundamental macros */
#define TD(d) (d[0])
#define HDL(d) ((d)->body->dl)
#define HTD(d) (TD(HDL(d)))
@@ -106,13 +114,13 @@ extern int Top,Reverse,dp_nelim;
#define LEN(a) ((a)->len)
#define LCM(a) ((a)->lcm)
+/* macros for term comparison */
#define TD_DL_COMPARE(d1,d2)\
(TD(d1)>TD(d2)?1:(TD(d1)
>((nd_epw-1)*nd_bpe))&nd_mask0;
for ( i = 1; i <= nd_wpd; i++ )
d[i] = ((d[i]<>((nd_epw-1)*nd_bpe))&nd_mask0):0);
+ |(i+1<=nd_wpd?((d[i+1]>>((nd_epw-1)*nd_bpe))&nd_mask0):0);
TD(d) -= h;
}
} else
@@ -445,10 +487,10 @@ void ndl_lcm(unsigned int *d1,unsigned *d2,unsigned in
}
break;
}
- TD(d) = ndl_td(d);
+ TD(d) = ndl_weight(d);
}
-int ndl_td(unsigned int *d)
+int ndl_weight(unsigned int *d)
{
unsigned int t,u;
int i,j;
@@ -505,12 +547,11 @@ INLINE void ndl_copy(unsigned int *d1,unsigned int *d2
}
}
-/* XXX : TD is not added */
-
INLINE void ndl_add(unsigned int *d1,unsigned int *d2,unsigned int *d)
{
int i;
+ TD(d) = TD(d1)+TD(d2);
switch ( nd_wpd ) {
case 1:
d[1] = d1[1]+d2[1];
@@ -755,6 +796,7 @@ INLINE int nd_find_reducer(ND g)
int d,k,i;
dg = HDL(g);
+#if 1
d = ndl_hash_value(HDL(g));
for ( r = nd_red[d], k = 0; r; r = NEXT(r), k++ ) {
if ( ndl_equal(dg,DL(r)) ) {
@@ -763,6 +805,7 @@ INLINE int nd_find_reducer(ND g)
return r->index;
}
}
+#endif
if ( Reverse )
for ( i = nd_psn-1; i >= 0; i-- ) {
r = nd_psh[i];
@@ -1250,7 +1293,7 @@ int nd_check_candidate(NODE input,NODE cand)
ND nf,d;
NODE t;
- nd_setup(0,cand);
+ nd_setup(0,0,cand);
n = length(cand);
/* membercheck : list is a subset of Id(cand) ? */
@@ -1459,7 +1502,7 @@ again:
} else if ( nf ) {
if ( checkonly ) return 0;
printf("+"); fflush(stdout);
- nh = nd_newps(m,nf);
+ nh = m?nd_newps(m,nf,0):nd_newps(m,0,nf);
d = update_pairs(d,g,nh);
g = update_base(g,nh);
FREENDP(l);
@@ -1513,9 +1556,9 @@ again:
nd_nf(0,h,!Top,&nfq);
if ( nfq ) {
printf("+"); fflush(stdout);
- nh = nd_newps_trace(m,nf,nfq);
+ nh = nd_newps(m,nf,nfq);
/* failure; m|HC(nfq) */
- if ( nf < 0 ) return 0;
+ if ( nh < 0 ) return 0;
d = update_pairs(d,g,nh);
g = update_base(g,nh);
} else {
@@ -1751,7 +1794,7 @@ int crit_2( int dp1, int dp2 )
return ndl_disjoint(DL(nd_psh[dp1]),DL(nd_psh[dp2]));
}
-static ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest )
+ND_pairs equivalent_pairs( ND_pairs d1, ND_pairs *prest )
{
ND_pairs w,p,r,s;
unsigned int *d;
@@ -1763,11 +1806,9 @@ static ND_pairs equivalent_pairs( ND_pairs d1, ND_pair
for ( r = 0; s; s = p ) {
p = NEXT(s);
if ( ndl_equal(d,LCM(s)) ) {
- NEXT(s) = w;
- w = s;
+ NEXT(s) = w; w = s;
} else {
- NEXT(s) = r;
- r = s;
+ NEXT(s) = r; r = s;
}
}
*prest = r;
@@ -1809,9 +1850,7 @@ ND_pairs nd_minp( ND_pairs d, ND_pairs *prest )
for ( ml = 0, l = m; p; p = NEXT(l = p) )
if ( (SG(p) < s)
|| ((SG(p) == s) && (DL_COMPARE(LCM(p),LCM(m)) < 0)) ) {
- ml = l;
- m = p;
- s = SG(m);
+ ml = l; m = p; s = SG(m);
}
if ( !ml ) *prest = NEXT(m);
else {
@@ -1822,7 +1861,7 @@ ND_pairs nd_minp( ND_pairs d, ND_pairs *prest )
return m;
}
-int nd_newps(int mod,ND a)
+int nd_newps(int mod,ND a,ND aq)
{
int len;
RHist r;
@@ -1836,95 +1875,30 @@ int nd_newps(int mod,ND a)
nd_bound = (unsigned int **)
REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *));
}
- nd_removecont(mod,a);
- nd_bound[nd_psn] = nd_compute_bound(a);
- NEWRHist(r); SG(r) = SG(a); ndl_copy(HDL(a),DL(r));
- nd_psh[nd_psn] = r;
- b = ndtondv(mod,a);
- len = LEN(b);
- if ( mod )
- nd_ps[nd_psn] = b;
- else
- nd_psq[nd_psn] = b;
- nd_free(a);
- return nd_psn++;
-}
-
-int nd_newps_trace(int mod,ND nf,ND nfq)
-{
- int len;
- RHist r;
- NDV b;
-
- if ( nd_psn == nd_pslen ) {
- nd_pslen *= 2;
- nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV));
- nd_psq = (NDV *)REALLOC((char *)nd_psq,nd_pslen*sizeof(NDV));
- nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist));
- nd_bound = (unsigned int **)
- REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *));
+ if ( a && aq ) {
+ /* trace lifting */
+ if ( !rem(NM(HCQ(aq)),mod) ) return -1;
}
- if ( !rem(NM(HCQ(nfq)),mod) ) return -1;
- nd_removecont(mod,nf);
- nd_ps[nd_psn] = ndtondv(mod,nf);
-
- nd_removecont(0,nfq);
- nd_psq[nd_psn] = ndtondv(0,nfq);
-
- nd_bound[nd_psn] = nd_compute_bound(nfq);
- NEWRHist(r); SG(r) = SG(nf); ndl_copy(HDL(nf),DL(r));
- nd_psh[nd_psn] = r;
- nd_free(nf); nd_free(nfq);
- return nd_psn++;
-}
-
-void nd_setup(int mod,NODE f)
-{
- int i,j,td,len,max;
- NODE s,s0,f0;
- unsigned int *d;
- RHist r;
- NDV a;
-
- nd_found = 0; nd_notfirst = 0; nd_create = 0;
-
- nd_psn = length(f); nd_pslen = 2*nd_psn;
- nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV));
- nd_psq = (NDV *)MALLOC(nd_pslen*sizeof(NDV));
- nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist));
- nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *));
- for ( max = 0, i = 0, s = f; i < nd_psn; i++, s = NEXT(s) ) {
- nd_bound[i] = d = dp_compute_bound((DP)BDY(s));
- for ( j = 0; j < nd_nvar; j++ )
- max = MAX(d[j],max);
+ NEWRHist(r); nd_psh[nd_psn] = r;
+ if ( aq ) {
+ nd_removecont(0,aq);
+ nd_psq[nd_psn] = ndtondv(0,aq);
+ nd_bound[nd_psn] = nd_compute_bound(aq);
+ SG(r) = SG(aq); ndl_copy(HDL(aq),DL(r));
}
- if ( !nd_red )
- nd_red = (RHist *)MALLOC(REDTAB_LEN*sizeof(RHist));
- bzero(nd_red,REDTAB_LEN*sizeof(RHist));
-
- if ( max < 2 ) nd_bpe = 2;
- else if ( max < 4 ) nd_bpe = 4;
- else if ( max < 64 ) nd_bpe = 6;
- else if ( max < 256 ) nd_bpe = 8;
- else if ( max < 65536 ) nd_bpe = 16;
- else nd_bpe = 32;
-
- nd_setup_parameters();
- nd_free_private_storage();
- len = 0;
- for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) {
- NEWRHist(r);
- a = dptondv(mod,(DP)BDY(f));
- ndv_removecont(mod,a);
- len = MAX(len,LEN(a));
- SG(r) = HTD(a); ndl_copy(HDL(a),DL(r));
- if ( mod ) nd_ps[i] = a;
- else nd_psq[i] = a;
- nd_psh[i] = r;
+ if ( a ) {
+ nd_removecont(mod,a);
+ nd_ps[nd_psn] = ndtondv(mod,a);
+ if ( !aq ) {
+ nd_bound[nd_psn] = nd_compute_bound(a);
+ SG(r) = SG(a); ndl_copy(HDL(a),DL(r));
+ }
}
+ nd_free(a); nd_free(aq);
+ return nd_psn++;
}
-void nd_setup_trace(int mod,NODE f)
+void nd_setup(int mod,int trace,NODE f)
{
int i,j,td,len,max;
NODE s,s0,f0;
@@ -1957,13 +1931,19 @@ void nd_setup_trace(int mod,NODE f)
nd_setup_parameters();
nd_free_private_storage();
- len = 0;
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) {
- a = dptondv(mod,(DP)BDY(f)); ndv_removecont(mod,a); nd_ps[i] = a;
- a = dptondv(0,(DP)BDY(f)); ndv_removecont(0,a); nd_psq[i] = a;
NEWRHist(r);
- len = MAX(len,LEN(a));
+ a = dptondv(mod,(DP)BDY(f)); ndv_removecont(mod,a);
SG(r) = HTD(a); ndl_copy(HDL(a),DL(r));
+
+ if ( trace ) {
+ nd_ps[i] = a;
+ a = dptondv(0,(DP)BDY(f)); ndv_removecont(0,a);
+ nd_psq[i] = a;
+ } else {
+ if ( mod ) nd_ps[i] = a;
+ else nd_psq[i] = a;
+ }
nd_psh[i] = r;
}
}
@@ -1985,7 +1965,7 @@ void nd_gr(LIST f,LIST v,int m,struct order_spec *ord,
NEXTNODE(fd0,fd); BDY(fd) = (pointer)b;
}
if ( fd0 ) NEXT(fd) = 0;
- nd_setup(m,fd0);
+ nd_setup(m,0,fd0);
x = nd_gb(m,0);
fprintf(asir_out,"found=%d,notfirst=%d,create=%d\n",
nd_found,nd_notfirst,nd_create);
@@ -2041,7 +2021,7 @@ void nd_gr_trace(LIST f,LIST v,int m,int homo,struct o
nd_init_ord(ord);
}
do {
- nd_setup_trace(m,fd0);
+ nd_setup(m,1,fd0);
cand = nd_gb_trace(m);
if ( !cand ) continue;
if ( homo ) {
@@ -2085,7 +2065,7 @@ void dltondl(int n,DL dl,unsigned int *r)
else
for ( i = 0; i < n; i++ )
r[i/nd_epw+1] |= d[i]<<((nd_epw-(i%nd_epw)-1)*nd_bpe);
- TD(r) = ndl_td(r);
+ TD(r) = ndl_weight(r);
}
DL ndltodl(int n,unsigned int *ndl)
@@ -2472,10 +2452,11 @@ void nd_setup_parameters() {
ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
{
- int i,obpe,oadv;
+ int i,obpe,oadv,h;
NM prev_nm_free_list;
RHist mr0,mr;
RHist r;
+ RHist *old_red;
ND_pairs s0,s,t,prev_ndp_free_list;
obpe = nd_bpe;
@@ -2502,21 +2483,29 @@ ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
s->i1 = t->i1;
s->i2 = t->i2;
SG(s) = SG(t);
- ndl_dup(obpe,LCM(t),LCM(s));
+ ndl_reconstruct(obpe,LCM(t),LCM(s));
}
+
+ old_red = (RHist *)ALLOCA(REDTAB_LEN*sizeof(RHist));
for ( i = 0; i < REDTAB_LEN; i++ ) {
- for ( mr0 = 0, r = nd_red[i]; r; r = NEXT(r) ) {
- NEXTRHist(mr0,mr);
+ old_red[i] = nd_red[i];
+ nd_red[i] = 0;
+ }
+ for ( i = 0; i < REDTAB_LEN; i++ )
+ for ( r = old_red[i]; r; r = NEXT(r) ) {
+ NEWRHist(mr);
mr->index = r->index;
SG(mr) = SG(r);
- ndl_dup(obpe,DL(r),DL(mr));
+ ndl_reconstruct(obpe,DL(r),DL(mr));
+ h = ndl_hash_value(DL(mr));
+ NEXT(mr) = nd_red[h];
+ nd_red[h] = mr;
}
- if ( mr0 ) NEXT(mr) = 0;
- nd_red[i] = mr0;
- }
+ for ( i = 0; i < REDTAB_LEN; i++ ) old_red[i] = 0;
+ old_red = 0;
for ( i = 0; i < nd_psn; i++ ) {
NEWRHist(r); SG(r) = SG(nd_psh[i]);
- ndl_dup(obpe,DL(nd_psh[i]),DL(r));
+ ndl_reconstruct(obpe,DL(nd_psh[i]),DL(r));
nd_psh[i] = r;
}
if ( s0 ) NEXT(s) = 0;
@@ -2528,10 +2517,11 @@ ND_pairs nd_reconstruct(int mod,int trace,ND_pairs d)
void nd_reconstruct_direct(int mod,NDV *ps,int len)
{
- int i,obpe,oadv;
+ int i,obpe,oadv,h;
NM prev_nm_free_list;
RHist mr0,mr;
RHist r;
+ RHist *old_red;
ND_pairs s0,s,t,prev_ndp_free_list;
obpe = nd_bpe;
@@ -2549,22 +2539,29 @@ void nd_reconstruct_direct(int mod,NDV *ps,int len)
_nm_free_list = 0; _ndp_free_list = 0;
if ( mod != 0 )
for ( i = len-1; i >= 0; i-- ) ndv_realloc(ps[i],obpe,oadv);
+ old_red = (RHist *)ALLOCA(REDTAB_LEN*sizeof(RHist));
for ( i = 0; i < REDTAB_LEN; i++ ) {
- for ( mr0 = 0, r = nd_red[i]; r; r = NEXT(r) ) {
- NEXTRHist(mr0,mr);
+ old_red[i] = nd_red[i];
+ nd_red[i] = 0;
+ }
+ for ( i = 0; i < REDTAB_LEN; i++ )
+ for ( r = old_red[i]; r; r = NEXT(r) ) {
+ NEWRHist(mr);
mr->index = r->index;
SG(mr) = SG(r);
- ndl_dup(obpe,DL(r),DL(mr));
+ ndl_reconstruct(obpe,DL(r),DL(mr));
+ h = ndl_hash_value(DL(mr));
+ NEXT(mr) = nd_red[h];
+ nd_red[h] = mr;
}
- if ( mr0 ) NEXT(mr) = 0;
- nd_red[i] = mr0;
- }
+ for ( i = 0; i < REDTAB_LEN; i++ ) old_red[i] = 0;
+ old_red = 0;
prev_nm_free_list = 0;
prev_ndp_free_list = 0;
GC_gcollect();
}
-void ndl_dup(int obpe,unsigned int *d,unsigned int *r)
+void ndl_reconstruct(int obpe,unsigned int *d,unsigned int *r)
{
int n,i,ei,oepw,cepw,cbpe;
@@ -2597,7 +2594,7 @@ void nd_realloc(ND p,int obpe)
for ( mr0 = 0; m; m = NEXT(m) ) {
NEXTNM(mr0,mr);
CM(mr) = CM(m);
- ndl_dup(obpe,DL(m),DL(mr));
+ ndl_reconstruct(obpe,DL(m),DL(mr));
}
NEXT(mr) = 0;
BDY(p) = mr0;
@@ -2706,7 +2703,6 @@ ND ndv_mul_nm(int mod,NDV p,NM m0)
c1 = CM(m);
DMAR(c1,c,0,mod,c2);
CM(mr) = c2;
- TD(DL(mr)) = TD(DL(m))+td;
ndl_add(DL(m),d,DL(mr));
}
} else {
@@ -2714,7 +2710,6 @@ ND ndv_mul_nm(int mod,NDV p,NM m0)
for ( i = 0; i < len; i++, NMV_ADV(m) ) {
NEXTNM(mr0,mr);
mulq(CQ(m),q,&CQ(mr));
- TD(DL(mr)) = TD(DL(m))+td;
ndl_add(DL(m),d,DL(mr));
}
}
@@ -2742,7 +2737,7 @@ void ndv_realloc(NDV p,int obpe,int oadv)
for ( i = 0; i < len; i++, NMV_OPREV(m), NMV_PREV(mr) ) {
CQ(t) = CQ(m);
for ( k = 0; k < nd_wpd; k++ ) DL(t)[k] = 0;
- ndl_dup(obpe,DL(m),DL(t));
+ ndl_reconstruct(obpe,DL(m),DL(t));
CQ(mr) = CQ(t);
ndl_copy(DL(t),DL(mr));
}
|