From 4ddf12c647d5fbce64a6b555099e4e8c8be3cdcb Mon Sep 17 00:00:00 2001 From: Lance Bullerwell Date: Thu, 6 Jul 2023 09:46:31 -0400 Subject: [PATCH] removes single-variate example for semi-structured solver and addresses comments --- cajita/src/Cajita_Hypre.hpp | 4 +- .../CMakeLists.txt | 15 -- .../hypre_semi_structured_solver_example.cpp | 189 ------------------ ...e_semi_structured_solver_multi_example.cpp | 2 +- .../hypre_structured_solver_example.cpp | 1 - example/cajita_tutorial/CMakeLists.txt | 1 - 6 files changed, 3 insertions(+), 209 deletions(-) delete mode 100644 example/cajita_tutorial/11_semi_structured_solver_hypre/CMakeLists.txt delete mode 100644 example/cajita_tutorial/11_semi_structured_solver_hypre/hypre_semi_structured_solver_example.cpp diff --git a/cajita/src/Cajita_Hypre.hpp b/cajita/src/Cajita_Hypre.hpp index 7405f3f74..d54b467a3 100644 --- a/cajita/src/Cajita_Hypre.hpp +++ b/cajita/src/Cajita_Hypre.hpp @@ -10,8 +10,8 @@ ****************************************************************************/ /*! - \file Cajita_HypreStructuredSolver.hpp - \brief HYPRE structured solver interface + \file Cajita_Hypre.hpp + \brief HYPRE memory space handling */ #ifndef CAJITA_HYPRE_HPP #define CAJITA_HYPRE_HPP diff --git a/example/cajita_tutorial/11_semi_structured_solver_hypre/CMakeLists.txt b/example/cajita_tutorial/11_semi_structured_solver_hypre/CMakeLists.txt deleted file mode 100644 index 706bf5d7c..000000000 --- a/example/cajita_tutorial/11_semi_structured_solver_hypre/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -############################################################################ -# Copyright (c) 2018-2022 by the Cabana authors # -# All rights reserved. # -# # -# This file is part of the Cabana library. Cabana is distributed under a # -# BSD 3-clause license. For the licensing terms see the LICENSE file in # -# the top-level directory. # -# # -# SPDX-License-Identifier: BSD-3-Clause # -############################################################################ - -add_executable(HypreSemiStructuredSolver hypre_semi_structured_solver_example.cpp) -target_link_libraries(HypreSemiStructuredSolver Cajita) -add_test(NAME Cajita_tutorial_11_hypre_SS COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS}) -set_tests_properties(Cajita_tutorial_11_hypre_SS PROPERTIES PROCESSORS ${MPIEXEC_MAX_NUMPROCS}) diff --git a/example/cajita_tutorial/11_semi_structured_solver_hypre/hypre_semi_structured_solver_example.cpp b/example/cajita_tutorial/11_semi_structured_solver_hypre/hypre_semi_structured_solver_example.cpp deleted file mode 100644 index 1b0a61fbd..000000000 --- a/example/cajita_tutorial/11_semi_structured_solver_hypre/hypre_semi_structured_solver_example.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2018-2022 by the Cabana authors * - * All rights reserved. * - * * - * This file is part of the Cabana library. Cabana is distributed under a * - * BSD 3-clause license. For the licensing terms see the LICENSE file in * - * the top-level directory. * - * * - * SPDX-License-Identifier: BSD-3-Clause * - ****************************************************************************/ - -#include - -#include - -#include - -#include -#include - -//---------------------------------------------------------------------------// -// HYPRE Structured Solver Example -//---------------------------------------------------------------------------// -void hypreSemiStructuredSolverExample() -{ - /* - In this example we will demonstrate building a HYPRE sem-structured - solver that solves a Poisson equation with designated solution tolerance, - - Laplacian( lhs ) = rhs, - - This is discretized at {i,j,k} - - Laplacian( lhs )_{i,j,k} = rhs_{i,j,k}, - - which includes 7 stencils at current {i,j,k} - - { 0, 0, 0 }, { -1, 0, 0 }, { 1, 0, 0 }, { 0, -1, 0 }, - { 0, 1, 0 }, { 0, 0, -1 }, { 0, 0, 1 } - - You can try one of the following solver type and preconditioner type - - solver type : PCG, GMRES, BiCGSTAB - preconditioner type : none, Diagonal, Jacobi - */ - - std::cout << "Cajita HYPRE Semi-Structured Solver Example\n" << std::endl; - - /* - As with all Cajita examples, we start by defining everything from the - global mesh to the local grid. - */ - using MemorySpace = Kokkos::HostSpace; - using ExecutionSpace = Kokkos::DefaultHostExecutionSpace; - - // Create the global grid. - double cell_size = 0.25; - std::array is_dim_periodic = { false, false, false }; - std::array global_low_corner = { -1.0, -2.0, -1.0 }; - std::array global_high_corner = { 1.0, 1.0, 0.5 }; - auto global_mesh = Cajita::createUniformGlobalMesh( - global_low_corner, global_high_corner, cell_size ); - - // Create the global grid. - Cajita::DimBlockPartitioner<3> partitioner; - auto global_grid = Cajita::createGlobalGrid( MPI_COMM_WORLD, global_mesh, - is_dim_periodic, partitioner ); - - // Create a local grid. - auto local_mesh = createLocalGrid( global_grid, 1 ); - auto owned_space = local_mesh->indexSpace( Cajita::Own(), Cajita::Cell(), - Cajita::Local() ); - - /************************************************************************/ - - // Create the RHS. - auto vector_layout = createArrayLayout( local_mesh, 1, Cajita::Cell() ); - auto rhs = Cajita::createArray( "rhs", vector_layout ); - Cajita::ArrayOp::assign( *rhs, 1.0, Cajita::Own() ); - - // Create the LHS. - auto lhs = Cajita::createArray( "lhs", vector_layout ); - Cajita::ArrayOp::assign( *lhs, 0.0, Cajita::Own() ); - - // Create a solver. - auto solver = Cajita::createHypreSemiStructuredSolver( - "PCG", *vector_layout, false, 1 ); - - // Create a 7-point 3d laplacian stencil. - std::vector> stencil = { - { 0, 0, 0 }, { -1, 0, 0 }, { 1, 0, 0 }, { 0, -1, 0 }, - { 0, 1, 0 }, { 0, 0, -1 }, { 0, 0, 1 } }; - solver->createMatrixStencil( 3, 0, 1, { 7 } ); - solver->setMatrixStencil( stencil, 0, 0 ); - - solver->setSolverGraph( 1 ); - - // Create the matrix entries. The stencil is defined over cells. - auto matrix_entry_layout = - createArrayLayout( local_mesh, 7, Cajita::Cell() ); - auto matrix_entries = Cajita::createArray( - "matrix_entries", matrix_entry_layout ); - auto entry_view = matrix_entries->view(); - Kokkos::parallel_for( - "fill_matrix_entries", - createExecutionPolicy( owned_space, ExecutionSpace() ), - KOKKOS_LAMBDA( const int i, const int j, const int k ) { - entry_view( i, j, k, 0 ) = 6.0; - entry_view( i, j, k, 1 ) = -1.0; - entry_view( i, j, k, 2 ) = -1.0; - entry_view( i, j, k, 3 ) = -1.0; - entry_view( i, j, k, 4 ) = -1.0; - entry_view( i, j, k, 5 ) = -1.0; - entry_view( i, j, k, 6 ) = -1.0; - } ); - - solver->initializeHypreMatrix(); - - solver->setMatrixValues( *matrix_entries, 0, 0 ); - - // The desired tolerance must be set for each solve. - solver->setTolerance( 1.0e-9 ); - - // Set the maximum iterations. - solver->setMaxIter( 2000 ); - - /* - The print level defines the information output from HYPRE during the solve - */ - solver->setPrintLevel( 2 ); - - /* - Create a preconditioner - in this case we use Diagonal - */ - std::string precond_type = "Jacobi"; - auto preconditioner = - Cajita::createHypreSemiStructuredSolver( - precond_type, *vector_layout, true, 1 ); - solver->setPreconditioner( preconditioner ); - - // Setup the problem - this is necessary before solving. - solver->setup(); - - // Now solve the problem. - solver->solve( *rhs, *lhs, 1 ); - - /* - Setup the problem again. We would need to do this if we changed the matrix - entries, but in this case we just leave it unchanged. - */ - solver->setup(); - // Reset to the same initial condition and solve the problem again. - Cajita::ArrayOp::assign( *rhs, 2.0, Cajita::Own() ); - Cajita::ArrayOp::assign( *lhs, 0.0, Cajita::Own() ); - solver->solve( *rhs, *lhs, 1 ); -} - -//---------------------------------------------------------------------------// -// Main. -//---------------------------------------------------------------------------// -int main( int argc, char* argv[] ) -{ - // MPI only needed to create the grid/mesh. Not intended to be run with - // multiple ranks. - MPI_Init( &argc, &argv ); - { - Kokkos::ScopeGuard scope_guard( argc, argv ); - - /* - The hypre solver capabilities used by Cabana must be initialized and - finalized. HYPRE_Init() initializes hypre. A call to HYPRE_Init() must be - included before any hypre calls occur - */ - HYPRE_Init(); - - hypreSemiStructuredSolverExample(); - - /* - The hypre solver capabilities used by Cabana must be initialized and - finalized. HYPRE_Finalize() finalizes hypre. A call to HYPRE_Finalize() - should not occur before all calls to hypre capabilites are finished. - */ - HYPRE_Finalize(); - } - MPI_Finalize(); - - return 0; -} -//---------------------------------------------------------------------------// diff --git a/example/cajita_tutorial/11_semi_structured_solver_multi_variate/hypre_semi_structured_solver_multi_example.cpp b/example/cajita_tutorial/11_semi_structured_solver_multi_variate/hypre_semi_structured_solver_multi_example.cpp index ccde69e38..8a25547e5 100644 --- a/example/cajita_tutorial/11_semi_structured_solver_multi_variate/hypre_semi_structured_solver_multi_example.cpp +++ b/example/cajita_tutorial/11_semi_structured_solver_multi_variate/hypre_semi_structured_solver_multi_example.cpp @@ -25,7 +25,7 @@ void hypreSemiStructuredSolverExample() { /* In this example we will demonstrate building a HYPRE semi-structured - solver that solves 3, indpenedent, Poisson equations with designated + solver that solves 3, independent, Poisson equations with designated solution tolerance, Laplacian( lhs ) = rhs, diff --git a/example/cajita_tutorial/11_structured_solver_hypre/hypre_structured_solver_example.cpp b/example/cajita_tutorial/11_structured_solver_hypre/hypre_structured_solver_example.cpp index b703a08cd..54c80dfe9 100644 --- a/example/cajita_tutorial/11_structured_solver_hypre/hypre_structured_solver_example.cpp +++ b/example/cajita_tutorial/11_structured_solver_hypre/hypre_structured_solver_example.cpp @@ -131,7 +131,6 @@ void hypreStructuredSolverExample() options are shown above). */ std::string precond_type = "Jacobi"; - // std::string precond_type = "Diagonal"; auto preconditioner = Cajita::createHypreStructuredSolver( precond_type, *vector_layout, true ); diff --git a/example/cajita_tutorial/CMakeLists.txt b/example/cajita_tutorial/CMakeLists.txt index b58870766..b96346390 100644 --- a/example/cajita_tutorial/CMakeLists.txt +++ b/example/cajita_tutorial/CMakeLists.txt @@ -24,7 +24,6 @@ endif() add_subdirectory(11_structured_solver) if(Cabana_ENABLE_HYPRE AND (NOT Kokkos_ENABLE_CUDA AND NOT Kokkos_ENABLE_HIP AND NOT Kokkos_ENABLE_SYCL)) add_subdirectory(11_structured_solver_hypre) - add_subdirectory(11_semi_structured_solver_hypre) add_subdirectory(11_semi_structured_solver_multi_variate) endif() add_subdirectory(12_halo)