void lis_input_f(LIS_MATRIX_F *A, LIS_VECTOR_F *b, LIS_VECTOR_F *x, char *filename, LIS_INT *ierr, LIS_INT len) { char buf[1024]; char *p; LIS_DEBUG_FUNC_IN; memset(buf,0x20,sizeof(buf)); strncpy(buf,filename,len); p = &buf[len]; if( len>0 ) { while( *p==' ' ) p--; p++; } *p = '\0'; *ierr = lis_input((LIS_MATRIX)LIS_V2P(A),(LIS_VECTOR)LIS_V2P(b),(LIS_VECTOR)LIS_V2P(x),buf); LIS_DEBUG_FUNC_OUT; return; }
LIS_INT main(LIS_INT argc, char* argv[]) { LIS_MATRIX A0,A,B; LIS_VECTOR x,b,u; LIS_SOLVER solver; LIS_INT nprocs,my_rank; int int_nprocs,int_my_rank; LIS_INT nsol,rhs,len,i,j,k,jj,kk,p,nrow_p,l,n; LIS_INT err,iter,iter_double,iter_quad; LIS_INT *iw,*nrow,*index,*ptr; LIS_SCALAR *s,t,*value; double times,itimes,ptimes,p_c_times,p_i_times; LIS_REAL resid; char solvername[128]; LIS_DEBUG_FUNC_IN; lis_initialize(&argc, &argv); #ifdef USE_MPI MPI_Comm_size(MPI_COMM_WORLD,&int_nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&int_my_rank); nprocs = int_nprocs; my_rank = int_my_rank; #else nprocs = 1; my_rank = 0; #endif if( argc < 5 ) { if( my_rank==0 ) { printf("Usage: %s matrix_filename rhs_setting solution_filename residual_filename [options]\n", argv[0]); } CHKERR(1); } len = (LIS_INT)strlen(argv[2]); if( len==1 ) { if( argv[2][0]=='0' || argv[2][0]=='1' || argv[2][0]=='2' ) { rhs = atoi(argv[2]); } else { rhs = -1; } } else { rhs = -1; } if( my_rank==0 ) { printf("\n"); #ifdef _LONGLONG printf("number of processes = %lld\n",nprocs); #else printf("number of processes = %d\n",nprocs); #endif } #ifdef _OPENMP if( my_rank==0 ) { #ifdef _LONGLONG printf("max number of threads = %lld\n",omp_get_num_procs()); printf("number of threads = %lld\n",omp_get_max_threads()); #else printf("max number of threads = %d\n",omp_get_num_procs()); printf("number of threads = %d\n",omp_get_max_threads()); #endif } #endif /* read matrix and vectors from file */ err = lis_matrix_create(LIS_COMM_WORLD,&A); CHKERR(err); err = lis_vector_create(LIS_COMM_WORLD,&b); CHKERR(err); err = lis_vector_create(LIS_COMM_WORLD,&x); CHKERR(err); err = lis_input(A,b,x,argv[1]); CHKERR(err); err = lis_matrix_duplicate(A,&A0); CHKERR(err); lis_matrix_set_type(A0,LIS_MATRIX_CSR); err = lis_matrix_convert(A,A0); CHKERR(err); lis_matrix_destroy(A); A = A0; err = lis_vector_duplicate(A,&u); CHKERR(err); if( lis_vector_is_null(b) ) { lis_vector_destroy(b); lis_vector_duplicate(A,&b); CHKERR(err); if( rhs==0 ) { CHKERR(1); } else if( rhs==1 ) { err = lis_vector_set_all(1.0,b); } else { err = lis_vector_set_all(1.0,u); lis_matvec(A,u,b); } } if( rhs==-1 ) { lis_input_vector(b,argv[2]); } if( lis_vector_is_null(x) ) { lis_vector_destroy(x); err = lis_vector_duplicate(A,&x); CHKERR(err); } err = lis_solver_create(&solver); CHKERR(err); lis_solver_set_option("-print mem",solver); lis_solver_set_optionC(solver); err = lis_solve(A,b,x,solver); CHKERR(err); lis_solver_get_itersex(solver,&iter,&iter_double,&iter_quad); lis_solver_get_timeex(solver,×,&itimes,&ptimes,&p_c_times,&p_i_times); lis_solver_get_residualnorm(solver,&resid); lis_solver_get_solver(solver,&nsol); lis_solver_get_solvername(nsol,solvername); /* write results */ if( my_rank==0 ) { #ifdef _LONGLONG #ifdef _LONG__DOUBLE printf("%s: number of iterations = %lld \n",solvername, iter); #else printf("%s: number of iterations = %lld (double = %lld, quad = %lld)\n",solvername,iter, iter_double, iter_quad); #endif #else #ifdef _LONG__DOUBLE printf("%s: number of iterations = %d \n",solvername, iter); #else printf("%s: number of iterations = %d (double = %d, quad = %d)\n",solvername,iter, iter_double, iter_quad); #endif #endif printf("%s: elapsed time = %e sec.\n",solvername,times); printf("%s: preconditioner = %e sec.\n",solvername, ptimes); printf("%s: matrix creation = %e sec.\n",solvername, p_c_times); printf("%s: linear solver = %e sec.\n",solvername, itimes); #ifdef _LONG__DOUBLE printf("%s: relative residual 2-norm = %Le\n\n",solvername,resid); #else printf("%s: relative residual 2-norm = %e\n\n",solvername,resid); #endif } /* write solution */ lis_output_vector(x,LIS_FMT_MM,argv[3]); /* write residual */ lis_solver_output_rhistory(solver, argv[4]); lis_solver_destroy(solver); lis_vector_destroy(x); lis_vector_destroy(u); lis_vector_destroy(b); lis_matrix_destroy(A); lis_finalize(); LIS_DEBUG_FUNC_OUT; return 0; }
LIS_INT main(LIS_INT argc, char* argv[]) { LIS_MATRIX A,A0; LIS_VECTOR b,x; LIS_INT nprocs,my_rank; int int_nprocs,int_my_rank; LIS_INT nthreads, maxthreads; LIS_INT nnz; LIS_INT i,n,np; LIS_INT block; LIS_INT is,ie; LIS_INT err,iter,matrix_type; double time,time2,nnzs,nnzap,nnzt; LIS_SCALAR val; double commtime,comptime,flops; char path[1024]; FILE *file; LIS_DEBUG_FUNC_IN; lis_initialize(&argc, &argv); #ifdef USE_MPI MPI_Comm_size(MPI_COMM_WORLD,&int_nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&int_my_rank); nprocs = int_nprocs; my_rank = int_my_rank; #else nprocs = 1; my_rank = 0; #endif if( argc < 3 ) { if( my_rank==0 ) { printf("Usage: %s matrix_filename_list iter [block] \n", argv[0]); } lis_finalize(); exit(0); } file = fopen(argv[1], "r"); if( file==NULL ) CHKERR(1); iter = atoi(argv[2]); if (argv[3] == NULL) { block = 2; } else { block = atoi(argv[3]); } if( iter<=0 ) { #ifdef _LONG__LONG printf("iter=%lld <= 0\n",iter); #else printf("iter=%d <= 0\n",iter); #endif CHKERR(1); } if( my_rank==0 ) { printf("\n"); #ifdef _LONG__LONG printf("number of processes = %lld\n",nprocs); #else printf("number of processes = %d\n",nprocs); #endif } #ifdef _OPENMP if( my_rank==0 ) { nthreads = omp_get_num_procs(); maxthreads = omp_get_max_threads(); #ifdef _LONG__LONG printf("max number of threads = %lld\n", nthreads); printf("number of threads = %lld\n", maxthreads); #else printf("max number of threads = %d\n", nthreads); printf("number of threads = %d\n", maxthreads); #endif } #else nthreads = 1; maxthreads = 1; #endif /* create matrix and vectors */ while( fscanf(file, "%s\n", path)==1 ) { if( my_rank==0 ) { printf("matrix_filename = %s\n", path); } lis_matrix_create(LIS_COMM_WORLD,&A0); err = lis_input(A0,NULL,NULL,path); if( err ) CHKERR(err); n = A0->n; nnz = A0->nnz; np = A0->np-n; #ifdef USE_MPI MPI_Allreduce(&nnz,&i,1,LIS_MPI_INT,MPI_SUM,A0->comm); nnzap = (double)i / (double)nprocs; nnzt = ((double)nnz -nnzap)*((double)nnz -nnzap); nnz = i; MPI_Allreduce(&nnzt,&nnzs,1,MPI_DOUBLE,MPI_SUM,A0->comm); nnzs = (nnzs / (double)nprocs)/nnzap; MPI_Allreduce(&np,&i,1,LIS_MPI_INT,MPI_SUM,A0->comm); np = i; #endif if( my_rank==0 ) { #ifdef _LONG__LONG printf("block size of BSR and BSC = %lld x %lld\n",block,block); printf("number of iterations = %lld\n\n",iter); #else printf("block size of BSR and BSC = %d x %d\n",block,block); printf("number of iterations = %d\n\n",iter); #endif } err = lis_vector_duplicate(A0,&x); if( err ) CHKERR(err); err = lis_vector_duplicate(A0,&b); if( err ) CHKERR(err); lis_matrix_get_range(A0,&is,&ie); for(i=0;i<n;i++) { err = lis_vector_set_value(LIS_INS_VALUE,i+is,1.0,x); } /* MPI version of VBR is not implemented. DNS is also excluded to reduce memory usage. */ for (matrix_type=1;matrix_type<11;matrix_type++) { if ( nprocs>1 && matrix_type==9 ) continue; lis_matrix_duplicate(A0,&A); lis_matrix_set_type(A,matrix_type); err = lis_matrix_convert(A0,A); if( err ) CHKERR(err); if( my_rank==0 ) { if( A->matrix_type==LIS_MATRIX_BSR || A->matrix_type==LIS_MATRIX_BSC ) { A->bnr = block; A->bnc = block; } } comptime = 0.0; commtime = 0.0; for(i=0;i<iter;i++) { #ifdef USE_MPI MPI_Barrier(A->comm); time = lis_wtime(); lis_send_recv(A->commtable,x->value); commtime += lis_wtime() - time; #endif time2 = lis_wtime(); lis_matvec(A,x,b); comptime += lis_wtime() - time2; } lis_vector_nrm2(b,&val); if( my_rank==0 ) { flops = 2.0*nnz*iter*1.0e-6 / comptime; #ifdef USE_MPI #ifdef _LONG__DOUBLE #ifdef _LONG__LONG printf("matrix_type = %2lld (%s), computation = %e sec, %8.3f MFLOPS, communication = %e sec, communication/computation = %3.3f %%, 2-norm = %Le\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,commtime,commtime/comptime*100,val); #else printf("matrix_type = %2d (%s), computation = %e sec, %8.3f MFLOPS, communication = %e sec, communication/computation = %3.3f %%, 2-norm = %Le\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,commtime,commtime/comptime*100,val); #endif #else #ifdef _LONG__LONG printf("matrix_type = %2lld (%s), computation = %e sec, %8.3f MFLOPS, communication = %e sec, communication/computation = %3.3f %%, 2-norm = %e\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,commtime,commtime/comptime*100,val); #else printf("matrix_type = %2d (%s), computation = %e sec, %8.3f MFLOPS, communication = %e sec, communication/computation = %3.3f %%, 2-norm = %e\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,commtime,commtime/comptime*100,val); #endif #endif #else #ifdef _LONG__DOUBLE #ifdef _LONG__LONG printf("matrix_type = %2lld (%s), computation = %e sec, %8.3f MFLOPS, 2-norm = %Le\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,val); #else printf("matrix_type = %2d (%s), computation = %e sec, %8.3f MFLOPS, 2-norm = %Le\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,val); #endif #else #ifdef _LONG__LONG printf("matrix_type = %2lld (%s), computation = %e sec, %8.3f MFLOPS, 2-norm = %e\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,val); #else printf("matrix_type = %2d (%s), computation = %e sec, %8.3f MFLOPS, 2-norm = %e\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,val); #endif #endif #endif } lis_matrix_destroy(A); } lis_matrix_destroy(A0); lis_vector_destroy(b); lis_vector_destroy(x); } fclose(file); lis_finalize(); LIS_DEBUG_FUNC_OUT; return 0; }
LIS_INT main(LIS_INT argc, char* argv[]) { LIS_MATRIX A,A0; LIS_VECTOR b,x,v; LIS_SCALAR ntimes,nmflops,nnrm2; LIS_SCALAR *value; LIS_INT nprocs,my_rank; int int_nprocs,int_my_rank; LIS_INT nthreads, maxthreads; LIS_INT gn,nnz,mode; LIS_INT i,j,jj,j0,j1,l,k,n,np,h,ih; LIS_INT m,nn,ii; LIS_INT block; LIS_INT rn,rmin,rmax,rb; LIS_INT is,ie,clsize,ci,*iw; LIS_INT err,iter,matrix_type; LIS_INT *ptr,*index; double mem,val,ra,rs,ri,ria,ca,time,time2,convtime,val2,nnzs,nnzap,nnzt; double commtime,comptime,flops; FILE *file; char path[1024]; LIS_DEBUG_FUNC_IN; lis_initialize(&argc, &argv); #ifdef USE_MPI MPI_Comm_size(MPI_COMM_WORLD,&int_nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&int_my_rank); nprocs = int_nprocs; my_rank = int_my_rank; #else nprocs = 1; my_rank = 0; #endif if( argc < 4 ) { if( my_rank==0 ) printf("Usage: spmvtest5 matrix_filename matrix_type iter [block] \n"); lis_finalize(); exit(0); } file = fopen(argv[1], "r"); if( file==NULL ) CHKERR(1); matrix_type = atoi(argv[2]); iter = atoi(argv[3]); if (argv[4] == NULL) { block = 2; } else { block = atoi(argv[4]); } if( matrix_type<1 || matrix_type>11 ) { if( my_rank==0 ) printf("matrix_type=%d <1 or matrix_type=%d >11\n",matrix_type,matrix_type); CHKERR(1); } if( iter<=0 ) { if( my_rank==0 ) printf("iter=%d <= 0\n",iter); CHKERR(1); } if( my_rank==0 ) { printf("\n"); printf("number of processes = %d\n",nprocs); } #ifdef _OPENMP if( my_rank==0 ) { nthreads = omp_get_num_procs(); maxthreads = omp_get_max_threads(); printf("max number of threads = %d\n", nthreads); printf("number of threads = %d\n", maxthreads); } #else nthreads = 1; maxthreads = 1; #endif /* create matrix and vectors */ lis_matrix_create(LIS_COMM_WORLD,&A0); err = lis_input(A0,NULL,NULL,argv[1]); CHKERR(err); n = A0->n; gn = A0->gn; nnz = A0->nnz; np = A0->np-n; #ifdef USE_MPI MPI_Allreduce(&nnz,&i,1,LIS_MPI_INT,MPI_SUM,A0->comm); nnzap = (double)i / (double)nprocs; nnzt = ((double)nnz -nnzap)*((double)nnz -nnzap); nnz = i; MPI_Allreduce(&nnzt,&nnzs,1,MPI_DOUBLE,MPI_SUM,A0->comm); nnzs = (nnzs / (double)nprocs)/nnzap; MPI_Allreduce(&np,&i,1,LIS_MPI_INT,MPI_SUM,A0->comm); np = i; #endif if( my_rank==0 ) { printf("block size of BSR and BSC = %d x %d\n",block,block); printf("iteration count = %d\n\n",iter); } err = lis_vector_duplicate(A0,&x); if( err ) CHKERR(err); err = lis_vector_duplicate(A0,&b); if( err ) CHKERR(err); lis_matrix_get_range(A0,&is,&ie); for(i=0;i<n;i++) { err = lis_vector_set_value(LIS_INS_VALUE,i+is,1.0,x); } lis_matrix_duplicate(A0,&A); lis_matrix_set_type(A,matrix_type); err = lis_matrix_convert(A0,A); if( err ) CHKERR(err); if( A->matrix_type==LIS_MATRIX_BSR || A->matrix_type==LIS_MATRIX_BSC ) { A->bnr = block; A->bnc = block; } comptime = 0.0; commtime = 0.0; for(i=0;i<iter;i++) { #ifdef USE_MPI MPI_Barrier(A->comm); time = lis_wtime(); lis_send_recv(A->commtable,x->value); commtime += lis_wtime() - time; #endif time2 = lis_wtime(); lis_matvec(A,x,b); comptime += lis_wtime() - time2; } lis_vector_nrm2(b,&val); if( my_rank==0 ) { flops = 2.0*nnz*iter*1.0e-6 / comptime; printf("matrix_type = %2d (%s), computation = %e sec, %8.3f MFLOPS, communication = %e sec, communication/computation = %3.3f %%, 2-norm = %e\n",matrix_type,lis_storagename2[matrix_type-1],comptime,flops,commtime,commtime/comptime*100,val); } lis_matrix_destroy(A); lis_matrix_destroy(A0); lis_vector_destroy(b); lis_vector_destroy(x); lis_finalize(); LIS_DEBUG_FUNC_OUT; return 0; }
LIS_INT main(LIS_INT argc, char* argv[]) { LIS_MATRIX A; LIS_VECTOR b,x; LIS_INT nprocs,my_rank; int int_nprocs,int_my_rank; LIS_INT format; LIS_INT err; LIS_DEBUG_FUNC_IN; lis_initialize(&argc, &argv); #ifdef USE_MPI MPI_Comm_size(MPI_COMM_WORLD,&int_nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&int_my_rank); nprocs = int_nprocs; my_rank = int_my_rank; #else nprocs = 1; my_rank = 0; #endif if( argc < 4 ) { err_print: if( my_rank==0 ) { printf("%s out_format out_matrix_filename in_matrix_filename [in_rhs_file in_init_file]\n", argv[0]); } CHKERR(1); } if( strncmp(argv[1], "mmb", 3)==0 ) { format = LIS_FMT_MMB; } else if( strncmp(argv[1], "mm", 2)==0 ) { format = LIS_FMT_MM; } else { goto err_print; } if( my_rank==0 ) { printf("\n"); #ifdef _LONGLONG printf("number of processes = %lld\n",nprocs); #else printf("number of processes = %d\n",nprocs); #endif } #ifdef _OPENMP if( my_rank==0 ) { #ifdef _LONGLONG printf("max number of threads = %lld\n",omp_get_num_procs()); printf("number of threads = %lld\n",omp_get_max_threads()); #else printf("max number of threads = %d\n",omp_get_num_procs()); printf("number of threads = %d\n",omp_get_max_threads()); #endif } #endif /* read matrix and vectors from file */ err = lis_matrix_create(LIS_COMM_WORLD,&A); CHKERR(err); err = lis_vector_create(LIS_COMM_WORLD,&b); CHKERR(err); err = lis_vector_create(LIS_COMM_WORLD,&x); CHKERR(err); err = lis_input(A,b,x,argv[3]); CHKERR(err); if( argc>4 ) { if( !lis_vector_is_null(b) ) { lis_vector_destroy(b); err = lis_vector_create(LIS_COMM_WORLD,&b); CHKERR(err); } err = lis_input_vector(b,argv[4]); CHKERR(err); if( A->n!=b->n ) { #ifdef _LONGLONG printf("different dimension: matrix A=%lld, vector b=%lld\n",A->n,b->n); #else printf("different dimension: matrix A=%d, vector b=%d\n",A->n,b->n); #endif goto err_to; } if( argc==6 ) { if( !lis_vector_is_null(x) ) { lis_vector_destroy(x); err = lis_vector_create(LIS_COMM_WORLD,&x); CHKERR(err); } err = lis_input_vector(x,argv[5]); CHKERR(err); if( A->n!=x->n ) { #ifdef _LONGLONG printf("different dimension: matrix A=%lld, vector x=%lld\n",A->n,x->n); #else printf("different dimension: matrix A=%d, vector x=%d\n",A->n,x->n); #endif goto err_to; } } } err = lis_output(A,b,x,format,argv[2]); CHKERR(err); err_to: lis_matrix_destroy(A); lis_vector_destroy(b); lis_vector_destroy(x); lis_finalize(); LIS_DEBUG_FUNC_OUT; return 0; }