Example #1
0
void CHKERR(LIS_INT ierr)
{
    if(ierr)
    {
        lis_finalize();
        exit(ierr);
    }
}
void lis_finalize_f(LIS_INT *ierr)
{
  LIS_DEBUG_FUNC_IN;

  *ierr = lis_finalize();

  LIS_DEBUG_FUNC_OUT;
  return;
}
Example #3
0
int main(int argc, char *argv[]) {
  int i, n_steps, grid[lbmodel.n_dim], vol;
  double rho, gamma, kappa;
  double start, finish, elapsed, mups;

  if (argc!=3) {
    fprintf(stderr, "Usage: ./run <kappa> <nsteps>\n");
    return -1;
  }	   

  lis_initialize(&argc, &argv);

  n_steps = atoi(argv[2]);

  grid[0] = 100;
  grid[1] = 20;

  vol = grid[0]*grid[1];

  rho   = 1.0;
  gamma = 0.0;
  kappa = atof(argv[1]);

  write_eos();

  char filename[1024];
  sprintf(filename, "profile_k%.03f.dat", kappa);

  lb_init(grid,rho,gamma,kappa); lb_mass_mom(0);

  fprintf(stdout, "Running  %d iterations\n", n_steps); fflush(stdout);

  start = (double) clock();
  for (i=0; i<n_steps; ++i) {
    lb_update(lbf);
    lb_mass_mom(i+1);
    write_profile(filename, 0);
  }
  finish = (double) clock();

  elapsed = (finish-start)/CLOCKS_PER_SEC;
  mups = vol*n_steps/elapsed/1e6;

  fprintf(stdout, "Elapsed time: %.3f s (%.3e MUPS)\n", elapsed, mups); fflush(stdout); 

  write_profile(filename, 0);

  lb_finalize();

  lis_finalize();

  return EXIT_SUCCESS;

}
void CHKERR_f(LIS_INT *err)
{
  LIS_DEBUG_FUNC_IN;

  if(*err)
  {
    lis_finalize();
    exit(*err);
  }

  LIS_DEBUG_FUNC_OUT;
}
Example #5
0
LIS_INT main(LIS_INT argc, char* argv[])
{
    LIS_INT i,n,gn,is,ie;
    LIS_INT nprocs,my_rank;
    int int_nprocs,int_my_rank;
    LIS_INT nesol;
    LIS_MATRIX A;
    LIS_VECTOR x;
    LIS_REAL evalue0;
    LIS_ESOLVER esolver;
    LIS_REAL residual;
    LIS_INT iter;
    double time;
    double itime,ptime,p_c_time,p_i_time;
    char esolvername[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 < 2 )
      {
	if( my_rank==0 ) 
	  {
	      printf("Usage: %s n [eoptions]\n", argv[0]);
	  }
	CHKERR(1);
      }

  if( my_rank==0 )
    {
      printf("\n");
      printf("number of processes = %d\n",nprocs);
    }

#ifdef _OPENMP
  if( my_rank==0 )
    {
#ifdef _LONG__LONG
      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
		
    /* generate coefficient matrix for one dimensional Poisson equation */
    n = atoi(argv[1]);
    lis_matrix_create(LIS_COMM_WORLD,&A);
    lis_matrix_set_size(A,0,n);
    lis_matrix_get_size(A,&n,&gn);
    lis_matrix_get_range(A,&is,&ie);
    for(i=is;i<ie;i++)
    {
      if( i>0   )  lis_matrix_set_value(LIS_INS_VALUE,i,i-1,-1.0,A);
      if( i<gn-1 ) lis_matrix_set_value(LIS_INS_VALUE,i,i+1,-1.0,A);
      lis_matrix_set_value(LIS_INS_VALUE,i,i,2.0,A);
    }
    lis_matrix_set_type(A,LIS_MATRIX_CSR);
    lis_matrix_assemble(A);
    lis_vector_duplicate(A,&x);

    lis_esolver_create(&esolver);
    lis_esolver_set_option("-eprint mem",esolver);
    lis_esolver_set_optionC(esolver);
    lis_esolve(A, x, &evalue0, esolver);
    lis_esolver_get_esolver(esolver,&nesol);
    lis_esolver_get_esolvername(nesol,esolvername);
    lis_esolver_get_residualnorm(esolver, &residual);
    lis_esolver_get_iter(esolver, &iter);
    lis_esolver_get_timeex(esolver,&time,&itime,&ptime,&p_c_time,&p_i_time);
    if( my_rank==0 ) {
      printf("%s: mode number          = %d\n", esolvername, 0);
#ifdef _LONG__DOUBLE
      printf("%s: eigenvalue           = %Le\n", esolvername, evalue0);
#else
      printf("%s: eigenvalue           = %e\n", esolvername, evalue0);
#endif
#ifdef _LONG__LONG
      printf("%s: number of iterations = %lld\n",esolvername, iter);
#else
      printf("%s: number of iterations = %d\n",esolvername, iter);
#endif
      printf("%s: elapsed time         = %e sec.\n", esolvername, time);
      printf("%s:   preconditioner     = %e sec.\n", esolvername, ptime);
      printf("%s:     matrix creation  = %e sec.\n", esolvername, p_c_time);
      printf("%s:   linear solver      = %e sec.\n", esolvername, itime);
#ifdef _LONG__DOUBLE
      printf("%s: relative residual    = %Le\n\n",esolvername, residual);
#else
      printf("%s: relative residual    = %e\n\n",esolvername, residual);
#endif
  }

    /*
    lis_vector_nrm2(x, &xnrm2);
    lis_vector_scale((1/xnrm2*sqrt(n)), x);
    lis_vector_print(x);
    */

    /*
    lis_vector_create(LIS_COMM_WORLD,&y);
    lis_matrix_create(LIS_COMM_WORLD,&B);
    lis_esolver_get_evalues(esolver,y);
    lis_esolver_get_evectors(esolver,B);
    lis_output_vector(y,LIS_FMT_MM,"evalues.out");
    lis_output_matrix(B,LIS_FMT_MM,"evectors.out");
    lis_vector_destroy(y);
    lis_matrix_destroy(B);
    */

    lis_esolver_destroy(esolver);
    lis_matrix_destroy(A);
    lis_vector_destroy(x);

    lis_finalize();

    LIS_DEBUG_FUNC_OUT;

    return 0;
}
Example #6
0
File: test2.c Project: huahbo/lis
LIS_INT main(LIS_INT argc, char* argv[])
{
	LIS_MATRIX A0,A;
	LIS_VECTOR x,b,u;
	LIS_SOLVER solver;
	LIS_INT m,n,nn,nnz;
	LIS_INT	i,j,ii,jj,ctr;
	LIS_INT	is,ie;
	LIS_INT	nprocs,my_rank;
	int int_nprocs,int_my_rank;
	LIS_INT	nsol;
	LIS_INT	err,iter,mtype,iter_double,iter_quad;
	double time,itime,ptime,p_c_time,p_i_time;
	LIS_REAL resid;
	char solvername[128];
	LIS_INT	*ptr,*index;
	LIS_SCALAR *value;


	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 < 6 )
	{
	  if( my_rank==0 ) 
{
	      printf("Usage: %s m n matrix_type solution_filename rhistory_filename [options]\n", argv[0]);
 }
	  CHKERR(1);
	}

	m  = atoi(argv[1]);
	n  = atoi(argv[2]);
	mtype  = atoi(argv[3]);
	if( m<=0 || n<=0 )
	{
#ifdef _LONGLONG
	  if( my_rank==0 ) printf("m=%lld <=0 or n=%lld <=0\n",m,n);
#else
	  if( my_rank==0 ) printf("m=%d <=0 or n=%d <=0\n",m,n);
#endif
	  CHKERR(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
		
	/* create matrix and vectors */
	nn = m*n;
	err = lis_matrix_create(LIS_COMM_WORLD,&A);
	err = lis_matrix_set_size(A,0,nn);
	CHKERR(err);

	ptr   = (LIS_INT *)malloc((A->n+1)*sizeof(LIS_INT));
	if( ptr==NULL ) CHKERR(1);
	index = (LIS_INT *)malloc(5*A->n*sizeof(LIS_INT));
	if( index==NULL ) CHKERR(1);
	value = (LIS_SCALAR *)malloc(5*A->n*sizeof(LIS_SCALAR));
	if( value==NULL ) CHKERR(1);

	lis_matrix_get_range(A,&is,&ie);
	ctr = 0;
	for(ii=is;ii<ie;ii++)
	{
		i = ii/m;
		j = ii - i*m;
		if( i>0 )   { jj = ii - m; index[ctr] = jj; value[ctr++] = -1.0;}
		if( i<n-1 ) { jj = ii + m; index[ctr] = jj; value[ctr++] = -1.0;}
		if( j>0 )   { jj = ii - 1; index[ctr] = jj; value[ctr++] = -1.0;}
		if( j<m-1 ) { jj = ii + 1; index[ctr] = jj; value[ctr++] = -1.0;}
		index[ctr] = ii; value[ctr++] = 4.0;
		ptr[ii-is+1] = ctr;
	}
	ptr[0] = 0;
	err = lis_matrix_set_csr(ptr[ie-is],ptr,index,value,A);
	CHKERR(err);
	err = lis_matrix_assemble(A);
	CHKERR(err);

	nnz = A->nnz;
#ifdef USE_MPI
	MPI_Allreduce(&nnz,&i,1,LIS_MPI_INT,MPI_SUM,A->comm);
	nnz   = i;
#endif

#ifdef _LONGLONG
	if( my_rank==0 ) printf("matrix size = %lld x %lld (%lld nonzero entries)\n\n",nn,nn,nnz);
#else
	if( my_rank==0 ) printf("matrix size = %d x %d (%d nonzero entries)\n\n",nn,nn,nnz);
#endif

	err = lis_matrix_duplicate(A,&A0);
	CHKERR(err);
	lis_matrix_set_type(A0,mtype);
	err = lis_matrix_convert(A,A0);
	CHKERR(err);
	lis_matrix_destroy(A);
	A = A0;

	err = lis_vector_duplicate(A,&u);
	CHKERR(err);
	err = lis_vector_duplicate(A,&b);
	CHKERR(err);
	err = lis_vector_duplicate(A,&x);
	CHKERR(err);

	err = lis_vector_set_all(1.0,u);
	lis_matvec(A,u,b);

	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_iterex(solver,&iter,&iter_double,&iter_quad);
	lis_solver_get_timeex(solver,&time,&itime,&ptime,&p_c_time,&p_i_time);
	lis_solver_get_residualnorm(solver,&resid);
	lis_solver_get_solver(solver,&nsol);
	lis_solver_get_solvername(nsol,solvername);
	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,time);
		printf("%s:   preconditioner     = %e sec.\n",solvername, ptime);
		printf("%s:     matrix creation  = %e sec.\n",solvername, p_c_time);
		printf("%s:   linear solver      = %e sec.\n",solvername, itime);
#ifdef _LONG__DOUBLE
		printf("%s: relative residual    = %Le\n\n",solvername,resid);
#else
		printf("%s: relative residual    = %e\n\n",solvername,resid);
#endif
	}

	/* write solution */
	lis_output_vector(x,LIS_FMT_MM,argv[4]);

	/* write residual history */
	lis_solver_output_rhistory(solver, argv[5]); 

	lis_solver_destroy(solver);
	lis_matrix_destroy(A);
	lis_vector_destroy(b);
	lis_vector_destroy(x);
	lis_vector_destroy(u);

	lis_finalize();

	LIS_DEBUG_FUNC_OUT;
	return 0;
}
Example #7
0
File: test5.c Project: huahbo/lis
LIS_INT main(LIS_INT argc, char* argv[])
{
	LIS_MATRIX A;
	LIS_VECTOR x,b,u;
	LIS_SOLVER solver;
	LIS_INT	k,n,gn,ii,jj;
	LIS_INT	is,ie;
	LIS_INT	nprocs,my_rank;
	int int_nprocs,int_my_rank;
	LIS_INT	nsol;
	LIS_INT	err,iter,iter_double,iter_quad;
	double time,itime,ptime,p_c_time,p_i_time;
	LIS_REAL resid;
	char solvername[128];
	LIS_INT	*ptr,*index;
	LIS_SCALAR *value,gamma;

	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 n gamma [options]\n", argv[0]);
	    }
	  CHKERR(1);
	}

	gn  = atoi(argv[1]);
	gamma  = atof(argv[2]);
	if( gn<=0 )
	{
#ifdef _LONGLONG
		if( my_rank==0 ) printf("n=%lld <=0 \n",gn);
#else
		if( my_rank==0 ) printf("n=%d <=0 \n",gn);
#endif
		CHKERR(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
		
	if(my_rank==0) 
	  {
#ifdef _LONGLONG
	    printf("n = %lld, gamma = %f\n\n",gn,gamma);
#else
	    printf("n = %d, gamma = %f\n\n",gn,gamma);
#endif
	  }
		
	/* create matrix and vectors */
	err = lis_matrix_create(LIS_COMM_WORLD,&A); CHKERR(err);
	err = lis_matrix_set_size(A,0,gn); CHKERR(err);
	err = lis_matrix_get_size(A,&n,&gn); CHKERR(err);
	err = lis_matrix_malloc_csr(n,3*n,&ptr,&index,&value); CHKERR(err);
	err = lis_matrix_get_range(A,&is,&ie); CHKERR(err);

	k = 0;
	ptr[0] = 0;
	for(ii=is;ii<ie;ii++)
	{
		if( ii>1 )    { jj = ii - 2; index[k] = jj; value[k++] = gamma;}
		if( ii<gn-1 ) { jj = ii + 1; index[k] = jj; value[k++] = 1.0;}
		index[k] = ii; value[k++] = 2.0;
		ptr[ii-is+1] = k;
	}
	err = lis_matrix_set_csr(ptr[ie-is],ptr,index,value,A); CHKERR(err);
	err = lis_matrix_assemble(A); CHKERR(err);

	err = lis_vector_duplicate(A,&u); CHKERR(err);
	err = lis_vector_duplicate(u,&b); CHKERR(err);
	err = lis_vector_duplicate(u,&x); CHKERR(err);

	err = lis_vector_set_all(1.0,u);
	lis_matvec(A,u,b);

	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_iterex(solver,&iter,&iter_double,&iter_quad);
	lis_solver_get_timeex(solver,&time,&itime,&ptime,&p_c_time,&p_i_time);
	lis_solver_get_residualnorm(solver,&resid);
	lis_solver_get_solver(solver,&nsol);
	lis_solver_get_solvername(nsol,solvername);
	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,time);
		printf("%s:   preconditioner     = %e sec.\n",solvername, ptime);
		printf("%s:     matrix creation  = %e sec.\n",solvername, p_c_time);
		printf("%s:   linear solver      = %e sec.\n",solvername, itime);
#ifdef _LONG__DOUBLE
		printf("%s: relative residual    = %Le\n\n",solvername,resid);
#else
		printf("%s: relative residual    = %e\n\n",solvername,resid);
#endif
	}

	
	lis_solver_destroy(solver);
	lis_matrix_destroy(A);
	lis_vector_destroy(b);
	lis_vector_destroy(x);
	lis_vector_destroy(u);

	lis_finalize();

	LIS_DEBUG_FUNC_OUT;
	return 0;
}
Example #8
0
LIS_INT main(LIS_INT argc, char* argv[])
{
  LIS_MATRIX A,A0;
  LIS_VECTOR b,x;
  LIS_SCALAR *value;
  LIS_INT nprocs,my_rank;
  int int_nprocs,int_my_rank;
  LIS_INT nthreads,maxthreads;
  LIS_INT gn,nnz,np;
  LIS_INT i,j,k,si,sj,sk,ii,jj,ctr;
  LIS_INT l,m,n,nn;
  LIS_INT is,ie;
  LIS_INT err,iter,matrix_type,storage,ss,se;
  LIS_INT *ptr,*index;
  double time,time2,nnzs,nnzap,nnzt;
  LIS_SCALAR val;
  double commtime,comptime,flops;

  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 l m n iter [matrix_type]\n", argv[0]);
	}
      CHKERR(1);
    }

  l  = atoi(argv[1]);
  m  = atoi(argv[2]);
  n  = atoi(argv[3]);
  iter = atoi(argv[4]);
  if (argv[5] == NULL) {
    storage = 0;
  }
  else {
    storage = atoi(argv[5]);
  }

  if( iter<=0 )
    {
#ifdef _LONG__LONG
      if( my_rank==0 ) printf("iter=%lld <= 0\n",iter);
#else
      if( my_rank==0 ) printf("iter=%d <= 0\n",iter);
#endif
      CHKERR(1);
    }
  if( l<=0 || m<=0 || n<=0 )
    {
#ifdef _LONG__LONG
      if( my_rank==0 ) printf("l=%lld <=0, m=%lld <=0 or n=%lld <=0\n",l,m,n);
#else
      if( my_rank==0 ) printf("l=%d <=0, m=%d <=0 or n=%d <=0\n",l,m,n);
#endif
      CHKERR(1);
    }
  if( storage<0 || storage>11 )
    {
#ifdef _LONG__LONG
      if( my_rank==0 ) printf("matrix_type=%lld < 0 or matrix_type=%lld > 11\n",storage,storage);
#else
      if( my_rank==0 ) printf("matrix_type=%d < 0 or matrix_type=%d > 11\n",storage,storage);
#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
  nthreads = omp_get_num_procs();
  maxthreads = omp_get_max_threads();
  if( my_rank==0 )
    {
#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 */
  nn = l*m*n;
  err = lis_matrix_create(LIS_COMM_WORLD,&A0);
  err = lis_matrix_set_size(A0,0,nn);
  CHKERR(err);

  ptr   = (LIS_INT *)malloc((A0->n+1)*sizeof(LIS_INT));
  if( ptr==NULL ) CHKERR(1);
  index = (LIS_INT *)malloc(27*A0->n*sizeof(LIS_INT));
  if( index==NULL ) CHKERR(1);
  value = (LIS_SCALAR *)malloc(27*A0->n*sizeof(LIS_SCALAR));
  if( value==NULL ) CHKERR(1);

  lis_matrix_get_range(A0,&is,&ie);
  ctr = 0;
  for(ii=is;ii<ie;ii++)
    {
      i = ii/(m*n);
      j = (ii - i*m*n)/n;
      k = ii - i*m*n - j*n;
      for(si=-1;si<=1;si++) {
	if( i+si>-1 && i+si<l ) {
	  for(sj=-1;sj<=1;sj++) {
	    if( j+sj>-1 && j+sj<m ) {
	      for(sk=-1;sk<=1;sk++) {
		if( k+sk>-1 && k+sk<n ) {
		  jj = ii + si*m*n + sj*n + sk; 
		  index[ctr] = jj; 
		  if( jj==ii ) { value[ctr++] = 26.0;}
		  else { value[ctr++] = -1.0;}
		}
	      }
	    }
	  }
	}
      }
      ptr[ii-is+1] = ctr;
    }
  ptr[0] = 0;
  err = lis_matrix_set_csr(ptr[ie-is],ptr,index,value,A0);
  CHKERR(err);
  err = lis_matrix_assemble(A0);
  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 ) 
    {
#ifdef _LONG__LONG
      printf("matrix size = %lld x %lld (%lld nonzero entries)\n",gn,gn,nnz);
      printf("number of iterations = %lld\n\n",iter);
#else
      printf("matrix size = %d x %d (%d nonzero entries)\n",gn,gn,nnz);
      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);
    }
  for(i=0;i<n;i++)
    {
      lis_sort_id(A0->ptr[i],A0->ptr[i+1]-1,A0->index,A0->value);
    }
		
  /* 
     MPI version of VBR is not implemented.
     DNS is also excluded to reduce memory usage.
  */

  if (storage==0) 
    {
      ss = 1;
      se = 11;
    }
  else
    {
      ss = storage;
      se = storage+1;
    }
	
  for (matrix_type=ss;matrix_type<se;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);
		    
      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);

  lis_finalize();

  LIS_DEBUG_FUNC_OUT;

  return 0;
}
Example #9
0
LIS_INT main(int argc, char* argv[])
{
  LIS_Comm comm;
  LIS_INT err;
  int nprocs,my_rank;
  LIS_INT nesol;
  LIS_MATRIX A,B;
  LIS_VECTOR x;
  LIS_SCALAR evalue0;
  LIS_ESOLVER esolver;
  LIS_REAL residual;
  LIS_INT iter;
  double time;
  double itime,ptime,p_c_time,p_i_time;
  char esolvername[128];

  LIS_DEBUG_FUNC_IN;
    
  lis_initialize(&argc, &argv);

  comm = LIS_COMM_WORLD;

#ifdef USE_MPI
  MPI_Comm_size(comm,&nprocs);
  MPI_Comm_rank(comm,&my_rank);
#else
  nprocs  = 1;
  my_rank = 0;
#endif
    
  if( argc < 5 )
    {
      lis_printf(comm,"Usage: %s matrix_a_filename matrix_b_filename evector_filename rhistory_filename [options]\n", argv[0]);
      CHKERR(1);
    }

  lis_printf(comm,"\n");
  lis_printf(comm,"number of processes = %d\n",nprocs);

#ifdef _OPENMP
  lis_printf(comm,"max number of threads = %d\n",omp_get_num_procs());
  lis_printf(comm,"number of threads = %d\n",omp_get_max_threads());
#endif
		
  /* create matrix and vectors */
  lis_matrix_create(comm,&A);  
  lis_matrix_create(comm,&B);
  lis_printf(comm,"\nmatrix A:\n");  
  lis_input_matrix(A,argv[1]);
  lis_printf(comm,"matrix B:\n");    
  lis_input_matrix(B,argv[2]);  
  lis_vector_duplicate(A,&x);
  lis_esolver_create(&esolver);
  lis_esolver_set_option("-e gii -eprint mem",esolver);
  err = lis_esolver_set_optionC(esolver);
  CHKERR(err);      

  err = lis_gesolve(A,B,x,&evalue0,esolver);
  CHKERR(err);
  lis_esolver_get_esolver(esolver,&nesol);
  lis_esolver_get_esolvername(nesol,esolvername);
  lis_esolver_get_residualnorm(esolver,&residual);
  lis_esolver_get_iter(esolver,&iter);
  lis_esolver_get_timeex(esolver,&time,&itime,&ptime,&p_c_time,&p_i_time);

  lis_printf(comm,"%s: mode number          = %d\n", esolvername, 0);
#ifdef _COMPLEX      
  lis_printf(comm,"%s: eigenvalue           = (%e, %e)\n", esolvername, (double)creal(evalue0), (double)cimag(evalue0));
#else
  lis_printf(comm,"%s: eigenvalue           = %e\n", esolvername, (double)evalue0);
#endif      
  lis_printf(comm,"%s: number of iterations = %D\n",esolvername, iter);
  lis_printf(comm,"%s: elapsed time         = %e sec.\n", esolvername, time);
  lis_printf(comm,"%s:   preconditioner     = %e sec.\n", esolvername, ptime);
  lis_printf(comm,"%s:     matrix creation  = %e sec.\n", esolvername, p_c_time);
  lis_printf(comm,"%s:   linear solver      = %e sec.\n", esolvername, itime);
  lis_printf(comm,"%s: relative residual    = %e\n\n",esolvername, (double)residual);

  /* write eigenvector */
  lis_output_vector(x,LIS_FMT_MM,argv[3]);

  /* write residual history */
  lis_esolver_output_rhistory(esolver,argv[4]);

  lis_esolver_destroy(esolver);
  lis_matrix_destroy(A);
  lis_matrix_destroy(B);  
  lis_vector_destroy(x);

  lis_finalize();

  LIS_DEBUG_FUNC_OUT;

  return 0;
}
Example #10
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,ii,j,jj,j0,j1,l,k,n,np,h,ih;
  LIS_INT		rn,rmin,rmax,rb;
  LIS_INT		is,ie,clsize,ci,*iw;
  LIS_INT		err,iter,matrix_type,s,ss,se;
  LIS_INT	       	*ptr,*index;
  double		mem,ra,rs,ri,ria,ca,time,time2,convtime,nnzs,nnzap,nnzt;
  LIS_SCALAR            val;
  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 < 3 )
    {
      if( my_rank==0 ) 
	{
	  printf("Usage: %s n iter [matrix_type]\n", argv[0]);
	}
      CHKERR(1);	  
    }
  
  n  = atoi(argv[1]);
  iter = atoi(argv[2]);
  if (argv[3] == NULL) {
    s = 0;
  }
  else {
    s = atoi(argv[3]);
  }

  if( n<=0 )
    {
#ifdef _LONGLONG
      if( my_rank==0 ) printf("n=%lld <=0\n",n);
#else
      if( my_rank==0 ) printf("n=%d <=0\n",n);
#endif
      CHKERR(1);	  
    }
  if( iter<=0 )
    {
#ifdef _LONGLONG
      if( my_rank==0 ) printf("iter=%lld <= 0\n",iter);
#else
      if( my_rank==0 ) printf("iter=%d <= 0\n",iter);
#endif
      CHKERR(1);
    }
  if( s<0 || s>11 )
    {
#ifdef _LONGLONG
      if( my_rank==0 ) printf("matrix_type=%lld < 0 or matrix_type=%lld > 11\n",s,s);
#else
      if( my_rank==0 ) printf("matrix_type=%d < 0 or matrix_type=%d > 11\n",s,s);
#endif
      CHKERR(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
  nthreads = omp_get_num_procs();
  maxthreads = omp_get_max_threads();
  if( my_rank==0 ) 
    {
#ifdef _LONGLONG
      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 */
  lis_matrix_create(LIS_COMM_WORLD,&A0);
  lis_matrix_set_size(A0,0,n);
  lis_matrix_get_size(A0,&n,&gn);
  lis_matrix_get_range(A0,&is,&ie);
  k = 0;
    for(i=is;i<ie;i++)
    {
      if( i>0   )  lis_matrix_set_value(LIS_INS_VALUE,i,i-1,-1.0,A0);
      if( i<gn-1 ) lis_matrix_set_value(LIS_INS_VALUE,i,i+1,-1.0,A0);
      lis_matrix_set_value(LIS_INS_VALUE,i,i,2.0,A0);
    }
  err = lis_matrix_assemble(A0);
  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 ) 
    {
#ifdef _LONGLONG
      printf("matrix size = %lld x %lld (%lld nonzero entries)\n",gn,gn,nnz);
      printf("iteration count = %lld\n\n",iter);
#else
      printf("matrix size = %d x %d (%d nonzero entries)\n",gn,gn,nnz);
      printf("iteration count = %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.
  */

  if (s==0) 
    {
      ss = 1;
      se = 11;
    }
  else
    {
      ss = s;
      se = s+1;
    }
	
  for (matrix_type=ss;matrix_type<se;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);
	  
      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;
	  MPI_Barrier(A->comm);
#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 _LONGLONG
	  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 _LONGLONG
	  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 _LONGLONG
	  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 _LONGLONG
	  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);

  lis_finalize();

  LIS_DEBUG_FUNC_OUT;

  return 0;
}
Example #11
0
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,&times,&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;
}
Example #12
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;
}
Example #13
0
int main ( int argc, char* argv[] )
{
	/* parse command line arguments */
	std::string anArg;
	std::string modelRoot;
	#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \
		defined(USE_MPI_GEMS) || defined(USE_MPI_KRC)
		int nb_ddc=0; //number of cores for DDC related processes
	#endif

	for( int i = 1; i < argc; i++ )
	{
		anArg = std::string( argv[i] );
		if( anArg == "--help" || anArg == "-h")
		{
			std::cout << "Usage: ogs [MODEL_ROOT] [OPTIONS]\n"
			          << "Where OPTIONS are:\n"
			          << "  -h [--help]               print this message and exit\n"
			          << "  -b [--build-info]         print build info and exit\n"
			          << "  --output-directory DIR    put output files into DIR\n"
			          << "  --version                 print ogs version and exit" << "\n";
			continue;
		}
		if( anArg == "--build-info" || anArg == "-b" )
		{
			std::cout << "ogs version: " << BuildInfo::OGS_VERSION << "\n"
			          << "ogs date: " << BuildInfo::OGS_DATE << "\n";
			std::cout << "git commit info: " << BuildInfo::GIT_COMMIT_INFO << "\n";
			std::cout << "build timestamp: " << BuildInfo::BUILD_TIMESTAMP << "\n";
			continue;
		}
		if( anArg == "--version" )
		{
			std::cout << BuildInfo::OGS_VERSION << "\n";
			continue;
		}
		if( anArg == "--model-root" || anArg == "-m" )
		{
			if (i+1 >= argc) {
				std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl;
				std::exit(EXIT_FAILURE);
			}
			modelRoot = std::string( argv[++i] );
			continue;
		}
		if (anArg == "--output-directory")
		{
			if (i+1 >= argc) {
				std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl;
				std::exit(EXIT_FAILURE);
			}
			std::string path = argv[++i];

			if (! path.empty()) defaultOutputPath = path;
			continue;
		}
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \
	defined(USE_MPI_GEMS) || defined(USE_MPI_KRC)
		std::string decompositions;
		if( anArg == "--domain-decomposition" || anArg == "-ddc" )
		{
			decompositions = std::string( argv[++i] );
			nb_ddc = atoi(decompositions.c_str());
			continue;
		}
#endif
		// anything left over must be the model root, unless already found
		if ( modelRoot == "" )
			modelRoot = std::string( argv[i] );
	} // end of parse argc loop

	if( argc > 1 && modelRoot == "" ) // non-interactive mode and no model given
		exit(0);             // e.g. just wanted the build info

	std::string solver_pkg_name = BuildInfo::SOLVER_PACKAGE_NAME;
	// No default linear solver package is in use.
	if(solver_pkg_name.find("Default") == std::string::npos)
	{
		std::cout << "\nWarning: " << solver_pkg_name
		<< " other than the OGS default one is in use." <<std::endl;
		std::cout << "         The solver setting may need to be adjusted for the solution accuracy!" << std::endl;
	}

	char* dateiname(NULL);
#ifdef SUPERCOMPUTER
// *********************************************************************
// buffered output ... important for performance on cray
// (unbuffered output is limited to 10 bytes per second)
// [email protected] 11.10.2007

	char buf[1024 * 1024];
	int bsize;

	bsize = 1024 * 1024; // question: what happens if buffer is full?
	                     // according to documentation the buffer is flushed when full.
	                     // If we have a lot of output, increasing buffer is usefull.
	if(bsize > 0)
//        bufstd = malloc(bsize);
		setvbuf(stdout, buf, _IOFBF, bsize);
	//**********************************************************************
#endif
/*---------- MPI Initialization ----------------------------------*/
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \
	defined(USE_MPI_GEMS) || defined(USE_MPI_KRC)
	printf("Before MPI_Init\n");
#if defined(USE_MPI_GEMS)
	int prov;
	MPI_Init_thread(&argc,&argv,MPI_THREAD_FUNNELED, &prov);
#else
	MPI_Init(&argc,&argv);
#endif
	MPI_Barrier (MPI_COMM_WORLD); // 12.09.2007 WW
	elapsed_time_mpi = -MPI_Wtime(); // 12.09.2007 WW
	bool splitcomm_flag;
	int np;
	MPI_Comm_size(MPI_COMM_WORLD, &np);
	splitcomm_flag = SplitMPI_Communicator::CreateCommunicator(MPI_COMM_WORLD, np, nb_ddc);
	time_ele_paral = 0.0;
#endif
/*---------- MPI Initialization ----------------------------------*/


#ifdef USE_PETSC
	int rank, r_size;
	PetscLogDouble v1,v2;
	char help[] = "OGS with PETSc \n";
	//PetscInitialize(argc, argv, help);
	PetscInitialize(&argc,&argv,(char *)0,help);
	//kg44 quick fix to compile PETSC with version PETSCV3.4
#ifdef USEPETSC34
       PetscTime(&v1);
#else
       PetscGetTime(&v1);
#endif
	MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
	MPI_Comm_size(PETSC_COMM_WORLD, &r_size);
	PetscSynchronizedPrintf(PETSC_COMM_WORLD, "===\nUse PETSc solver");
	PetscSynchronizedPrintf(PETSC_COMM_WORLD, "Number of CPUs: %d, rank: %d\n", r_size, rank);
#endif

/*---------- LIS solver -----------------------------------------*/
#ifdef LIS
	//Initialization of the lis solver.
	lis_initialize(&argc, &argv);
#endif
/*========================================================================*/
/* Kommunikation mit Betriebssystem */
	/* Timer fuer Gesamtzeit starten */
#ifdef TESTTIME
	TStartTimer(0);
#endif
	/* Intro ausgeben */
#if defined(USE_MPI) //WW
	if(myrank == 0)
#endif
#ifdef USE_PETSC
        if(rank == 0 )
#endif

	DisplayStartMsg();
	/* Speicherverwaltung initialisieren */
	if (!InitMemoryTest())
	{
		DisplayErrorMsg("Fehler: Speicherprotokoll kann nicht erstellt werden!");
		DisplayErrorMsg("        Programm vorzeitig beendet!");
		return 1; // LB changed from 0 to 1 because 0 is indicating success
	}
	if( argc == 1 )               // interactive mode

		dateiname = ReadString();
	else                         // non-interactive mode
	{
		if ( argc == 2 )     // a model root was supplied
		{
			dateiname = (char*) Malloc((int)strlen(argv[1]) + 1);
			dateiname = strcpy(dateiname,argv[1]);
		}
		else                // several args supplied
		if( modelRoot != "")
		{
			dateiname = (char*) Malloc( (int) modelRoot.size() + 1 );
			dateiname = strcpy( dateiname, modelRoot.c_str() );
		}
		DisplayMsgLn(dateiname);
	}
	//WW  DisplayMsgLn("");
	//WW  DisplayMsgLn("");
	// ----------23.02.2009. WW-----------------

	// LB Check if file exists
	std::string tmpFilename = dateiname;
	tmpFilename.append(".pcs");
	if(!IsFileExisting(tmpFilename))
	{
		std::cout << " Error: Cannot find file " << dateiname << "\n";
		return 1;
	}

	// If no option is given, output files are placed in the same directory as the input files
	if (defaultOutputPath.empty()) defaultOutputPath = pathDirname(std::string(dateiname));

	FileName = dateiname;
	size_t indexChWin, indexChLinux;
	indexChWin = indexChLinux = 0;
	indexChWin = FileName.find_last_of('\\');
	indexChLinux = FileName.find_last_of('/');
	//
	if(indexChWin != std::string::npos)
		FilePath = FileName.substr(0,indexChWin) + "\\";
	else if(indexChLinux != std::string::npos)
		FilePath = FileName.substr(0,indexChLinux) + "/";
	// ---------------------------WW
	Problem* aproblem = new Problem(dateiname);
#ifdef USE_PETSC
	aproblem->setRankandSize(rank, r_size);
#endif
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS)  || defined(USE_MPI_KRC)
	aproblem->setRankandSize(myrank, mysize);

	if (myrank != MPI_UNDEFINED)
	{
#endif
	aproblem->Euler_TimeDiscretize();
	delete aproblem;
	aproblem = NULL;
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS)  || defined(USE_MPI_KRC)
	  }

	//sending killing signals to ranks of group_IPQC, only when the group exists
	if (splitcomm_flag == true){
		int signal = -1, rank_IPQC, mysize_IPQC = np - nb_ddc;
		for (int i=0; i< mysize_IPQC; i++){
			rank_IPQC = mysize + i;
			MPI_Send(&signal, 1, MPI_INT, rank_IPQC, 0, MPI_COMM_WORLD);
		}
 	  }

#endif


	if(ClockTimeVec.size()>0)
		ClockTimeVec[0]->PrintTimes();  //CB time
	DestroyClockTime();
#ifdef TESTTIME
#if defined(USE_MPI)
     if(myrank == 0)
#endif
#if defined(USE_PETSC)
     if(rank == 0)
#endif
	std::cout << "Simulation time: " << TGetTimer(0) << "s" << "\n";
#endif
	/* Abspann ausgeben */
/*--------- MPI Finalize ------------------*/
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_KRC)
	elapsed_time_mpi += MPI_Wtime(); // 12.09.2007 WW
	std::cout << "\n *** Total CPU time of parallel modeling: " << elapsed_time_mpi <<
	"\n";                                                                          //WW
	// Count CPU time of post time loop WW
	MPI_Finalize();
#endif
/*--------- MPI Finalize ------------------*/
/*--------- LIS Finalize ------------------*/
#ifdef LIS
	lis_finalize();
#endif
/*--------- LIS Finalize ------------------*/

	free(dateiname);

#ifdef USE_PETSC
	//kg44 quick fix to compile PETSC with version PETSCV3.4
#ifdef USEPETSC34
       PetscTime(&v2);
#else
       PetscGetTime(&v2);
#endif


   PetscPrintf(PETSC_COMM_WORLD,"\t\n>>Total elapsed time by using PETSC:%f s\n",v2-v1);

   PetscFinalize();
#endif

	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;
}
Example #15
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;
}
Example #16
0
LIS_INT main(LIS_INT argc, char* argv[])
{
        LIS_SCALAR *a,*q,*r;
	LIS_INT m,n,nn;
	LIS_INT	i,j,ii,jj,nnz,qriter;
	double time,time0;
	LIS_REAL qrerr;	

 	LIS_DEBUG_FUNC_IN;

	lis_initialize(&argc, &argv);

	if( argc < 3 )
	{
	  printf("Usage: %s m n\n", argv[0]);
	  CHKERR(1);
	}

	m  = atoi(argv[1]);
	n  = atoi(argv[2]);
	if( m<=0 || n<=0 )
	{
	  printf("m=%d <=0 or n=%d <=0\n", m,n);
	  CHKERR(1);
	}
	
	printf("\n");

	/* create arrays */

	nn = m*n;

	a = (LIS_SCALAR *)malloc(nn*nn*sizeof(LIS_SCALAR));
	q = (LIS_SCALAR *)malloc(nn*nn*sizeof(LIS_SCALAR));
	r = (LIS_SCALAR *)malloc(nn*nn*sizeof(LIS_SCALAR));

	/* define two-dimensional Laplacian */

	lis_array_set_all(nn*nn,(LIS_SCALAR)0.0,a);

	nnz = 0;
	for(ii=0;ii<nn;ii++)
	  {
	    i = ii/m;
	    j = ii - i*m;
	    if( i>0 )   { jj = ii - m; a[ii + jj * nn] = -1.0; nnz++;} 
	    if( i<n-1 ) { jj = ii + m; a[ii + jj * nn] = -1.0; nnz++;}
	    if( j>0 )   { jj = ii - 1; a[ii + jj * nn] = -1.0; nnz++;}
	    if( j<m-1 ) { jj = ii + 1; a[ii + jj * nn] = -1.0; nnz++;}
	    jj = ii; a[ii + jj * nn] = 4.0; nnz++;
	  }

	printf("matrix size = %d x %d (%d nonzero entries)\n\n", nn,nn,nnz);

	/* solve eigenproblem */

	time0 = lis_wtime();
	lis_array_qr(nn,a,q,r,&qriter,&qrerr);
	time = lis_wtime() - time0;

	printf("QR    : number of iterations = %d\n", qriter);
	printf("QR    : elapsed time         = %e sec.\n", time);
	printf("QR    :   eigensolver        = %e sec.\n", time);
#ifdef _LONG__DOUBLE
	printf("QR    : 2-norm of A(2,1)     = %Le\n\n", qrerr);
#else
	printf("QR    : 2-norm of A(2,1)     = %e\n\n", qrerr);
#endif

	lis_finalize();

	LIS_DEBUG_FUNC_OUT;
	return 0;
}
Example #17
0
int main ( int argc, char* argv[] )
{
	/* parse command line arguments */
	std::string anArg;
	std::string modelRoot;
	for( int i = 1; i < argc; i++ )
	{
		anArg = std::string( argv[i] );
		if( anArg == "--help" || anArg == "-h")
		{
			std::cout << "Usage: ogs [MODEL_ROOT] [OPTIONS]\n"
			          << "Where OPTIONS are:\n"
			          << "  -h [--help]       print this message and exit\n"
			          << "  -b [--build-info] print build info and exit\n"
			          << "  --version         print ogs version and exit" << "\n";
			continue;
		}
		if( anArg == "--build-info" || anArg == "-b" )
		{
			std::cout << "ogs version: " << OGS_VERSION << "\n"
			          << "ogs date: " << OGS_DATE << "\n";
#ifdef CMAKE_CMD_ARGS
			std::cout << "cmake command line arguments: " << CMAKE_CMD_ARGS << "\n";
#endif // CMAKE_CMD_ARGS
#ifdef GIT_COMMIT_INFO
			std::cout << "git commit info: " << GIT_COMMIT_INFO << "\n";
#endif // GIT_COMMIT_INFO
#ifdef SVN_REVISION
			std::cout << "subversion info: " << SVN_REVISION << "\n";
#endif // SVN_REVISION
#ifdef BUILD_TIMESTAMP
			std::cout << "build timestamp: " << BUILD_TIMESTAMP << "\n";
#endif // BUILD_TIMESTAMP
			continue;
		}
		if( anArg == "--version" )
		{
			std::cout << OGS_VERSION << "\n";
			continue;
		}
		if( anArg == "--model-root" || anArg == "-m" )
		{
			modelRoot = std::string( argv[++i] );
			continue;
		}
		// anything left over must be the model root, unless already found
		if ( modelRoot == "" )
			modelRoot = std::string( argv[i] );
	} // end of parse argc loop

	if( argc > 1 && modelRoot == "" ) // non-interactive mode and no model given
		exit(0);             // e.g. just wanted the build info

	char* dateiname(NULL);
#ifdef SUPERCOMPUTER
// *********************************************************************
// buffered output ... important for performance on cray
// (unbuffered output is limited to 10 bytes per second)
// [email protected] 11.10.2007

	char buf[1024 * 1024];
	int bsize;

	bsize = 1024 * 1024; // question: what happens if buffer is full?
	                     // according to documentation the buffer is flushed when full.
	                     // If we have a lot of output, increasing buffer is usefull.
	if(bsize > 0)
//        bufstd = malloc(bsize);
		setvbuf(stdout, buf, _IOFBF, bsize);
	//**********************************************************************
#endif
/*---------- MPI Initialization ----------------------------------*/
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \
	defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) 
	printf("Before MPI_Init\n");
#if defined(USE_MPI_GEMS)
	int prov;
	MPI_Init_thread(&argc,&argv,MPI_THREAD_FUNNELED, &prov);
#else
	MPI_Init(&argc,&argv);
#endif
	MPI_Barrier (MPI_COMM_WORLD); // 12.09.2007 WW
	elapsed_time_mpi = -MPI_Wtime(); // 12.09.2007 WW
	MPI_Comm_size(MPI_COMM_WORLD,&mysize);
	MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
	std::cout << "After MPI_Init myrank = " << myrank << '\n';
	time_ele_paral = 0.0;
#endif
/*---------- MPI Initialization ----------------------------------*/


#ifdef USE_PETSC
	int rank, r_size;
	PetscLogDouble v1,v2;
	char help[] = "OGS with PETSc \n";
	//PetscInitialize(argc, argv, help);
	PetscInitialize(&argc,&argv,(char *)0,help);
	//kg44 quick fix to compile PETSC with version PETSCV3.4
#ifdef USEPETSC34
       PetscTime(&v1);
#else
       PetscGetTime(&v1);
#endif
	MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
	MPI_Comm_size(PETSC_COMM_WORLD, &r_size);
	PetscSynchronizedPrintf(PETSC_COMM_WORLD, "===\nUse PETSc solver");
	PetscSynchronizedPrintf(PETSC_COMM_WORLD, "Number of CPUs: %d, rank: %d\n", r_size, rank);
#endif




/*---------- LIS solver -----------------------------------------*/
#ifdef LIS
	//Initialization of the lis solver.
	lis_initialize(&argc, &argv);
#endif
/*========================================================================*/
/* Kommunikation mit Betriebssystem */
	/* Timer fuer Gesamtzeit starten */
#ifdef TESTTIME
	TStartTimer(0);
#endif
	/* Intro ausgeben */
#if defined(USE_MPI) //WW
	if(myrank == 0)
#endif
#ifdef USE_PETSC
        if(rank == 0 )
#endif

	DisplayStartMsg();
	/* Speicherverwaltung initialisieren */
	if (!InitMemoryTest())
	{
		DisplayErrorMsg("Fehler: Speicherprotokoll kann nicht erstellt werden!");
		DisplayErrorMsg("        Programm vorzeitig beendet!");
		return 1; // LB changed from 0 to 1 because 0 is indicating success
	}
	if( argc == 1 )               // interactive mode

		dateiname = ReadString();
	else                         // non-interactive mode
	{
		if ( argc == 2 )     // a model root was supplied
		{
			dateiname = (char*) Malloc((int)strlen(argv[1]) + 1);
			dateiname = strcpy(dateiname,argv[1]);
		}
		else                // several args supplied
		if( modelRoot != "")
		{
			dateiname = (char*) Malloc( (int) modelRoot.size() + 1 );
			dateiname = strcpy( dateiname, modelRoot.c_str() );
		}
		DisplayMsgLn(dateiname);
	}
	//WW  DisplayMsgLn("");
	//WW  DisplayMsgLn("");
	// ----------23.02.2009. WW-----------------

	// LB Check if file exists
	std::string tmpFilename = dateiname;
	tmpFilename.append(".pcs");
	if(!IsFileExisting(tmpFilename))
	{
		std::cout << " Error: Cannot find file " << dateiname << "\n";
		return 1;
	}

	FileName = dateiname;
	size_t indexChWin, indexChLinux;
	indexChWin = indexChLinux = 0;
	indexChWin = FileName.find_last_of('\\');
	indexChLinux = FileName.find_last_of('/');
	//
	if(indexChWin != std::string::npos)
		FilePath = FileName.substr(0,indexChWin) + "\\";
	else if(indexChLinux != std::string::npos)
		FilePath = FileName.substr(0,indexChLinux) + "/";
	// ---------------------------WW
	Problem* aproblem = new Problem(dateiname);
#ifdef USE_PETSC
	aproblem->setRankandSize(rank, r_size);
#endif
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS)  || defined(USE_MPI_KRC)
	aproblem->setRankandSize(myrank, mysize);
#endif
	
	aproblem->Euler_TimeDiscretize();
	delete aproblem;
	aproblem = NULL;
	if(ClockTimeVec.size()>0)
		ClockTimeVec[0]->PrintTimes();  //CB time
	DestroyClockTime();
#ifdef TESTTIME
#if defined(USE_MPI)
     if(myrank == 0)
#endif
#if defined(USE_PETSC) 
     if(rank == 0)
#endif
	std::cout << "Simulation time: " << TGetTimer(0) << "s" << "\n";
#endif
	/* Abspann ausgeben */
/*--------- MPI Finalize ------------------*/
#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_KRC)
	elapsed_time_mpi += MPI_Wtime(); // 12.09.2007 WW
	std::cout << "\n *** Total CPU time of parallel modeling: " << elapsed_time_mpi <<
	"\n";                                                                          //WW
	// Count CPU time of post time loop WW
	MPI_Finalize();
#endif
/*--------- MPI Finalize ------------------*/
/*--------- LIS Finalize ------------------*/
#ifdef LIS
	lis_finalize();
#endif
/*--------- LIS Finalize ------------------*/

	free(dateiname);

#ifdef USE_PETSC
	//kg44 quick fix to compile PETSC with version PETSCV3.4
#ifdef USEPETSC34
       PetscTime(&v2);
#else
       PetscGetTime(&v2);
#endif


   PetscPrintf(PETSC_COMM_WORLD,"\t\n>>Total elapsed time by using PETSC:%f s\n",v2-v1);

   PetscFinalize();
#endif

	return 0;
}
Example #18
0
LIS_INT main(LIS_INT argc, char* argv[])
{
  LIS_INT nprocs,my_rank;
  int int_nprocs,int_my_rank;
  LIS_INT nsol;
  LIS_MATRIX A,B;
  LIS_VECTOR x,y,z,w;
  LIS_SCALAR evalue0;
  LIS_ESOLVER esolver;
  LIS_REAL residual;
  LIS_INT iter;
  double time;
  double itime,ptime,p_c_time,p_i_time;
  char esolvername[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 < 6 )
    {
      if( my_rank==0 ) 
	{
	  printf("Usage: %s matrix_filename evalues_filename evectors_filename residuals_filename iters_filename [options]\n", argv[0]);
	}
      CHKERR(1);
    }

  if( my_rank==0 )
    {
      printf("\n");
      printf("number of processes = %d\n",nprocs);
    }

#ifdef _OPENMP
  if( my_rank==0 )
    {
      printf("max number of threads = %d\n",omp_get_num_procs());
      printf("number of threads = %d\n",omp_get_max_threads());
    }
#endif
		
  /* create matrix and vectors */
  lis_matrix_create(LIS_COMM_WORLD,&A);
  lis_input_matrix(A,argv[1]);
  lis_vector_duplicate(A,&x);
  lis_esolver_create(&esolver);
  lis_esolver_set_option("-e si -ss 1 -eprint mem",esolver);
  lis_esolver_set_optionC(esolver);
  lis_esolve(A, x, &evalue0, esolver);
  lis_esolver_get_esolver(esolver,&nsol);
  lis_esolver_get_esolvername(nsol,esolvername);
  lis_esolver_get_residualnorm(esolver, &residual);
  lis_esolver_get_iter(esolver, &iter);
  lis_esolver_get_timeex(esolver,&time,&itime,&ptime,&p_c_time,&p_i_time);
  if( my_rank==0 ) {
    printf("%s: mode number          = %d\n", esolvername, 0);
#ifdef _LONG__DOUBLE
    printf("%s: eigenvalue           = %Le\n", esolvername, evalue0);
#else
    printf("%s: eigenvalue           = %e\n", esolvername, evalue0);
#endif
#ifdef _LONG__LONG
    printf("%s: number of iterations = %lld\n",esolvername, iter);
#else
    printf("%s: number of iterations = %d\n",esolvername, iter);
#endif
    printf("%s: elapsed time         = %e sec.\n", esolvername, time);
    printf("%s:   preconditioner     = %e sec.\n", esolvername, ptime);
    printf("%s:     matrix creation  = %e sec.\n", esolvername, p_c_time);
    printf("%s:   linear solver      = %e sec.\n", esolvername, itime);
#ifdef _LONG__DOUBLE
    printf("%s: relative residual    = %Le\n\n",esolvername, residual);
#else
    printf("%s: relative residual    = %e\n\n",esolvername, residual);
#endif
  }

  lis_vector_create(LIS_COMM_WORLD,&y);
  lis_vector_create(LIS_COMM_WORLD,&z);
  lis_vector_create(LIS_COMM_WORLD,&w);
  lis_matrix_create(LIS_COMM_WORLD,&B);
  lis_esolver_get_evalues(esolver,y);
  lis_esolver_get_residualnorms(esolver,z);
  lis_esolver_get_iters(esolver,w);
  lis_esolver_get_evectors(esolver,B);

  /* write eigenvalues */
  lis_output_vector(y,LIS_FMT_MM,argv[2]);

  /* write eigenvectors */
  lis_output_matrix(B,LIS_FMT_MM,argv[3]);

  /* write residual norms */
  lis_output_vector(z,LIS_FMT_MM,argv[4]);

  /* write numbers of iterations */
  lis_output_vector(w,LIS_FMT_MM,argv[5]);

  lis_esolver_destroy(esolver);
  lis_matrix_destroy(A);
  lis_vector_destroy(x);
  lis_matrix_destroy(B);
  lis_vector_destroy(y);
  lis_vector_destroy(z);
  lis_vector_destroy(w);

  lis_finalize();

  LIS_DEBUG_FUNC_OUT;

  return 0;
}
Example #19
0
int main(int argc, char* argv[])
{
  int               err;
  int               nprocs,mtype,my_rank;
  int               nsol;
  LIS_MATRIX        A,A0;
  LIS_VECTOR        x;
  LIS_REAL          evalue0;
  LIS_SCALAR        shift, *tmpa;
  LIS_ESOLVER       esolver;
  LIS_SOLVER        solver;
  LIS_REAL          residual;
  int               iters;
  double            times;
  double	      itimes,ptimes,p_c_times,p_i_times;
  LIS_PRECON        precon;
  int		      *ptr,*index;
  LIS_SCALAR	      *value;
  int               nsolver;
  char	      esolvername[128];
  int               mode;

  LIS_DEBUG_FUNC_IN;
    
  lis_initialize(&argc, &argv);

#ifdef USE_MPI
  MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
  MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
#else
  nprocs  = 1;
  my_rank = 0;
#endif
    
  if( argc < 4 )
    {
      if( my_rank==0 ) printf("Usage: etest1 matrix_filename solution_filename residual_filename [options]\n");
      lis_finalize();
      exit(0);
    }

  if( my_rank==0 )
    {
      printf("\n");
      printf("number of processes = %d\n",nprocs);
    }

#ifdef _OPENMP
  if( my_rank==0 )
    {
      printf("max number of threads = %d\n",omp_get_num_procs());
      printf("number of threads = %d\n",omp_get_max_threads());
    }
#endif
		
  /* create matrix and vectors */
  lis_matrix_create(LIS_COMM_WORLD,&A);
  lis_input_matrix(A,argv[1]);
  lis_vector_duplicate(A,&x);
  lis_esolver_create(&esolver);
  lis_esolver_set_option("-eprint mem",esolver);
  lis_esolver_set_optionC(esolver);
  lis_esolve(A, x, &evalue0, esolver);
  lis_esolver_get_esolver(esolver,&nsol);
  lis_get_esolvername(nsol,esolvername);
  lis_esolver_get_residualnorm(esolver, &residual);
  lis_esolver_get_iters(esolver, &iters);
  lis_esolver_get_timeex(esolver,&times,&itimes,&ptimes,&p_c_times,&p_i_times);
  if( my_rank==0 ) {
    printf("%s: mode number              = %d\n", esolvername, esolver->options[LIS_EOPTIONS_MODE]);
    printf("%s: eigenvalue               = %e\n", esolvername, evalue0);
    printf("%s: number of iterations     = %d\n",esolvername, iters);
    printf("%s: elapsed time             = %e sec.\n", esolvername, times);
    printf("%s:   preconditioner         = %e sec.\n", esolvername, ptimes);
    printf("%s:     matrix creation      = %e sec.\n", esolvername, p_c_times);
    printf("%s:   linear solver          = %e sec.\n", esolvername, itimes);
    printf("%s: relative residual 2-norm = %e\n\n",esolvername, residual);
  }

  /* write solution */
  lis_output_vector(x,LIS_FMT_MM,argv[2]);

  /* write residual */
  lis_esolver_output_rhistory(esolver, argv[3]);

  lis_esolver_destroy(esolver);
  lis_matrix_destroy(A);
  lis_vector_destroy(x);

  lis_finalize();

  LIS_DEBUG_FUNC_OUT;

  return 0;
}
Example #20
0
File: test4.c Project: rwl/lis
LIS_INT main(LIS_INT argc, char* argv[])
{
    LIS_MATRIX A;
    LIS_VECTOR b,x,u;
    LIS_SOLVER solver;
    LIS_INT my_rank;
#ifdef USE_MPI
    int int_nprocs,int_my_rank;
#endif
    LIS_INT err,i,n,gn,is,ie,iter;
    n  = 12;
    lis_initialize(&argc, &argv);

#ifdef USE_MPI
    MPI_Comm_size(MPI_COMM_WORLD,&int_nprocs);
    MPI_Comm_rank(MPI_COMM_WORLD,&int_my_rank);
    my_rank = int_my_rank;
#else
    my_rank = 0;
#endif

    lis_matrix_create(LIS_COMM_WORLD,&A); 
    err = lis_matrix_set_size(A,0,n);
    CHKERR(err);
    lis_matrix_get_size(A,&n,&gn);
    lis_matrix_get_range(A,&is,&ie);
    for(i=is;i<ie;i++)
    {
        if( i>0   )  lis_matrix_set_value(LIS_INS_VALUE,i,i-1,-1.0,A);
        if( i<gn-1 ) lis_matrix_set_value(LIS_INS_VALUE,i,i+1,-1.0,A);
        lis_matrix_set_value(LIS_INS_VALUE,i,i,2.0,A);
    }
    lis_matrix_set_type(A,LIS_MATRIX_CSR);
    lis_matrix_assemble(A);

    lis_vector_duplicate(A,&u);
    lis_vector_duplicate(A,&b);
    lis_vector_duplicate(A,&x);
    lis_vector_set_all(1.0,u);
    lis_matvec(A,u,b);
    lis_solver_create(&solver);
    lis_solver_set_option("-print mem",solver);
    lis_solver_set_optionC(solver);
    lis_solve(A,b,x,solver);
    lis_solver_get_iter(solver,&iter);
    if (my_rank==0)
      {
#ifdef _LONG__LONG
	printf("number of iterations = %lld\n",iter);
#else
	printf("number of iterations = %d\n",iter);
#endif
	printf("\n");
      }
    lis_vector_print(x);

    lis_matrix_destroy(A);
    lis_vector_destroy(b);
    lis_vector_destroy(x);
    lis_vector_destroy(u);
    lis_solver_destroy(solver);
    lis_finalize();
    return 0;
}