Skip to content

Commit 4787aa3

Browse files
authored
Merge pull request #4126 from lindsayad/revert-revert-hypre-memory-location
Revert the revert of setting the hypre memory location
2 parents 1fba560 + 1cf082e commit 4787aa3

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/solvers/petsc_linear_solver.C

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#include "libmesh/enum_solver_type.h"
3737
#include "libmesh/enum_convergence_flags.h"
3838

39+
#if defined(LIBMESH_HAVE_PETSC_HYPRE) && PETSC_VERSION_LESS_THAN(3, 23, 0) && \
40+
!PETSC_VERSION_LESS_THAN(3, 12, 0) && defined(PETSC_HAVE_HYPRE_DEVICE)
41+
#include <HYPRE_utilities.h>
42+
#endif
43+
3944
// C++ includes
4045
#include <memory>
4146
#include <string.h>
@@ -571,6 +576,20 @@ PetscLinearSolver<T>::solve_base (SparseMatrix<T> * matrix,
571576
// Allow command line options to override anything set programmatically.
572577
LibmeshPetscCall(KSPSetFromOptions(_ksp));
573578

579+
#if defined(LIBMESH_HAVE_PETSC_HYPRE) && PETSC_VERSION_LESS_THAN(3, 23, 0) && \
580+
!PETSC_VERSION_LESS_THAN(3, 12, 0) && defined(PETSC_HAVE_HYPRE_DEVICE)
581+
{
582+
// Make sure hypre has been initialized
583+
LibmeshPetscCallExternal(HYPRE_Initialize);
584+
PetscScalar * dummyarray;
585+
PetscMemType mtype;
586+
LibmeshPetscCall(VecGetArrayAndMemType(solution->vec(), &dummyarray, &mtype));
587+
LibmeshPetscCall(VecRestoreArrayAndMemType(solution->vec(), &dummyarray));
588+
if (PetscMemTypeHost(mtype))
589+
LibmeshPetscCallExternal(HYPRE_SetMemoryLocation, HYPRE_MEMORY_HOST);
590+
}
591+
#endif
592+
574593
// If the SolverConfiguration object is provided, use it to override
575594
// solver options.
576595
if (this->_solver_configuration)

src/solvers/petsc_nonlinear_solver.C

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#include "libmesh/petscdmlibmesh.h"
3535
#include "libmesh/petsc_mffd_matrix.h"
3636

37+
#if defined(LIBMESH_HAVE_PETSC_HYPRE) && PETSC_VERSION_LESS_THAN(3, 23, 0) && \
38+
!PETSC_VERSION_LESS_THAN(3, 12, 0) && defined(PETSC_HAVE_HYPRE_DEVICE)
39+
#include <HYPRE_utilities.h>
40+
#endif
41+
3742
namespace libMesh
3843
{
3944
class ResidualContext
@@ -1069,6 +1074,20 @@ PetscNonlinearSolver<T>::solve (SparseMatrix<T> & pre_in, // System Preconditi
10691074
#endif
10701075
LibmeshPetscCall(SNESSetFromOptions(_snes));
10711076

1077+
#if defined(LIBMESH_HAVE_PETSC_HYPRE) && PETSC_VERSION_LESS_THAN(3, 23, 0) && \
1078+
!PETSC_VERSION_LESS_THAN(3, 12, 0) && defined(PETSC_HAVE_HYPRE_DEVICE)
1079+
{
1080+
// Make sure hypre has been initialized
1081+
LibmeshPetscCallExternal(HYPRE_Initialize);
1082+
PetscScalar * dummyarray;
1083+
PetscMemType mtype;
1084+
LibmeshPetscCall(VecGetArrayAndMemType(x->vec(), &dummyarray, &mtype));
1085+
LibmeshPetscCall(VecRestoreArrayAndMemType(x->vec(), &dummyarray));
1086+
if (PetscMemTypeHost(mtype))
1087+
LibmeshPetscCallExternal(HYPRE_SetMemoryLocation, HYPRE_MEMORY_HOST);
1088+
}
1089+
#endif
1090+
10721091
if (this->user_presolve)
10731092
this->user_presolve(this->system());
10741093

0 commit comments

Comments
 (0)