version 1.11, 2018/10/23 04:53:37 |
version 1.13, 2019/01/14 09:17:34 |
|
|
/* $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.12 2018/11/12 04:25:13 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
int Nnd_add,Nf4_red; |
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 diag_period = 6; |
int weight_check = 1; |
int weight_check = 1; |
Line 1130 INLINE int ndl_hash_value(UINT *d) |
|
Line 1130 INLINE int ndl_hash_value(UINT *d) |
|
|
|
r = 0; |
r = 0; |
for ( i = 0; i < nd_wpd; i++ ) |
for ( i = 0; i < nd_wpd; i++ ) |
r = (r*10007+d[i]); |
r = (r*1511+d[i]); |
r %= REDTAB_LEN; |
r %= REDTAB_LEN; |
return r; |
return r; |
} |
} |
Line 4235 void mpz_removecont_array(mpz_t *c,int n) |
|
Line 4235 void mpz_removecont_array(mpz_t *c,int n) |
|
{ |
{ |
mpz_t d0,a,u,u1,gcd; |
mpz_t d0,a,u,u1,gcd; |
int i,j; |
int i,j; |
mpz_t *q,*r; |
static mpz_t *q,*r; |
|
static int c_len = 0; |
|
|
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
if ( mpz_sgn(c[i]) ) break; |
if ( mpz_sgn(c[i]) ) break; |
if ( i == n ) return; |
if ( i == n ) return; |
gcdv_mpz_estimate(d0,c,n); |
gcdv_mpz_estimate(d0,c,n); |
q = (mpz_t *)MALLOC(n*sizeof(mpz_t)); |
if ( n > c_len ) { |
r = (mpz_t *)MALLOC(n*sizeof(mpz_t)); |
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++ ) { |
for ( i = 0; i < n; i++ ) { |
mpz_init(q[i]); mpz_init(r[i]); |
mpz_init(q[i]); mpz_init(r[i]); |
mpz_fdiv_qr(q[i],r[i],c[i],d0); |
mpz_fdiv_qr(q[i],r[i],c[i],d0); |
Line 6056 int ndv_reduce_vect_q(Z *svect,int trace,int col,IndAr |
|
Line 6060 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 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; |
int i,j,k,len,pos,prev; |
mpz_t *svect; |
|
mpz_t cs,cr,gcd; |
mpz_t cs,cr,gcd; |
IndArray ivect; |
IndArray ivect; |
unsigned char *ivc; |
unsigned char *ivc; |
Line 6068 int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndA |
|
Line 6071 int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndA |
|
int maxrs; |
int maxrs; |
double hmag; |
double hmag; |
int l; |
int l; |
|
static mpz_t *svect; |
|
static int svect_len=0; |
|
|
maxrs = 0; |
maxrs = 0; |
for ( i = 0; i < col && !svect0[i]; i++ ); |
for ( i = 0; i < col && !svect0[i]; i++ ); |
if ( i == col ) return maxrs; |
if ( i == col ) return maxrs; |
hmag = p_mag((P)svect0[i])*nd_scale; |
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++ ) { |
for ( i = 0; i < col; i++ ) { |
mpz_init(svect[i]); |
mpz_init(svect[i]); |
if ( svect0[i] ) |
if ( svect0[i] ) |
Line 6679 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6687 NODE nd_f4(int m,int checkonly,int **indp) |
|
PGeoBucket bucket; |
PGeoBucket bucket; |
struct oEGT eg0,eg1,eg_f4; |
struct oEGT eg0,eg1,eg_f4; |
Z i1,i2,sugarq; |
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 |
#if 0 |
ndv_alloc = 0; |
ndv_alloc = 0; |
#endif |
#endif |
Line 6724 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6734 NODE nd_f4(int m,int checkonly,int **indp) |
|
d = nd_reconstruct(0,d); |
d = nd_reconstruct(0,d); |
continue; |
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 ) |
if ( DP_Print ) |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
sugar,eg_f4.exectime); |
sugar,eg_f4.exectime); |
Line 6773 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6783 NODE nd_f4(int m,int checkonly,int **indp) |
|
#if 0 |
#if 0 |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
#endif |
#endif |
if ( DP_Print ) |
if ( DP_Print ) { |
fprintf(asir_out,"number of red=%d\n",Nf4_red); |
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); |
conv_ilist(nd_demand,0,g,indp); |
return g; |
return g; |
} |
} |
Line 7083 NODE nd_f4_red(int m,ND_pairs sp0,int trace,UINT *s0ve |
|
Line 7096 NODE nd_f4_red(int m,ND_pairs sp0,int trace,UINT *s0ve |
|
rhead[imat[i]->head] = 1; |
rhead[imat[i]->head] = 1; |
start = imat[i]->head; |
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 ) { |
if ( DP_Print ) { |
fprintf(asir_out,"conv=%.3fsec,",eg_conv.exectime); |
fprintf(asir_out,"conv=%.3fsec,",eg_conv.exectime); |
fflush(asir_out); |
fflush(asir_out); |
Line 9088 int ndv_reduce_vect64(int m,mp_limb_t *svect,mp_limb_t |
|
Line 9101 int ndv_reduce_vect64(int m,mp_limb_t *svect,mp_limb_t |
|
ivc = ivect->index.c; |
ivc = ivect->index.c; |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
pos = prev+ivc[j]; c1 = CM(mr); prev = pos; |
pos = prev+ivc[j]; c1 = CM(mr); prev = pos; |
if ( c1 ) { |
c2 = svect[pos]+c1*c; |
c2 = svect[pos]+c1*c; |
if ( c2 < svect[pos] ) cvect[pos]++; |
if ( c2 < svect[pos] ) cvect[pos]++; |
svect[pos] = c2; |
svect[pos] = c2; |
|
} |
|
} |
} |
break; |
break; |
case 2: |
case 2: |
ivs = ivect->index.s; |
ivs = ivect->index.s; |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
pos = prev+ivs[j]; c1 = CM(mr); prev = pos; |
pos = prev+ivs[j]; c1 = CM(mr); prev = pos; |
if ( c1 ) { |
c2 = svect[pos]+c1*c; |
c2 = svect[pos]+c1*c; |
if ( c2 < svect[pos] ) cvect[pos]++; |
if ( c2 < svect[pos] ) cvect[pos]++; |
svect[pos] = c2; |
svect[pos] = c2; |
|
} |
|
} |
} |
break; |
break; |
case 4: |
case 4: |
ivi = ivect->index.i; |
ivi = ivect->index.i; |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
pos = prev+ivi[j]; c1 = CM(mr); prev = pos; |
pos = prev+ivi[j]; c1 = CM(mr); prev = pos; |
if ( c1 ) { |
c2 = svect[pos]+c1*c; |
c2 = svect[pos]+c1*c; |
if ( c2 < svect[pos] ) cvect[pos]++; |
if ( c2 < svect[pos] ) cvect[pos]++; |
svect[pos] = c2; |
svect[pos] = c2; |
|
} |
|
} |
} |
break; |
break; |
} |
} |
Line 9170 NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U |
|
Line 9177 NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U |
|
} |
} |
nd_free(spol); |
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 ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime); |
fflush(asir_out); |
fflush(asir_out); |
Line 9191 NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U |
|
Line 9198 NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U |
|
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
|
|
for ( ; i < sprow; i++ ) GCFREE(spmat[i]); |
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); |
init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime); |
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime); |