Skip to content

Ifpack2: Hypre interface and ordinal type matching - #15090

Merged
cgcgcg merged 6 commits into
trilinos:developfrom
berselius:ifpack2_hypre_globals
Jul 6, 2026
Merged

Ifpack2: Hypre interface and ordinal type matching#15090
cgcgcg merged 6 commits into
trilinos:developfrom
berselius:ifpack2_hypre_globals

Conversation

@berselius

Copy link
Copy Markdown
Contributor

@trilinos/ifpack2

Motivation

  • I want to use the hypre interface for BoomerAMG preconditioners, which we previously used on the Epetra stack, for Tpetra conversion acceptance
  • See Ifpack2: HYPRE interface #15085
  • This interface tested, and it seems that the Tpetra global_ordinal and hypre's quasi-equivalent HYPRE_BigInt did not map to each other in the Ifpack2 hypre interface implementation

Testing

  • I was able to use these changes in Trilinos 16.2 to successfully call BoomerAMG and Hypre_PCG in my tpetra-based application code.

@berselius
berselius requested a review from a team as a code owner April 1, 2026 21:44
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

CDash for AT2 results [Currently only accessible from Sandia networks]

@berselius
berselius force-pushed the ifpack2_hypre_globals branch from ef0637a to 61d37cb Compare April 1, 2026 22:00
@cgcgcg

cgcgcg commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Did Hypre change this? Because originally this definitely did build and run correctly. Maybe use a typedef so that it's easier to change it back?

@berselius

berselius commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

I wonder if you built hypre/trilinos in a different way - I think the way the code is currently set up would work if local_ordinal and global_ordinal were both int, which is the default out of the box with hypre spack builds

@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

Your PR updated files that did not respect package formatting settings.
Please apply the patch given below. Alternatively you can download a patch file here.

Patch
diff --git a/packages/ifpack2/src/Ifpack2_Hypre_decl.hpp b/packages/ifpack2/src/Ifpack2_Hypre_decl.hpp
index e21d1476..4e46d6b8 100644
--- a/packages/ifpack2/src/Ifpack2_Hypre_decl.hpp
+++ b/packages/ifpack2/src/Ifpack2_Hypre_decl.hpp
@@ -287,13 +287,13 @@ class Hypre : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar
 
 template <class LocalOrdinal, class Node>
 class Hypre<Tpetra::RowMatrix<HYPRE_Real, LocalOrdinal, HYPRE_BigInt, Node> > : virtual public Ifpack2::Preconditioner<HYPRE_Real,
-                                                                                                                    LocalOrdinal,
-                                                                                                                    HYPRE_BigInt,
-                                                                                                                    Node>,
-                                                                             virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<HYPRE_Real,
-                                                                                                                                                LocalOrdinal,
-                                                                                                                                                HYPRE_BigInt,
-                                                                                                                                                Node> > {
+                                                                                                                       LocalOrdinal,
+                                                                                                                       HYPRE_BigInt,
+                                                                                                                       Node>,
+                                                                                virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<HYPRE_Real,
+                                                                                                                                                   LocalOrdinal,
+                                                                                                                                                   HYPRE_BigInt,
+                                                                                                                                                   Node> > {
  public:
   //! \name Typedefs
   //@{
diff --git a/packages/ifpack2/src/Ifpack2_Hypre_def.hpp b/packages/ifpack2/src/Ifpack2_Hypre_def.hpp
index 048d02a5..7c8ed23d 100644
--- a/packages/ifpack2/src/Ifpack2_Hypre_def.hpp
+++ b/packages/ifpack2/src/Ifpack2_Hypre_def.hpp
@@ -395,7 +395,7 @@ int Hypre<Tpetra::RowMatrix<HYPRE_Real, LocalOrdinal, HYPRE_BigInt, Node> >::Set
     }
     HYPRE_BigInt GlobalRow[1];
     HYPRE_Int numEntries = (HYPRE_Int)indices.extent(0);
-    GlobalRow[0]  = GloballyContiguousRowMap_->getGlobalElement(i);
+    GlobalRow[0]         = GloballyContiguousRowMap_->getGlobalElement(i);
     IFPACK2_CHK_ERR(HYPRE_IJMatrixSetValues(HypreG_, 1, &numEntries, GlobalRow, new_indices.data(), values.data()));
   }
   IFPACK2_CHK_ERR(HYPRE_IJMatrixAssemble(HypreG_));
@@ -548,10 +548,10 @@ int Hypre<Tpetra::RowMatrix<HYPRE_Real, LocalOrdinal, HYPRE_BigInt, Node> >::Cal
 //==============================================================================
 template <class LocalOrdinal, class Node>
 void Hypre<Tpetra::RowMatrix<HYPRE_Real, LocalOrdinal, HYPRE_BigInt, Node> >::apply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &X,
-                                                                                 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &Y,
-                                                                                 Teuchos::ETransp mode,
-                                                                                 scalar_type alpha,
-                                                                                 scalar_type beta) const {
+                                                                                    Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &Y,
+                                                                                    Teuchos::ETransp mode,
+                                                                                    scalar_type alpha,
+                                                                                    scalar_type beta) const {
   using LO = local_ordinal_type;
   using SC = scalar_type;
   const std::string timerName("Ifpack2::Hypre::apply");
@@ -621,8 +621,8 @@ void Hypre<Tpetra::RowMatrix<HYPRE_Real, LocalOrdinal, HYPRE_BigInt, Node> >::ap
 //==============================================================================
 template <class LocalOrdinal, class Node>
 void Hypre<Tpetra::RowMatrix<HYPRE_Real, LocalOrdinal, HYPRE_BigInt, Node> >::applyMat(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &X,
-                                                                                    Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &Y,
-                                                                                    Teuchos::ETransp mode) const {
+                                                                                       Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> &Y,
+                                                                                       Teuchos::ETransp mode) const {
   A_->apply(X, Y, mode);
 }  // applyMat()
 

More details about our use of clang-format and other tools can be found in the wiki.

@berselius

Copy link
Copy Markdown
Contributor Author

I think this should work if you build trilinos with int int instead of int long long and configure hypre the same way...I can test it, but what is the recommended way to set that in spack for trilinos?

@cgcgcg

cgcgcg commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

I always built with --enable-bigint. #15085 (comment)

@berselius

Copy link
Copy Markdown
Contributor Author

ahh, IIRC that one makes HYPRE_Int (locals) and HYPRE_BigInt (globals) both long long so I guess you also would not run into mismatches there. From what I've seen in the hypre docs going "full bigint" is not recommended/possible for most of their GPU-related things. And we don't need 64 bit locals in our app anyway.

@cgcgcg

cgcgcg commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Ok. Sounds like your changes are an improvement, but might require additional changes to the Trilinos Spack package?

@berselius

Copy link
Copy Markdown
Contributor Author

I guess it depends on how prescriptive you want to be about expected build failures, heh. In the current head I don't think there is a check that the hypre types and trilinos types are consistent.

@sebrowne sebrowne added AT: PRE-TEST INSPECTED Required to test outside contributions. This label alone will not allow a PR to merge. AT2-Pre-Test-Inspected labels Apr 7, 2026
@berselius

Copy link
Copy Markdown
Contributor Author

Howdy @cgcgcg

I finally had time to take another look at the MR, and I’m not sure if I am remembering our discussion correctly. My sketched notes were that you suggested adding a typedef so that a developer can more easily toggle back to the way things were set up in the current head. But looking again I’m not sure that’s right. Apologies for thinking out loud below, let me lay out my thinking…

  • Hypre does not have dynamic typing, HYPRE_Int and HYPRE_BigInt are locked in when you build it
  • HYPRE_Int is the equivalent of Trilinos’s local_ordinal_type and HYPRE_BigInt is the equivalent of the global type in trilinos
  • The issue this MR is fixing is that these mappings were not reflected in the interface above, but still work in the case where HYPRE_Int and HYPRE_BigInt are the same type (in your testing, IIRC they were both int64).
  • Since this automatically picks up whatever was defined in the hypre build, I don't think it makes sense to add some additional typedef'ing

Let me know if I'm misremembering what we discussed, or if there was something else I should modify.

@cgcgcg

cgcgcg commented May 20, 2026

Copy link
Copy Markdown
Contributor

Finally had a look:
https://github.com/hypre-space/hypre/blob/85b779557005b2eb94c231c1b516e988b87f4e53/src/utilities/HYPRE_utilities.h#L54-L95

Does this mean that we should outright specialize like so

template <class Node>
Hypre<Tpetra::RowMatrix<HYPRE_Real, HYPRE_Int, HYPRE_BigInt, Node> >

instead of

template <class LocalOrdinal, class Node>
Hypre<Tpetra::RowMatrix<HYPRE_Real, LocalOrdinal, HYPRE_BigInt, Node> >

?

@berselius
berselius requested a review from a team as a code owner May 26, 2026 16:42
@berselius

Copy link
Copy Markdown
Contributor Author

@cgcgcg my app's tests are passing with these changes

@cgcgcg cgcgcg added AT: PRE-TEST INSPECTED Required to test outside contributions. This label alone will not allow a PR to merge. and removed AT: PRE-TEST INSPECTED Required to test outside contributions. This label alone will not allow a PR to merge. labels Jun 15, 2026
@berselius

Copy link
Copy Markdown
Contributor Author

Made some small changes as hypre@3.0: changes a header file name that ifpack2 references.

@berselius

Copy link
Copy Markdown
Contributor Author

I've been testing these changes off of Trilinos 17.1.1

@berselius
berselius force-pushed the ifpack2_hypre_globals branch from e284e4d to 1c7dec7 Compare July 2, 2026 17:49
@cgcgcg cgcgcg added AT: PRE-TEST INSPECTED Required to test outside contributions. This label alone will not allow a PR to merge. and removed AT: PRE-TEST INSPECTED Required to test outside contributions. This label alone will not allow a PR to merge. labels Jul 2, 2026

@cgcgcg cgcgcg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@berselius LGTM. Please sign off your commits.

@berselius

Copy link
Copy Markdown
Contributor Author

Might be my own ignorance here with the signoffs - I think the commits its complaining about was something I brought in with a merge or rebase. Is there an easy way to fix it?

@cgcgcg

cgcgcg commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Oh, my bad. Yes, please rebase onto develop. That should get rid of the unsigned merge commits.

…PRE_BigInt to match up

Signed-off-by: Jeff Haack <haack@lanl.gov>
berselius added 5 commits July 6, 2026 09:52
Signed-off-by: Jeff Haack <haack@lanl.gov>
Signed-off-by: Jeff Haack <haack@lanl.gov>
Signed-off-by: Jeff Haack <haack@lanl.gov>
Signed-off-by: Jeff Haack <haack@lanl.gov>
Signed-off-by: Jeff Haack <haack@lanl.gov>
@berselius
berselius force-pushed the ifpack2_hypre_globals branch from 1c7dec7 to 3196e5f Compare July 6, 2026 15:57
@cgcgcg
cgcgcg enabled auto-merge July 6, 2026 17:23
@cgcgcg
cgcgcg merged commit 53a35a9 into trilinos:develop Jul 6, 2026
26 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AT: PRE-TEST INSPECTED Required to test outside contributions. This label alone will not allow a PR to merge. pkg: Ifpack2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants