From: Daniel Arndt Date: Sun, 2 Jul 2023 16:08:37 +0000 (-0400) Subject: Allow running step-64 without CUDA X-Git-Tag: v9.5.0~4^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15595%2Fhead;p=dealii.git Allow running step-64 without CUDA --- diff --git a/examples/step-64/CMakeLists.txt b/examples/step-64/CMakeLists.txt index 88f6e90857..90e20e4314 100644 --- a/examples/step-64/CMakeLists.txt +++ b/examples/step-64/CMakeLists.txt @@ -37,16 +37,14 @@ endif() # # Are all dependencies fulfilled? # -if(NOT DEAL_II_WITH_MPI OR NOT DEAL_II_WITH_P4EST OR NOT DEAL_II_WITH_CUDA) # keep in one line +if(NOT DEAL_II_WITH_MPI OR NOT DEAL_II_WITH_P4EST) # keep in one line message(FATAL_ERROR " Error! This tutorial requires a deal.II library that was configured with the following options: DEAL_II_WITH_MPI = ON DEAL_II_WITH_P4EST = ON - DEAL_II_WITH_CUDA = ON However, the deal.II library found at ${DEAL_II_PATH} was configured with these options: DEAL_II_WITH_MPI = ${DEAL_II_WITH_MPI} DEAL_II_WITH_P4EST = ${DEAL_II_WITH_P4EST} - DEAL_II_WITH_CUDA = ${DEAL_II_WITH_CUDA} This conflicts with the requirements." ) endif() diff --git a/examples/step-64/step-64.cc b/examples/step-64/step-64.cc index c14134bb9f..dccfe9f9a6 100644 --- a/examples/step-64/step-64.cc +++ b/examples/step-64/step-64.cc @@ -131,7 +131,9 @@ namespace Step64 const typename CUDAWrappers::MatrixFree::Data *gpu_data, double * coef, int cell) - : coef(coef) + : gpu_data(gpu_data) + , coef(coef) + , cell(cell) {} DEAL_II_HOST_DEVICE void operator()( @@ -244,16 +246,17 @@ namespace Step64 const AffineConstraints &constraints); void - vmult(LinearAlgebra::distributed::Vector &dst, - const LinearAlgebra::distributed::Vector + vmult(LinearAlgebra::distributed::Vector &dst, + const LinearAlgebra::distributed::Vector &src) const; void initialize_dof_vector( - LinearAlgebra::distributed::Vector &vec) const; + LinearAlgebra::distributed::Vector &vec) + const; private: - CUDAWrappers::MatrixFree mf_data; - LinearAlgebra::CUDAWrappers::Vector coef; + CUDAWrappers::MatrixFree mf_data; + LinearAlgebra::distributed::Vector coef; }; @@ -307,8 +310,8 @@ namespace Step64 // destination vector afterwards. template void HelmholtzOperator::vmult( - LinearAlgebra::distributed::Vector & dst, - const LinearAlgebra::distributed::Vector &src) + LinearAlgebra::distributed::Vector & dst, + const LinearAlgebra::distributed::Vector &src) const { dst = 0.; @@ -322,7 +325,7 @@ namespace Step64 template void HelmholtzOperator::initialize_dof_vector( - LinearAlgebra::distributed::Vector &vec) const + LinearAlgebra::distributed::Vector &vec) const { mf_data.initialize_dof_vector(vec); } @@ -379,8 +382,9 @@ namespace Step64 // can view and display the solution as usual. LinearAlgebra::distributed::Vector ghost_solution_host; - LinearAlgebra::distributed::Vector solution_dev; - LinearAlgebra::distributed::Vector + LinearAlgebra::distributed::Vector + solution_dev; + LinearAlgebra::distributed::Vector system_rhs_dev; ConditionalOStream pcout; @@ -517,8 +521,8 @@ namespace Step64 SolverControl solver_control(system_rhs_dev.size(), 1e-12 * system_rhs_dev.l2_norm()); - SolverCG> cg( - solver_control); + SolverCG> + cg(solver_control); cg.solve(*system_matrix_dev, solution_dev, system_rhs_dev, preconditioner); pcout << " Solved in " << solver_control.last_step() << " iterations." @@ -633,15 +637,6 @@ int main(int argc, char *argv[]) Utilities::MPI::MPI_InitFinalize mpi_init(argc, argv, 1); - int n_devices = 0; - cudaError_t cuda_error_code = cudaGetDeviceCount(&n_devices); - AssertCuda(cuda_error_code); - const unsigned int my_mpi_id = - Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); - const int device_id = my_mpi_id % n_devices; - cuda_error_code = cudaSetDevice(device_id); - AssertCuda(cuda_error_code); - HelmholtzProblem<3, 3> helmholtz_problem; helmholtz_problem.run(); }