Updated HAVE_XX guards. Replaced string == compare with .compare()

This commit is contained in:
T.D. (Tongdong) Qiu 2020-06-23 18:19:33 +02:00
parent 39df7c9381
commit b9e4bd3a95
2 changed files with 16 additions and 9 deletions

View File

@ -49,7 +49,7 @@
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
#if HAVE_CUDA
#if HAVE_CUDA + HAVE_OPENCL
#include <opm/simulators/linalg/bda/BdaBridge.hpp>
#endif
@ -278,7 +278,7 @@ protected:
enum { pressureVarIndex = Indices::pressureSwitchIdx };
static const int numEq = Indices::numEq;
#if HAVE_CUDA
#if HAVE_CUDA + HAVE_OPENCL
std::unique_ptr<BdaBridge> bdaBridge;
#endif
@ -316,9 +316,9 @@ protected:
prm_ = setupPropertyTree<TypeTag>(parameters_);
}
const auto& gridForConn = simulator_.vanguard().grid();
#if HAVE_CUDA
#if HAVE_CUDA + HAVE_OPENCL
std::string gpu_mode = EWOMS_GET_PARAM(TypeTag, std::string, GpuMode);
if (gridForConn.comm().size() > 1 && "none" != gpu_mode) {
if (gridForConn.comm().size() > 1 && gpu_mode.compare("none") != 0) {
OpmLog::warning("Warning cannot use GPU with MPI, GPU is disabled");
gpu_mode = "none";
}
@ -328,7 +328,7 @@ protected:
bdaBridge.reset(new BdaBridge(gpu_mode, linear_solver_verbosity, maxit, tolerance));
#else
const bool gpu_mode = EWOMS_GET_PARAM(TypeTag, bool, GpuMode);
if ("none" != gpu_mode) {
if (gpu_mode.compare("none") != 0) {
OPM_THROW(std::logic_error,"Error cannot use GPU solver since CUDA was not found during compilation");
}
#endif
@ -622,7 +622,7 @@ protected:
#endif
{
// tries to solve linear system
#if HAVE_CUDA
#if HAVE_CUDA + HAVE_OPENCL
bool use_gpu = bdaBridge->getUseGpu();
if (use_gpu) {
WellContributions wellContribs;

View File

@ -41,17 +41,24 @@ namespace Opm
BdaBridge::BdaBridge(std::string gpu_mode_, int linear_solver_verbosity, int maxit, double tolerance)
: gpu_mode(gpu_mode_)
{
if (gpu_mode == "cusparse") {
std::cout << "mode: " << gpu_mode_ << std::endl;
if (gpu_mode.compare("cusparse") == 0) {
#if HAVE_CUDA
use_gpu = true;
backend.reset(new bda::cusparseSolverBackend(linear_solver_verbosity, maxit, tolerance));
} else if (gpu_mode == "opencl") {
#else
OPM_THROW(std::logic_error, "Error cusparseSolver was chosen, but CUDA was not found by CMake");
#endif
} else if (gpu_mode.compare("opencl") == 0) {
#if HAVE_OPENCL
use_gpu = true;
backend.reset(new bda::openclSolverBackend(linear_solver_verbosity, maxit, tolerance));
#else
OPM_THROW(std::logic_error, "Error openclSolver was chosen, but OpenCL was not found by CMake");
#endif
} else if (gpu_mode != "none") {
} else if (gpu_mode.compare("none") == 0) {
use_gpu = false;
} else {
OPM_THROW(std::logic_error, "Error unknown value for parameter 'GpuMode', should be passed like '--gpu-mode=[none|cusparse|opencl]");
}
}