version 1.239, 2017/09/14 01:34:53 |
version 1.244, 2018/03/05 06:43:09 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.238 2017/08/31 02:36:21 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.243 2018/03/05 01:56:17 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
Line 65 static int *nd_gbblock; |
|
Line 65 static int *nd_gbblock; |
|
static NODE nd_nzlist,nd_check_splist; |
static NODE nd_nzlist,nd_check_splist; |
static int nd_splist; |
static int nd_splist; |
static int *nd_sugarweight; |
static int *nd_sugarweight; |
static int nd_f4red,nd_rank0; |
static int nd_f4red,nd_rank0,nd_last_nonzero; |
|
|
NumberField get_numberfield(); |
NumberField get_numberfield(); |
UINT *nd_det_compute_bound(NDV **dm,int n,int j); |
UINT *nd_det_compute_bound(NDV **dm,int n,int j); |
Line 100 void nd_mul_c_lf(ND p,GZ mul); |
|
Line 100 void nd_mul_c_lf(ND p,GZ mul); |
|
void ndv_mul_c_lf(NDV p,GZ mul); |
void ndv_mul_c_lf(NDV p,GZ mul); |
NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz); |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz); |
NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz); |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz); |
NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int trace,UINT *s0vect,int col, |
NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int trace,UINT *s0vect,int col, |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred); |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred); |
Line 3228 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
Line 3228 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
NODE tr,tl1,tl2,tl3,tl4,nzlist; |
NODE tr,tl1,tl2,tl3,tl4,nzlist; |
LIST l1,l2,l3,l4,l5; |
LIST l1,l2,l3,l4,l5; |
int j; |
int j; |
Q jq,bpe; |
Q jq,bpe,last_nonzero; |
int *perm; |
int *perm; |
EPOS oepos; |
EPOS oepos; |
int obpe,oadv,ompos,cbpe; |
int obpe,oadv,ompos,cbpe; |
Line 3315 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
Line 3315 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
} |
} |
homogenize_order(ord,nvar,&ord1); |
homogenize_order(ord,nvar,&ord1); |
nd_init_ord(ord1); |
nd_init_ord(ord1); |
nd_setup_parameters(nvar+1,wmax); |
nd_setup_parameters(nvar+1,nd_nzlist?0:wmax); |
for ( t = fd0; t; t = NEXT(t) ) |
for ( t = fd0; t; t = NEXT(t) ) |
ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos); |
ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos); |
} |
} |
|
|
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
if ( f4 ) { |
if ( f4 ) { |
STOQ(16,bpe); |
STOQ(16,bpe); |
tr = mknode(4,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe); MKLIST(*rp,tr); |
STOQ(nd_last_nonzero,last_nonzero); |
|
tr = mknode(5,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe,last_nonzero); MKLIST(*rp,tr); |
|
|
} else { |
} else { |
tl1 = reverse_node(tl1); tl2 = reverse_node(tl2); |
tl1 = reverse_node(tl1); tl2 = reverse_node(tl2); |
tl3 = reverse_node(tl3); |
tl3 = reverse_node(tl3); |
Line 3840 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
Line 3842 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); |
get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"check=%fsec\n",eg_check.exectime+eg_check.gctime); |
fprintf(asir_out,"check=%.3fsec,",eg_check.exectime+eg_check.gctime); |
/* dp->p */ |
/* dp->p */ |
nd_bpe = cbpe; |
nd_bpe = cbpe; |
nd_setup_parameters(nd_nvar,0); |
nd_setup_parameters(nd_nvar,0); |
Line 5822 int nd_to_vect(int mod,UINT *s0,int n,ND d,UINT *r) |
|
Line 5824 int nd_to_vect(int mod,UINT *s0,int n,ND d,UINT *r) |
|
return i; |
return i; |
} |
} |
|
|
#if defined(__GNUC__) |
#if defined(__GNUC__) && SIZEOF_LONG==8 |
int nd_to_vect128(int mod,UINT *s0,int n,ND d,U128 *r) |
|
|
#define MOD128(a,c,m) ((a)=(((c)!=0||((a)>=(m)))?(((((U128)(c))<<64)+(a))%(m)):(a))) |
|
|
|
int nd_to_vect64(int mod,UINT *s0,int n,ND d,U64 *r) |
{ |
{ |
NM m; |
NM m; |
UINT *t,*s; |
UINT *t,*s; |
Line 5833 int nd_to_vect128(int mod,UINT *s0,int n,ND d,U128 *r) |
|
Line 5838 int nd_to_vect128(int mod,UINT *s0,int n,ND d,U128 *r) |
|
for ( i = 0, s = s0, m = BDY(d); m; m = NEXT(m) ) { |
for ( i = 0, s = s0, m = BDY(d); m; m = NEXT(m) ) { |
t = DL(m); |
t = DL(m); |
for ( ; !ndl_equal(t,s); s += nd_wpd, i++ ); |
for ( ; !ndl_equal(t,s); s += nd_wpd, i++ ); |
r[i] = (U128)CM(m); |
r[i] = (U64)CM(m); |
} |
} |
for ( i = 0; !r[i]; i++ ); |
for ( i = 0; !r[i]; i++ ); |
return i; |
return i; |
Line 6234 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
Line 6239 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
return maxrs; |
return maxrs; |
} |
} |
|
|
#if defined(__GNUC__) |
#if defined(__GNUC__) && SIZEOF_LONG==8 |
int ndv_reduce_vect128(int m,U128 *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
|
|
int ndv_reduce_vect64(int m,U64 *svect,U64 *cvect,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
{ |
{ |
int i,j,k,len,pos,prev; |
int i,j,k,len,pos,prev; |
U64 c,c1; |
U64 a,c,c1,c2; |
U128 a; |
|
IndArray ivect; |
IndArray ivect; |
unsigned char *ivc; |
unsigned char *ivc; |
unsigned short *ivs; |
unsigned short *ivs; |
Line 6249 int ndv_reduce_vect128(int m,U128 *svect,int col,IndAr |
|
Line 6254 int ndv_reduce_vect128(int m,U128 *svect,int col,IndAr |
|
NODE rp; |
NODE rp; |
int maxrs; |
int maxrs; |
|
|
|
for ( i = 0; i < col; i++ ) cvect[i] = 0; |
maxrs = 0; |
maxrs = 0; |
for ( i = 0; i < nred; i++ ) { |
for ( i = 0; i < nred; i++ ) { |
ivect = imat[i]; |
ivect = imat[i]; |
k = ivect->head; svect[k] %= m; |
k = ivect->head; |
|
a = svect[k]; c = cvect[k]; |
|
MOD128(a,c,m); |
|
svect[k] = a; cvect[k] = 0; |
if ( c = svect[k] ) { |
if ( c = svect[k] ) { |
maxrs = MAX(maxrs,rp0[i]->sugar); |
maxrs = MAX(maxrs,rp0[i]->sugar); |
c = m-c; redv = nd_ps[rp0[i]->index]; |
c = m-c; redv = nd_ps[rp0[i]->index]; |
Line 6263 int ndv_reduce_vect128(int m,U128 *svect,int col,IndAr |
|
Line 6272 int ndv_reduce_vect128(int m,U128 *svect,int col,IndAr |
|
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 ) svect[pos] += c1*c; |
if ( c1 ) { |
|
c2 = svect[pos]+c1*c; |
|
if ( c2 < svect[pos] ) cvect[pos]++; |
|
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 ) svect[pos] += c1*c; |
if ( c1 ) { |
|
c2 = svect[pos]+c1*c; |
|
if ( c2 < svect[pos] ) cvect[pos]++; |
|
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 ) svect[pos] += c1*c; |
if ( c1 ) { |
|
c2 = svect[pos]+c1*c; |
|
if ( c2 < svect[pos] ) cvect[pos]++; |
|
svect[pos] = c2; |
|
} |
} |
} |
break; |
break; |
} |
} |
} |
} |
} |
} |
for ( i = 0; i < col; i++ ) svect[i] %= m; |
for ( i = 0; i < col; i++ ) { |
|
a = svect[i]; c = cvect[i]; MOD128(a,c,m); svect[i] = a; |
|
} |
return maxrs; |
return maxrs; |
} |
} |
#endif |
#endif |
Line 6545 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
Line 6568 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
} |
} |
} |
} |
|
|
#if defined(__GNUC__) |
#if defined(__GNUC__) && SIZEOF_LONG==8 |
NDV vect128o_ndv(U128 *vect,int spcol,int col,int *rhead,UINT *s0vect) |
NDV vect64_to_ndv(U64 *vect,int spcol,int col,int *rhead,UINT *s0vect) |
{ |
{ |
int j,k,len; |
int j,k,len; |
UINT *p; |
UINT *p; |
Line 6781 int nd_symbolic_preproc(PGeoBucket bucket,int trace,UI |
|
Line 6804 int nd_symbolic_preproc(PGeoBucket bucket,int trace,UI |
|
return col; |
return col; |
} |
} |
|
|
|
void print_ndp(ND_pairs l) |
|
{ |
|
ND_pairs t; |
|
|
|
for ( t = l; t; t = NEXT(t) ) |
|
printf("[%d,%d] ",t->i1,t->i2); |
|
printf("\n"); |
|
} |
|
|
NODE nd_f4(int m,int checkonly,int **indp) |
NODE nd_f4(int m,int checkonly,int **indp) |
{ |
{ |
int i,nh,stat,index,f4red; |
int i,nh,stat,index,f4red; |
NODE r,g,tn0,tn,node; |
NODE r,g,tn0,tn,node; |
ND_pairs d,l,t,ll0,ll; |
ND_pairs d,l,t,ll0,ll,lh; |
LIST l0,l1; |
LIST l0,l1; |
ND spol,red; |
ND spol,red; |
NDV nf,redv; |
NDV nf,redv; |
Line 6799 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6831 NODE nd_f4(int m,int checkonly,int **indp) |
|
IndArray *imat; |
IndArray *imat; |
int *rhead; |
int *rhead; |
int spcol,sprow; |
int spcol,sprow; |
int sugar; |
int sugar,sugarh; |
PGeoBucket bucket; |
PGeoBucket bucket; |
struct oEGT eg0,eg1,eg_f4; |
struct oEGT eg0,eg1,eg_f4; |
Q i1,i2,sugarq; |
Q i1,i2,sugarq; |
Line 6808 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6840 NODE nd_f4(int m,int checkonly,int **indp) |
|
#endif |
#endif |
g = 0; d = 0; |
g = 0; d = 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
if ( !nd_nzlist ) d = update_pairs(d,g,i,0); |
d = update_pairs(d,g,i,0); |
g = update_base(g,i); |
g = update_base(g,i); |
} |
} |
nzlist = 0; |
nzlist = 0; |
nzlist_t = nd_nzlist; |
nzlist_t = nd_nzlist; |
f4red = 0; |
f4red = 1; |
while ( d || nzlist_t ) { |
nd_last_nonzero = 0; |
|
while ( d ) { |
get_eg(&eg0); |
get_eg(&eg0); |
if ( nd_nzlist ) { |
l = nd_minsugarp(d,&d); |
|
sugar = nd_sugarweight?l->sugar2:SG(l); |
|
if ( MaxDeg > 0 && sugar > MaxDeg ) break; |
|
if ( nzlist_t ) { |
node = BDY((LIST)BDY(nzlist_t)); |
node = BDY((LIST)BDY(nzlist_t)); |
sugar = (int)ARG0(node); |
sugarh = QTOS((Q)ARG0(node)); |
tn = BDY((LIST)ARG1(node)); |
tn = BDY((LIST)ARG1(node)); |
if ( !tn ) { |
if ( !tn ) { |
nzlist_t = NEXT(nzlist_t); |
nzlist_t = NEXT(nzlist_t); |
continue; |
continue; |
} |
} |
/* tn = [[i1,i2],...] */ |
/* tn = [[i1,i2],...] */ |
l = nd_ipairtospair(tn); |
lh = nd_ipairtospair(tn); |
} else { |
|
l = nd_minsugarp(d,&d); |
|
sugar = nd_sugarweight?l->sugar2:SG(l); |
|
if ( MaxDeg > 0 && sugar > MaxDeg ) break; |
|
} |
} |
bucket = create_pbucket(); |
bucket = create_pbucket(); |
stat = nd_sp_f4(m,0,l,bucket); |
stat = nd_sp_f4(m,0,l,bucket); |
if ( !stat ) { |
if ( !stat ) { |
if ( !nd_nzlist ) { |
for ( t = l; NEXT(t); t = NEXT(t) ); |
for ( t = l; NEXT(t); t = NEXT(t) ); |
NEXT(t) = d; d = l; |
NEXT(t) = d; d = l; |
d = nd_reconstruct(0,d); |
d = nd_reconstruct(0,d); |
|
} |
|
continue; |
continue; |
} |
} |
if ( bucket->m < 0 ) continue; |
if ( bucket->m < 0 ) continue; |
Line 6851 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6881 NODE nd_f4(int m,int checkonly,int **indp) |
|
} |
} |
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); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"sugar=%d,symb=%fsec,", |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
sugar,eg_f4.exectime+eg_f4.gctime); |
sugar,eg_f4.exectime+eg_f4.gctime); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,nd_gentrace?&ll:0); |
nflist = nd_f4_red(m,nd_nzlist?lh:l,0,s0vect,col,rp0,nd_gentrace?&ll:0); |
if ( checkonly && nflist ) return 0; |
if ( checkonly && nflist ) return 0; |
/* adding new bases */ |
/* adding new bases */ |
|
if ( nflist ) nd_last_nonzero = f4red; |
for ( r = nflist; r; r = NEXT(r) ) { |
for ( r = nflist; r; r = NEXT(r) ) { |
nf = (NDV)BDY(r); |
nf = (NDV)BDY(r); |
ndv_removecont(m,nf); |
ndv_removecont(m,nf); |
Line 6868 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6899 NODE nd_f4(int m,int checkonly,int **indp) |
|
nf = ndtondv(m,nf1); |
nf = ndtondv(m,nf1); |
} |
} |
nh = ndv_newps(m,nf,0,1); |
nh = ndv_newps(m,nf,0,1); |
if ( !nd_nzlist ) d = update_pairs(d,g,nh,0); |
d = update_pairs(d,g,nh,0); |
g = update_base(g,nh); |
g = update_base(g,nh); |
} |
} |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"f4red=%d,gblen=%d,",f4red,length(g)); fflush(asir_out); |
fprintf(asir_out,"f4red=%d,gblen=%d\n",f4red,length(g)); fflush(asir_out); |
} |
} |
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
for ( t = ll, tn0 = 0; t; t = NEXT(t) ) { |
for ( t = ll, tn0 = 0; t; t = NEXT(t) ) { |
Line 6887 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6918 NODE nd_f4(int m,int checkonly,int **indp) |
|
} |
} |
if ( nd_nzlist ) nzlist_t = NEXT(nzlist_t); |
if ( nd_nzlist ) nzlist_t = NEXT(nzlist_t); |
f4red++; |
f4red++; |
if ( nd_f4red && f4red >= nd_f4red ) break; |
if ( nd_f4red && f4red > nd_f4red ) break; |
if ( nd_rank0 && !nflist ) break; |
if ( nd_rank0 && !nflist ) break; |
} |
} |
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
Line 6950 NODE nd_f4_trace(int m,int **indp) |
|
Line 6981 NODE nd_f4_trace(int m,int **indp) |
|
} |
} |
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); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"sugar=%d,symb=%fsec,", |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
sugar,eg_f4.exectime+eg_f4.gctime); |
sugar,eg_f4.exectime+eg_f4.gctime); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
if ( !l0 ) continue; |
if ( !l0 ) continue; |
Line 7164 init_eg(&eg_search); |
|
Line 7195 init_eg(&eg_search); |
|
get_eg(&eg2); |
get_eg(&eg2); |
init_eg(&eg_elim2); add_eg(&eg_elim2,&eg1,&eg2); |
init_eg(&eg_elim2); add_eg(&eg_elim2,&eg1,&eg2); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,elim2=%fsec\n", |
fprintf(asir_out,"elim1=%.3fsec,elim2=%.3fsec,", |
eg_elim1.exectime+eg_elim1.gctime,eg_elim2.exectime+eg_elim2.gctime); |
eg_elim1.exectime+eg_elim1.gctime,eg_elim2.exectime+eg_elim2.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
Line 7195 init_eg(&eg_search); |
|
Line 7226 init_eg(&eg_search); |
|
|
|
/* construction of index arrays */ |
/* construction of index arrays */ |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(stderr,"%dx%d,",nsp+nred,col); |
fprintf(asir_out,"%dx%d,",nsp+nred,col); |
} |
} |
rvect = (NM_ind_pair *)MALLOC(nred*sizeof(NM_ind_pair)); |
rvect = (NM_ind_pair *)MALLOC(nred*sizeof(NM_ind_pair)); |
s0hash = (int *)MALLOC(col*sizeof(int)); |
s0hash = (int *)MALLOC(col*sizeof(int)); |
Line 7206 init_eg(&eg_search); |
|
Line 7237 init_eg(&eg_search); |
|
imat[i] = nm_ind_pair_to_vect_compress(trace,s0vect,col,s0hash,rvect[i]); |
imat[i] = nm_ind_pair_to_vect_compress(trace,s0vect,col,s0hash,rvect[i]); |
rhead[imat[i]->head] = 1; |
rhead[imat[i]->head] = 1; |
} |
} |
#if defined(__GNUC__) |
|
if ( m >= (1<<15) ) |
|
r0 = nd_f4_red_mod128_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
|
else |
|
#endif |
|
if ( m > 0 ) |
if ( m > 0 ) |
|
#if defined(__GNUC__) && SIZEOF_LONG==8 |
|
r0 = nd_f4_red_mod64_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
|
#else |
r0 = nd_f4_red_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
r0 = nd_f4_red_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
|
#endif |
else if ( m == -1 ) |
else if ( m == -1 ) |
r0 = nd_f4_red_sf_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
r0 = nd_f4_red_sf_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
else if ( m == -2 ) |
else if ( m == -2 ) |
Line 7223 init_eg(&eg_search); |
|
Line 7253 init_eg(&eg_search); |
|
#else |
#else |
r0 = nd_f4_red_gz_main(sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
r0 = nd_f4_red_gz_main(sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
#endif |
#endif |
|
#if 0 |
if ( DP_Print ) print_eg("search",&eg_search); |
if ( DP_Print ) print_eg("search",&eg_search); |
|
#endif |
return r0; |
return r0; |
} |
} |
|
|
Line 7274 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 7306 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
} |
} |
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); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7299 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 7331 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
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); |
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=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",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,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
if ( nz ) { |
if ( nz ) { |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
Line 7315 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 7347 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
return r0; |
return r0; |
} |
} |
|
|
#if defined(__GNUC__) |
#if defined(__GNUC__) && SIZEOF_LONG==8 |
/* for Fp, 2^15=<p<2^29 */ |
/* for Fp, 2^15=<p<2^29 */ |
|
|
NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz) |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz) |
{ |
{ |
int spcol,sprow,a; |
int spcol,sprow,a; |
Line 7326 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
Line 7358 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
NODE r0,r; |
NODE r0,r; |
ND_pairs sp; |
ND_pairs sp; |
ND spol; |
ND spol; |
U128 **spmat; |
U64 **spmat; |
U128 *svect,*v; |
U64 *svect,*cvect; |
|
U64 *v; |
int *colstat; |
int *colstat; |
struct oEGT eg0,eg1,eg2,eg_f4,eg_f4_1,eg_f4_2; |
struct oEGT eg0,eg1,eg2,eg_f4,eg_f4_1,eg_f4_2; |
int maxrs; |
int maxrs; |
int *spsugar; |
int *spsugar; |
ND_pairs *spactive; |
ND_pairs *spactive; |
int **spmat32; |
|
|
|
spcol = col-nred; |
spcol = col-nred; |
get_eg(&eg0); |
get_eg(&eg0); |
/* elimination (1st step) */ |
/* elimination (1st step) */ |
spmat = (U128 **)MALLOC(nsp*sizeof(U128 *)); |
spmat = (U64 **)MALLOC(nsp*sizeof(U64 *)); |
svect = (U128 *)MALLOC(col*sizeof(U128)); |
svect = (U64 *)MALLOC(col*sizeof(U64)); |
|
cvect = (U64 *)MALLOC(col*sizeof(U64)); |
spsugar = (int *)MALLOC(nsp*sizeof(int)); |
spsugar = (int *)MALLOC(nsp*sizeof(int)); |
spactive = !nz?0:(ND_pairs *)MALLOC(nsp*sizeof(ND_pairs)); |
spactive = !nz?0:(ND_pairs *)MALLOC(nsp*sizeof(ND_pairs)); |
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
nd_sp(m,0,sp,&spol); |
nd_sp(m,0,sp,&spol); |
if ( !spol ) continue; |
if ( !spol ) continue; |
nd_to_vect128(m,s0vect,col,spol,svect); |
nd_to_vect64(m,s0vect,col,spol,svect); |
maxrs = ndv_reduce_vect128(m,svect,col,imat,rvect,nred); |
maxrs = ndv_reduce_vect64(m,svect,cvect,col,imat,rvect,nred); |
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
if ( i < col ) { |
if ( i < col ) { |
spmat[sprow] = v = (U128 *)MALLOC_ATOMIC(spcol*sizeof(U128)); |
spmat[sprow] = v = (U64 *)MALLOC_ATOMIC(spcol*sizeof(U64)); |
for ( j = k = 0; j < col; j++ ) |
for ( j = k = 0; j < col; j++ ) |
if ( !rhead[j] ) v[k++] = (UINT)svect[j]; |
if ( !rhead[j] ) v[k++] = (UINT)svect[j]; |
spsugar[sprow] = MAX(maxrs,SG(spol)); |
spsugar[sprow] = MAX(maxrs,SG(spol)); |
Line 7361 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
Line 7394 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
} |
} |
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); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7369 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
Line 7402 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
|
|
/* elimination (2nd step) */ |
/* elimination (2nd step) */ |
colstat = (int *)MALLOC(spcol*sizeof(int)); |
colstat = (int *)MALLOC(spcol*sizeof(int)); |
rank = nd_gauss_elim_mod128(spmat,spsugar,spactive,sprow,spcol,m,colstat); |
rank = nd_gauss_elim_mod64(spmat,spsugar,spactive,sprow,spcol,m,colstat); |
r0 = 0; |
r0 = 0; |
for ( i = 0; i < rank; i++ ) { |
for ( i = 0; i < rank; i++ ) { |
NEXTNODE(r0,r); BDY(r) = |
NEXTNODE(r0,r); BDY(r) = |
(pointer)vect128o_ndv(spmat[i],spcol,col,rhead,s0vect); |
(pointer)vect64_to_ndv(spmat[i],spcol,col,rhead,s0vect); |
SG((NDV)BDY(r)) = spsugar[i]; |
SG((NDV)BDY(r)) = spsugar[i]; |
GCFREE(spmat[i]); |
GCFREE(spmat[i]); |
} |
} |
Line 7383 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
Line 7416 NODE nd_f4_red_mod128_main(int m,ND_pairs sp0,int nsp, |
|
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); |
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=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",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,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
if ( nz ) { |
if ( nz ) { |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
Line 7444 NODE nd_f4_red_sf_main(int m,ND_pairs sp0,int nsp,UINT |
|
Line 7477 NODE nd_f4_red_sf_main(int m,ND_pairs sp0,int nsp,UINT |
|
} |
} |
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); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7466 NODE nd_f4_red_sf_main(int m,ND_pairs sp0,int nsp,UINT |
|
Line 7499 NODE nd_f4_red_sf_main(int m,ND_pairs sp0,int nsp,UINT |
|
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); |
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=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",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,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
if ( nz ) { |
if ( nz ) { |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
Line 7521 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
Line 7554 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
} |
} |
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); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7556 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
Line 7589 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
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); |
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=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",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,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
return r0; |
return r0; |
} |
} |
Line 7604 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
Line 7637 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
} |
} |
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); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7638 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
Line 7671 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
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); |
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=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",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,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
return r0; |
return r0; |
} |
} |
Line 7686 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
Line 7719 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
} |
} |
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); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7723 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
Line 7756 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
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); |
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=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",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,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
return r0; |
return r0; |
} |
} |
Line 7976 int nd_gauss_elim_mod(int **mat0,int *sugar,ND_pairs * |
|
Line 8009 int nd_gauss_elim_mod(int **mat0,int *sugar,ND_pairs * |
|
return rank; |
return rank; |
} |
} |
|
|
#if defined(__GNUC__) |
#if defined(__GNUC__) && SIZEOF_LONG==8 |
int nd_gauss_elim_mod128(U128 **mat,int *sugar,ND_pairs *spactive,int row,int col,int md,int *colstat) |
|
|
int nd_gauss_elim_mod64(U64 **mat,int *sugar,ND_pairs *spactive,int row,int col,int md,int *colstat) |
{ |
{ |
int i,j,k,l,rank,s; |
int i,j,k,l,rank,s; |
U64 inv; |
U64 inv; |
U128 a; |
U64 a; |
U128 *t,*pivot,*pk; |
UINT c; |
ND_pairs pair; |
U64 *t,*pivot,*pk; |
|
UINT *ck; |
|
UINT **cmat; |
|
UINT *ct; |
|
ND_pairs pair; |
|
|
for ( rank = 0, j = 0; j < col; j++ ) { |
cmat = (UINT **)MALLOC(row*sizeof(UINT *)); |
for ( i = rank; i < row; i++ ) |
for ( i = 0; i < row; i++ ) { |
mat[i][j] %= md; |
cmat[i] = MALLOC_ATOMIC(col*sizeof(UINT)); |
for ( i = rank; i < row; i++ ) |
bzero(cmat[i],col*sizeof(UINT)); |
if ( mat[i][j] ) |
} |
break; |
|
if ( i == row ) { |
for ( rank = 0, j = 0; j < col; j++ ) { |
colstat[j] = 0; |
for ( i = rank; i < row; i++ ) { |
continue; |
a = mat[i][j]; c = cmat[i][j]; |
} else |
MOD128(a,c,md); |
colstat[j] = 1; |
mat[i][j] = a; cmat[i][j] = 0; |
if ( i != rank ) { |
|
t = mat[i]; mat[i] = mat[rank]; mat[rank] = t; |
|
s = sugar[i]; sugar[i] = sugar[rank]; sugar[rank] = s; |
|
if ( spactive ) { |
|
pair = spactive[i]; spactive[i] = spactive[rank]; |
|
spactive[rank] = pair; |
|
} |
|
} |
|
pivot = mat[rank]; |
|
s = sugar[rank]; |
|
inv = invm((UINT)pivot[j],md); |
|
for ( k = j, pk = pivot+k; k < col; k++, pk++ ) |
|
if ( a = *pk ) { |
|
if ( a >= md ) a %= md; |
|
*pk = ((U64)a*inv)%md; |
|
} |
|
for ( i = rank+1; i < row; i++ ) { |
|
t = mat[i]; |
|
if ( a = (t[j]%md) ) { |
|
sugar[i] = MAX(sugar[i],s); |
|
red_by_vect128(md,t+j,pivot+j,(int)(md-a),col-j); |
|
} |
|
} |
|
rank++; |
|
} |
} |
for ( j = col-1, l = rank-1; j >= 0; j-- ) |
for ( i = rank; i < row; i++ ) |
if ( colstat[j] ) { |
if ( mat[i][j] ) |
pivot = mat[l]; |
break; |
for ( k = j; k < col; k++ ) |
if ( i == row ) { |
if ( pivot[k] >= md ) pivot[k] %= md; |
colstat[j] = 0; |
s = sugar[l]; |
continue; |
for ( i = 0; i < l; i++ ) { |
} else |
t = mat[i]; |
colstat[j] = 1; |
t[j] %= md; |
if ( i != rank ) { |
if ( a = (t[j]%md) ) { |
t = mat[i]; mat[i] = mat[rank]; mat[rank] = t; |
sugar[i] = MAX(sugar[i],s); |
ct = cmat[i]; cmat[i] = cmat[rank]; cmat[rank] = ct; |
red_by_vect128(md,t+j,pivot+j,(int)(md-a),col-j); |
s = sugar[i]; sugar[i] = sugar[rank]; sugar[rank] = s; |
} |
if ( spactive ) { |
} |
pair = spactive[i]; spactive[i] = spactive[rank]; |
l--; |
spactive[rank] = pair; |
|
} |
|
} |
|
/* column j is normalized */ |
|
s = sugar[rank]; |
|
inv = invm((UINT)mat[rank][j],md); |
|
/* normalize pivot row */ |
|
for ( k = j, pk = mat[rank]+j, ck = cmat[rank]+j; k < col; k++, pk++, ck++ ) { |
|
a = *pk; c = *ck; MOD128(a,c,md); *pk = (a*inv)%md; *ck = 0; |
|
} |
|
for ( i = rank+1; i < row; i++ ) { |
|
if ( a = mat[i][j] ) { |
|
sugar[i] = MAX(sugar[i],s); |
|
red_by_vect64(md,mat[i]+j,cmat[i]+j,mat[rank]+j,(int)(md-a),col-j); |
|
} |
|
} |
|
rank++; |
|
} |
|
for ( j = col-1, l = rank-1; j >= 0; j-- ) |
|
if ( colstat[j] ) { |
|
for ( k = j, pk = mat[l]+j, ck = cmat[l]+j; k < col; k++, pk++, ck++ ) { |
|
a = *pk; c = *ck; MOD128(a,c,md); *pk = a; *ck = 0; |
|
} |
|
s = sugar[l]; |
|
for ( i = 0; i < l; i++ ) { |
|
a = mat[i][j]; c = cmat[i][j]; MOD128(a,c,md); mat[i][j] = a; cmat[i][j] = 0; |
|
if ( a ) { |
|
sugar[i] = MAX(sugar[i],s); |
|
red_by_vect64(md,mat[i]+j,cmat[i]+j,mat[l]+j,(int)(md-a),col-j); |
} |
} |
return rank; |
} |
|
l--; |
|
} |
|
for ( i = 0; i < row; i++ ) GCFREE(cmat[i]); |
|
GCFREE(cmat); |
|
return rank; |
} |
} |
#endif |
#endif |
|
|
Line 8330 void nd_det(int mod,MAT f,P *rp) |
|
Line 8377 void nd_det(int mod,MAT f,P *rp) |
|
chsgnq(ONE,&mone); |
chsgnq(ONE,&mone); |
for ( j = 0, sgn = 1; j < n; j++ ) { |
for ( j = 0, sgn = 1; j < n; j++ ) { |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(stderr,".",j); |
fprintf(asir_out,".",j); |
} |
} |
for ( i = j; i < n && !dm[i][j]; i++ ); |
for ( i = j; i < n && !dm[i][j]; i++ ); |
if ( i == n ) { |
if ( i == n ) { |
Line 8360 void nd_det(int mod,MAT f,P *rp) |
|
Line 8407 void nd_det(int mod,MAT f,P *rp) |
|
nd_det_reconstruct(dm,n,j,d); |
nd_det_reconstruct(dm,n,j,d); |
|
|
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
/* if ( DP_Print ) fprintf(stderr," i=%d\n ",i); */ |
/* if ( DP_Print ) fprintf(asir_out," i=%d\n ",i); */ |
mi = dm[i]; mij = mi[j]; |
mi = dm[i]; mij = mi[j]; |
if ( mod ) |
if ( mod ) |
ndv_mul_c(mod,mij,mod-1); |
ndv_mul_c(mod,mij,mod-1); |
else |
else |
ndv_mul_c_q(mij,mone); |
ndv_mul_c_q(mij,mone); |
for ( k = j+1; k < n; k++ ) { |
for ( k = j+1; k < n; k++ ) { |
/* if ( DP_Print ) fprintf(stderr,"k=%d ",k); */ |
/* if ( DP_Print ) fprintf(asir_out,"k=%d ",k); */ |
bucket = create_pbucket(); |
bucket = create_pbucket(); |
if ( mi[k] ) { |
if ( mi[k] ) { |
nmv = BDY(mjj); len = LEN(mjj); |
nmv = BDY(mjj); len = LEN(mjj); |
Line 8386 void nd_det(int mod,MAT f,P *rp) |
|
Line 8433 void nd_det(int mod,MAT f,P *rp) |
|
u = nd_quo(mod,bucket,d); |
u = nd_quo(mod,bucket,d); |
mi[k] = ndtondv(mod,u); |
mi[k] = ndtondv(mod,u); |
} |
} |
/* if ( DP_Print ) fprintf(stderr,"\n",k); */ |
/* if ( DP_Print ) fprintf(asir_out,"\n",k); */ |
} |
} |
d = mjj; |
d = mjj; |
} |
} |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(stderr,"\n",k); |
fprintf(asir_out,"\n",k); |
} |
} |
if ( sgn < 0 ) |
if ( sgn < 0 ) |
if ( mod ) |
if ( mod ) |
Line 8753 void parse_nd_option(NODE opt) |
|
Line 8800 void parse_nd_option(NODE opt) |
|
else if ( !strcmp(key,"lf") ) |
else if ( !strcmp(key,"lf") ) |
nd_lf = value?1:0; |
nd_lf = value?1:0; |
else if ( !strcmp(key,"trace") ) { |
else if ( !strcmp(key,"trace") ) { |
u = BDY((LIST)value); |
if ( value ) { |
nd_nzlist = BDY((LIST)ARG2(u)); |
u = BDY((LIST)value); |
nd_bpe = QTOS((Q)ARG3(u)); |
nd_nzlist = BDY((LIST)ARG2(u)); |
|
nd_bpe = QTOS((Q)ARG3(u)); |
|
} |
} else if ( !strcmp(key,"f4red") ) { |
} else if ( !strcmp(key,"f4red") ) { |
nd_f4red = QTOS((Q)value); |
nd_f4red = QTOS((Q)value); |
} else if ( !strcmp(key,"rank0") ) { |
} else if ( !strcmp(key,"rank0") ) { |
Line 9190 void nd_f4_lf_trace(LIST f,LIST v,int trace,int homo,s |
|
Line 9239 void nd_f4_lf_trace(LIST f,LIST v,int trace,int homo,s |
|
} |
} |
get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"check=%fsec\n",eg_check.exectime+eg_check.gctime); |
fprintf(asir_out,"check=%.3fsec\n",eg_check.exectime+eg_check.gctime); |
/* dp->p */ |
/* dp->p */ |
nd_bpe = cbpe; |
nd_bpe = cbpe; |
nd_setup_parameters(nd_nvar,0); |
nd_setup_parameters(nd_nvar,0); |
Line 9250 NODE nd_f4_lf_trace_main(int m,int **indp) |
|
Line 9299 NODE nd_f4_lf_trace_main(int m,int **indp) |
|
} |
} |
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); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"sugar=%d,symb=%fsec,", |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
sugar,eg_f4.exectime+eg_f4.gctime); |
sugar,eg_f4.exectime+eg_f4.gctime); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
if ( !l0 ) continue; |
if ( !l0 ) continue; |