Replaced exit() with OPM_THROW. Replaced primitive pointer with unique_ptr.

This commit is contained in:
T.D. (Tongdong) Qiu 2019-12-16 10:05:12 +01:00
parent 13e524dba2
commit 293bd5816f
3 changed files with 7 additions and 22 deletions

View File

@ -225,7 +225,7 @@ protected:
static const int numEq = Indices::numEq; static const int numEq = Indices::numEq;
#if HAVE_CUDA #if HAVE_CUDA
BdaBridge *bdaBridge; std::unique_ptr<BdaBridge> bdaBridge;
#endif #endif
public: public:
@ -252,27 +252,19 @@ protected:
const bool matrix_add_well_contributions = EWOMS_GET_PARAM(TypeTag, bool, MatrixAddWellContributions); const bool matrix_add_well_contributions = EWOMS_GET_PARAM(TypeTag, bool, MatrixAddWellContributions);
const int linear_solver_verbosity = parameters_.linear_solver_verbosity_; const int linear_solver_verbosity = parameters_.linear_solver_verbosity_;
if(use_gpu && !matrix_add_well_contributions){ if(use_gpu && !matrix_add_well_contributions){
std::cerr << "Error cannot use GPU solver if command line parameter --matrix-add-well-contributions is false, because the GPU solver performs a standard bicgstab" << std::endl; OPM_THROW(std::logic_error,"Error cannot use GPU solver if command line parameter --matrix-add-well-contributions is false, because the GPU solver performs a standard bicgstab");
exit(1);
} }
bdaBridge = new BdaBridge(use_gpu, linear_solver_verbosity, maxit, tolerance); bdaBridge.reset(new BdaBridge(use_gpu, linear_solver_verbosity, maxit, tolerance));
#else #else
const bool use_gpu = EWOMS_GET_PARAM(TypeTag, bool, UseGpu); const bool use_gpu = EWOMS_GET_PARAM(TypeTag, bool, UseGpu);
if(use_gpu){ if(use_gpu){
std::cerr << "Error cannot use GPU solver since CUDA was not found during compilation" << std::endl; OPM_THROW(std::logic_error,"Error cannot use GPU solver since CUDA was not found during compilation");
exit(1);
} }
#endif #endif
extractParallelGridInformationToISTL(simulator_.vanguard().grid(), parallelInformation_); extractParallelGridInformationToISTL(simulator_.vanguard().grid(), parallelInformation_);
detail::findOverlapRowsAndColumns(simulator_.vanguard().grid(),overlapRowAndColumns_); detail::findOverlapRowsAndColumns(simulator_.vanguard().grid(),overlapRowAndColumns_);
} }
~ISTLSolverEbos(){
#if HAVE_CUDA
delete bdaBridge;
#endif
}
// nothing to clean here // nothing to clean here
void eraseMatrix() { void eraseMatrix() {
matrix_for_preconditioner_.reset(); matrix_for_preconditioner_.reset();

View File

@ -37,18 +37,11 @@ namespace Opm
BdaBridge::BdaBridge(bool use_gpu_, int linear_solver_verbosity OPM_UNUSED, int maxit OPM_UNUSED, double tolerance OPM_UNUSED) : use_gpu(use_gpu_) { BdaBridge::BdaBridge(bool use_gpu_, int linear_solver_verbosity OPM_UNUSED, int maxit OPM_UNUSED, double tolerance OPM_UNUSED) : use_gpu(use_gpu_) {
#if HAVE_CUDA #if HAVE_CUDA
if(use_gpu){ if(use_gpu){
backend = new cusparseSolverBackend(linear_solver_verbosity, maxit, tolerance); backend.reset(new cusparseSolverBackend(linear_solver_verbosity, maxit, tolerance));
} }
#endif #endif
} }
BdaBridge::~BdaBridge(){
#if HAVE_CUDA
if(use_gpu){
delete backend;
}
#endif
}
#if HAVE_CUDA #if HAVE_CUDA
template <class BridgeMatrix> template <class BridgeMatrix>

View File

@ -40,7 +40,7 @@ class BdaBridge
{ {
private: private:
#if HAVE_CUDA #if HAVE_CUDA
cusparseSolverBackend *backend; std::unique_ptr<cusparseSolverBackend> backend;
#endif #endif
bool use_gpu; bool use_gpu;