void gchol(Sint *n2, double *matrix, double *toler) { int i,j; int n/*, flag*/; double **mat; n = *n2; mat = dmatrix(matrix, n, n); i = cholesky5(mat, n, *toler); *toler = i; /* zero out the upper triangle */ for (i=0; i<n; i++) { for (j= i+1; j<n; j++) mat[i][j] =0; } }
static int comp_varp(double *rr,int m) { int i; double a; i=cholesky5(rr11,rr,m,ceps,perm1); if (i<0) { tr=-1.0; return(1); } if (method==3) { tr=0.0; for (i=0; i<m; ++i) { a=rr11[i*(m+1)]; tr+=fabs(a); } } else { tr=0.0; for (i=0; i<m; ++i) { a=rr11[i*(m+1)]; tr+=a*a; } } return(1); }
int main() { int n = 3; double m1[] = {25, 15, -5, 15, 18, 0, -5, 0, 11}; double *c1 = cholesky(m1, n); show_matrix(c1, n); free(c1); n = 4; double m2[] = {18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106}; printf("\n"); double *c2 = cholesky4(m2, n); show_matrix(c2, n); free(c2); n = 1000; double *m3 = (double*)malloc(sizeof(double)*n*n); for(int i=0; i<n; i++) { for(int j=i; j<n; j++) { double element = 1.0*rand()/RAND_MAX; m3[i*n+j] = element; m3[j*n+i] = element; } } double *m4 = (double*)malloc(sizeof(double)*n*n); gemm_ATA(m3, m4, n); //make a positive-definite matrix printf("\n"); //show_matrix(m4,n); double dtime; double *c3 = cholesky4(m4, n); //warm up OpenMP free(c3); dtime = omp_get_wtime(); c3 = cholesky(m4, n); dtime = omp_get_wtime() - dtime; printf("dtime %f\n", dtime); dtime = omp_get_wtime(); double *c4 = cholesky5(m4, n); dtime = omp_get_wtime() - dtime; printf("dtime %f\n", dtime); printf("%d\n", memcmp(c3, c4, sizeof(double)*n*n)); //show_matrix(c3,n); printf("\n"); //show_matrix(c4,n); //for(int i=0; i<100; i++) printf("%f %f %f \n", m4[i], c3[i], c4[i]); /* double *l = (double*)malloc(sizeof(double)*n*n); dtime = omp_get_wtime(); cholesky_dll(m3, l, n); dtime = omp_get_wtime() - dtime; printf("dtime %f\n", dtime); */ //printf("%d\n", memcmp(c3, c4, sizeof(double)*n*n)); //for(int i=0; i<100; i++) printf("%f %f %f \n", m3[i], c3[i], c4[i]); //free(c3); //free(c4); //free(m3); return 0; }