#include #include #include #include #include #include #include #include #include "kimura_common.h" #define NB2 64 #define UP0 10 #define UP1 10 #define SPEED 64 #pragma pack(1) int *restrict IAP,*restrict IA,*restrict JA; mpz_t chtmp1,chtmp2,chtmp3,chtmp4; mpz_t *restrict zmatrix; mpz_t ** restrict row,** restrict colm; mpz_t * restrict resultZ; /* definition */ #define MAXlett 65535 #define MAXline 655350000 int MAXmat; int nonzero; int NB; int MAXthreads; jmp_buf ma; UI invm2_(UI a,UI CM){ UI d, q, r; int s, t, x; d=CM; x=0; s=1; while(a!=0){ q=d/a; r=d%a; d=a; a=r; t=x-q*s; x=s; s=t; } if(d!=1){ printf("Miller-Rabin method is false.\n"); } return (x+CM); } int getline2(char * restrict line,FILE * restrict fp){ int c; int i; for(i=0;iCMh) v=v-CM; else if (v<-CMh) v=v+CM; B[tmp0+k][j]=v; } } } if(tmp0==MAXmat){ dgemm_("N","N",&MAXmat,&NB,&MAXmat,&ALPHA,A,&MAXmat,&B[tmp0-NB][0],&MAXmat,&BETA,C,&MAXmat); for(k=0;kCMh) v=v-CM; else if (v<-CMh) v=v+CM; C[k][j]=v; } } } else{ dgemm_("N","N",&MAXmat,&NB,&MAXmat,&ALPHA,A,&MAXmat,&B[tmp0-NB][0],&MAXmat,&BETA,WORKD,&MAXmat); tmp1=MAXmat-tmp0; for(k=0;kCMh) v=v-CM; else if (v<-CMh) v=v+CM; B[k+tmp0][j]=v; } } tmp2=NB-tmp1; for(k=0;kCMh) v=v-CM; else if (v<-CMh) v=v+CM; C[k][j]=v; } } dgemm_("N","N",&MAXmat,&tmp1,&MAXmat,&ALPHA,A,&MAXmat,&B[tmp0][0],&MAXmat,&BETA,&C[tmp2][0],&MAXmat); for(k=0;kCMh) v=v-CM; else if (v<-CMh) v=v+CM; C[k+tmp2][j]=v; } } } } UI makesind(UI (* restrict vmatrix)[MAXmat],UI * restrict ut,UI * restrict vt,UI * restrict v2t,UI CM,ULL CMX){ int i,j; ULL tmp; UI tmp0; int NN; NN=MAXmat-NB; for(j=0;j=0;k--){ polyc[k+1]=polyc[k]; } polyc[0]=0; } for(k=0;k=3;CM-=2){ for(mpz_set_ui(chtmp1,CM); mpz_probab_prime_p(chtmp1,5)==0; CM--,mpz_set_ui(chtmp1,CM)) ; num_CM=num_CM+1; if((CMD=(SI * restrict)realloc(CMD,sizeof(SI)*num_CM))==NULL){ printf("Out of memory!\n"); return 0; } CMD[num_CM-1]=CM; mpz_mul_ui(chtmp4,chtmp4,CM); if(mpz_cmp(chtmp4,chtmp3)>=0) break; } if (CM<3){ printf("p ga tarinai\n"); return 0; } if((CMhD=(SI * restrict)malloc(sizeof(SI)*num_CM))==NULL){ printf("Out of memory!\n"); return 0; } if((CM_result=(UI ** restrict)malloc(sizeof(UI *)*num_CM))==NULL){ printf("Out of memory!\n"); return 0; } CM_flag=0; #pragma omp parallel private(chtmpu,INFO,k,j,l,A,B,C,WORK,WORK2,WORKD,WORKD3,CM,CMh,v,polya,polyb,polyc,ut,vt,v2t,sind,IPIV,WORKD2) { mpz_init(chtmpu); if((A=(double (* restrict)[MAXmat]) malloc(sizeof(double)*MAXmat*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((B=(double (* restrict)[MAXmat]) malloc(sizeof(double)*MAXmat*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((C=(double (* restrict)[MAXmat]) malloc(sizeof(double)*MAXmat*NB+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((WORKD3=(double (* restrict)[MAXmat]) malloc(sizeof(double)*MAXmat*NB+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((WORK=(SI (*restrict)[MAXmat]) malloc(sizeof(SI)*MAXmat*NB+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((WORK2=(UI (*restrict)[MAXmat]) malloc(sizeof(UI)*MAXmat*NB+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((polya=(UI * restrict)malloc(sizeof(UI)*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((polyb=(UI * restrict)malloc(sizeof(UI)*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((polyc=(UI * restrict)malloc(sizeof(UI)*(MAXmat+1)+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((ut=(UI * restrict)malloc(sizeof(UI)*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((vt=(UI * restrict)malloc(sizeof(UI)*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((v2t=(UI * restrict)malloc(sizeof(UI)*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((sind=(UI * restrict)malloc(sizeof(UI)*2*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((IPIV=(int * restrict)malloc(sizeof(int)*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } if((WORKD2=(double * restrict)malloc(sizeof(double)*MAXmat+SPEED))==NULL){ printf("out of memory.\n"); CM_flag=1; } #pragma omp for for(i=0;iCMh) v=v-CM; A[k][JA[j]]=v; } } for(j=0;jCMh) v=v-CM; else if (v<-CMh) v=v+CM; B[j][k]=v; } } A_mul_v_(A,B,C,WORKD3,CM,CMh); fgetrf_blas_inner_(MAXmat,MAXmat,MAXmat,B, IPIV,WORK,WORKD,WORKD2,CM,CMh,&INFO); if(INFO!=0){ printf("F1"); fflush(stdout); continue; } dlaswp_(&NB,C,&MAXmat,&IONE,&MAXmat,IPIV,&IONE); ftrsmL_recursive_(MAXmat,NB,MAXmat,B,MAXmat,C,CM,CMh); ftrsmU_recursive_(MAXmat,NB,MAXmat,B,MAXmat,C,WORK,CM,CMh); for(k=0;k=UP0){ free(CM_result[i]); CM_result[i]=NULL; continue; } } else{ memset(WORK2,0,sizeof(UI)*MAXmat*MAXmat); for (k = 0; k < MAXmat; k++){ for(j=IAP[k];jCMh) v=v-CM; WORK2[k][JA[j]]=v; } } } for(l=0;l=UP0){ free(CM_result[i]); CM_result[i]=NULL; continue; } for(j=0;j=UP1){ printf("FAULT!\n"); fflush(stdout); return 0; } if(n>0){ if((tD=(UI * restrict)malloc(sizeof(UI)*num_CM))==NULL){ printf("Out of memory!\n"); return 0; } if((chtmps=(mpz_t * restrict)malloc(sizeof(mpz_t)*num_CM))==NULL){ printf("Out of memory!\n"); return 0; } for(i=0;iCMhD[i]) ? tmp-CMD[i] : tmp; mpz_mul_si(chtmpu,chtmps[i],(long int)(int)tmp); mpz_add(resultZ[j],resultZ[j],chtmpu); } } } } mpz_clear(chtmpu); } if(n==num_CM) return MAXmat; for(j=0;j 0) mpz_set (chtmp1, chtmp2); mpz_sqrtrem (chtmp3, chtmp2, chtmp1); if (mpz_cmp_ui (chtmp2, 0) != 0) mpz_add_ui (chtmp3, chtmp3, 1); mpz_mul_ui (chtmp3, chtmp3, 2); mpz_add_ui (chtmp3, chtmp3, 1); return 1; } int main(int argc,char ** restrict argv){ int i, k, l, t; long int bit_bound; int row0, colm0; FILE * restrict fp; char * restrict line; int line0; int key; mpz_init(chtmp1); mpz_init(chtmp2); mpz_init(chtmp3); mpz_init(chtmp4); MAXthreads = omp_get_max_threads (); srand(getpid()); if (argc<3){ printf("input file name.\n"); return 0; } fp=fopen(argv[1],"r"); if ((line=(char * restrict)malloc(sizeof(char)*MAXlett))==NULL){ printf("out of momory.\n"); return 0; } k = 0; l = 0; printf("read file.\n"); for(line0=0;line0=0;i--){ if(mpz_cmp_si(resultZ[i],0)!=0){ switch(i){ case 0: gmp_fprintf(fp,"+(%Zd)",resultZ[i]); break; case 1: if(mpz_cmp_si(resultZ[i],1)==0) gmp_fprintf(fp,"+x"); else gmp_fprintf(fp,"+(%Zd)*x",resultZ[i]); break; default: if(mpz_cmp_si(resultZ[i],1)==0) gmp_fprintf(fp,"+x^%d",i); else gmp_fprintf(fp,"+(%Zd)*x^%d",resultZ[i],i); } } } gmp_fprintf(fp,"\n"); fclose(fp); return 0; }