Reuse amgcl parameters

This commit is contained in:
Tong Dong Qiu 2021-06-08 12:11:42 +02:00
parent 47e2899ba8
commit a23d881817
2 changed files with 14 additions and 15 deletions

View File

@ -51,7 +51,7 @@ void amgclSolverBackend<block_size>::initialize(int N_, int nnz_, int dim, doubl
std::ostringstream out;
out << "Initializing amgclSolverBackend, matrix size: " << N << " blocks, nnzb: " << nnzb << "\n";
out << "Maxit: " << maxit << std::scientific << ", tolerance: " << tolerance << "\n";
out << "PlatformID: " << platformID << ", deviceID: " << deviceID << "\n";
out << "DeviceID: " << deviceID << "\n";
OpmLog::info(out.str());
out.str("");
out.clear();
@ -63,14 +63,22 @@ void amgclSolverBackend<block_size>::initialize(int N_, int nnz_, int dim, doubl
x.resize(N);
#if AMGCL_CUDA
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, deviceID);
std::cout << prop.name << std::endl;
cusparseCreate(&bprm.cusparse_handle);
#endif
// set amgcl parameters
prm.precond.damping = 0.9;
prm.solver.maxiter = maxit;
prm.solver.tol = tolerance;
prm.solver.verbose = (verbosity >= 2);
initialized = true;
} // end initialize()
template <unsigned int block_size>
void amgclSolverBackend<block_size>::convert_sparsity_pattern(int *rows, int *cols) {
Timer t;
@ -99,6 +107,7 @@ void amgclSolverBackend<block_size>::convert_sparsity_pattern(int *rows, int *co
}
} // end convert_sparsity_pattern()
template <unsigned int block_size>
void amgclSolverBackend<block_size>::convert_data(double *vals, int *rows) {
Timer t;
@ -136,23 +145,12 @@ void amgclSolverBackend<block_size>::solve_system(double *b, WellContributions &
// create matrix object
auto A = std::tie(N, A_rows, A_cols, A_vals);
// set parameters
typename Solver::params prm;
prm.precond.damping = 0.9;
prm.solver.maxiter = maxit;
prm.solver.tol = tolerance;
prm.solver.verbose = (verbosity >= 2);
// create solver
// create solver and construct preconditioner
// don't reuse this unless the preconditioner can be reused
Solver solve(A, prm, bprm);
// print info (once)
std::call_once(print_info, [&](){
#if AMGCL_CUDA
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, deviceID);
std::cout << prop.name << std::endl;
#endif
// print solver structure
std::cout << solve << std::endl;
});

View File

@ -89,6 +89,7 @@ private:
std::vector<double> x;
std::once_flag print_info;
typename Solver::params prm;
typename Backend::params bprm; // amgcl backend parameters, only used for cusparseHandle
/// Initialize GPU and allocate memory