diff --git a/bout++.spec b/bout++.spec index c796cbe..b484ac6 100644 --- a/bout++.spec +++ b/bout++.spec @@ -15,6 +15,7 @@ Patch: https://github.com/boutproject/BOUT-dev/pull/2664.patch Patch: https://github.com/boutproject/BOUT-dev/pull/2678.patch Patch: https://github.com/boutproject/BOUT-dev/commit/489270184ba9e03cb9996c614050cb92513424e6.patch#./petsc_318_compat.patch Patch: https://github.com/boutproject/BOUT-dev/pull/2693.patch +Patch: https://github.com/boutproject/BOUT-dev/pull/2730.patch#./fmt10.patch # https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval ExcludeArch: %{ix86} diff --git a/fmt10.patch b/fmt10.patch new file mode 100644 index 0000000..3e60d8b --- /dev/null +++ b/fmt10.patch @@ -0,0 +1,375 @@ +From 1b970934752b0c5e3bfef17abba7feaac1d18ad1 Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Wed, 28 Jun 2023 14:58:42 +0200 +Subject: [PATCH 01/10] Improving compatibility with fmt 10 + +--- + src/invert/laplacexy/laplacexy.cxx | 3 ++- + src/invert/laplacexy2/laplacexy2.cxx | 3 ++- + src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx | 3 ++- + src/solver/impls/imex-bdf2/imex-bdf2.cxx | 3 ++- + 4 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/src/invert/laplacexy/laplacexy.cxx b/src/invert/laplacexy/laplacexy.cxx +index 439022e9bb..c1bc616bb1 100644 +--- a/src/invert/laplacexy/laplacexy.cxx ++++ b/src/invert/laplacexy/laplacexy.cxx +@@ -1199,7 +1199,8 @@ const Field2D LaplaceXY::solve(const Field2D& rhs, const Field2D& x0) { + KSPGetConvergedReason(ksp, &reason); + + if (reason <= 0) { +- throw BoutException("LaplaceXY failed to converge. Reason {:d}", reason); ++ throw BoutException("LaplaceXY failed to converge. Reason {} ({:d})", ++ KSPConvergedReasons[reason], static_cast(reason)); + } + + if (save_performance) { +diff --git a/src/invert/laplacexy2/laplacexy2.cxx b/src/invert/laplacexy2/laplacexy2.cxx +index dc7a4afa7f..8b5e98d747 100644 +--- a/src/invert/laplacexy2/laplacexy2.cxx ++++ b/src/invert/laplacexy2/laplacexy2.cxx +@@ -383,7 +383,8 @@ Field2D LaplaceXY2::solve(const Field2D& rhs, const Field2D& x0) { + KSPGetConvergedReason(ksp, &reason); + + if (reason <= 0) { +- throw BoutException("LaplaceXY2 failed to converge. Reason {:d}", reason); ++ throw BoutException("LaplaceXY2 failed to converge. Reason {} ({:d})", ++ KSPConvergedReasons[reason], static_cast(reason)); + } + + // Convert result into a Field2D +diff --git a/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx b/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx +index ff28f6d51a..8ddb058ab2 100644 +--- a/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx ++++ b/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx +@@ -942,7 +942,8 @@ Field3D LaplaceXZpetsc::solve(const Field3D& bin, const Field3D& x0in) { + KSPGetConvergedReason(it.ksp, &reason); + + if (reason <= 0) { +- throw BoutException("LaplaceXZ failed to converge. Reason {:d}", reason); ++ throw BoutException("LaplaceXZ failed to converge. Reason {} ({:d})", ++ KSPConvergedReasons[reason], static_cast(reason)); + } + + ////////////////////////// +diff --git a/src/solver/impls/imex-bdf2/imex-bdf2.cxx b/src/solver/impls/imex-bdf2/imex-bdf2.cxx +index aae92ad27d..c0faacc540 100644 +--- a/src/solver/impls/imex-bdf2/imex-bdf2.cxx ++++ b/src/solver/impls/imex-bdf2/imex-bdf2.cxx +@@ -1240,7 +1240,8 @@ PetscErrorCode IMEXBDF2::solve_implicit(BoutReal curtime, BoutReal gamma) { + if (verbose) { + output << "SNES failed to converge with reason " << reason << endl; + } +- throw BoutException("SNES failed to converge. Reason: {:d}\n", reason); ++ throw BoutException("SNES failed to converge. Reason: {} ({:d})", ++ SNESGetConvergedReasons[reason], static_cast(reason)); + } + + int its; + +From 697e5dcfc97454e5d4861189efcec91723a57f62 Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 01:26:26 +0200 +Subject: [PATCH 02/10] Add helper for ierr checking + +--- + include/bout/petsclib.hxx | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/include/bout/petsclib.hxx b/include/bout/petsclib.hxx +index e731405e1c..ef345aa87a 100644 +--- a/include/bout/petsclib.hxx ++++ b/include/bout/petsclib.hxx +@@ -64,6 +64,8 @@ class Options; + #include + #include + ++#define BOUT_DO_PETSC(cmd) PetscLib::assertIerr(cmd, #cmd) ++ + /*! + * Handles initialisation and finalisation of PETSc library. + * The first instance which is created initialises PETSc +@@ -111,6 +113,11 @@ public: + */ + static void cleanup(); + ++ static inline void assertIerr(PetscErrorCode ierr, std::string op = "PETSc operation") { ++ if (ierr) { ++ throw BoutException("{:s} failed with {:d}", op, ierr); ++ } ++ } + private: + static int count; ///< How many instances? + static char help[]; ///< Help string + +From 1a252a1dd2bdb04188bc4f4932a7e1bcf7fc5766 Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 01:27:08 +0200 +Subject: [PATCH 03/10] Use helper for snes error + +--- + include/bout/petsclib.hxx | 3 +++ + src/solver/impls/imex-bdf2/imex-bdf2.cxx | 3 +-- + src/sys/petsclib.cxx | 9 +++++++++ + 3 files changed, 13 insertions(+), 2 deletions(-) + +diff --git a/include/bout/petsclib.hxx b/include/bout/petsclib.hxx +index ef345aa87a..670069dd61 100644 +--- a/include/bout/petsclib.hxx ++++ b/include/bout/petsclib.hxx +@@ -118,6 +118,9 @@ public: + throw BoutException("{:s} failed with {:d}", op, ierr); + } + } ++ ++ static BoutException SNESFailure(SNES& snes); ++ + private: + static int count; ///< How many instances? + static char help[]; ///< Help string +diff --git a/src/solver/impls/imex-bdf2/imex-bdf2.cxx b/src/solver/impls/imex-bdf2/imex-bdf2.cxx +index c0faacc540..f7e03e5bed 100644 +--- a/src/solver/impls/imex-bdf2/imex-bdf2.cxx ++++ b/src/solver/impls/imex-bdf2/imex-bdf2.cxx +@@ -1240,8 +1240,7 @@ PetscErrorCode IMEXBDF2::solve_implicit(BoutReal curtime, BoutReal gamma) { + if (verbose) { + output << "SNES failed to converge with reason " << reason << endl; + } +- throw BoutException("SNES failed to converge. Reason: {} ({:d})", +- SNESGetConvergedReasons[reason], static_cast(reason)); ++ throw PetscLib::SNESFailure(snesUse); + } + + int its; +diff --git a/src/sys/petsclib.cxx b/src/sys/petsclib.cxx +index 91db0c44ea..2ca46d68af 100644 +--- a/src/sys/petsclib.cxx ++++ b/src/sys/petsclib.cxx +@@ -133,4 +133,13 @@ void PetscLib::setPetscOptions(Options& options, const std::string& prefix) { + } + } + } ++ ++BoutException PetscLib::SNESFailure(SNES& snes) { ++ SNESConvergedReason reason; ++ const char* message; ++ BOUT_DO_PETSC(SNESGetConvergedReason(snes, &reason)); ++ BOUT_DO_PETSC(SNESGetConvergedReasonString(snes, &message)); ++ return BoutException("SNES failed to converge. Reason: {} ({:d})", message, ++ static_cast(reason)); ++} + #endif // BOUT_HAS_PETSC + +From 18d3eadfb0a1895581ca31cad4eebcb55278bf2c Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 01:27:26 +0200 +Subject: [PATCH 04/10] Fix formatting + +This does not use fmt +--- + src/solver/impls/petsc/petsc.cxx | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/solver/impls/petsc/petsc.cxx b/src/solver/impls/petsc/petsc.cxx +index ad8e99dd38..6d6c5aa1ee 100644 +--- a/src/solver/impls/petsc/petsc.cxx ++++ b/src/solver/impls/petsc/petsc.cxx +@@ -542,7 +542,7 @@ int PetscSolver::init() { + CHKERRQ(ierr); + #endif + +- ierr = PetscSynchronizedPrintf(comm, "[{:d}] TSComputeRHSJacobian is done\n", rank); ++ ierr = PetscSynchronizedPrintf(comm, "[%d] TSComputeRHSJacobian is done\n", rank); + CHKERRQ(ierr); + + #if PETSC_VERSION_GE(3, 5, 0) +@@ -603,7 +603,7 @@ PetscErrorCode PetscSolver::run() { + "SNES Iteration, KSP Iterations, Wall Time, Norm\n"); + CHKERRQ(ierr); + for (const auto& info : snes_list) { +- ierr = PetscFPrintf(PETSC_COMM_WORLD, fp, "{:d}, {:d}, {:e}, {:e}\n", info.it, ++ ierr = PetscFPrintf(PETSC_COMM_WORLD, fp, "%d, %d, %e, %e\n", info.it, + info.linear_its, info.time, info.norm); + CHKERRQ(ierr); + } + +From e34966a456ebfe52475538871a6b62db47c9d94b Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 01:30:00 +0200 +Subject: [PATCH 05/10] Use new ierr checker + +--- + src/sys/petsclib.cxx | 20 ++++---------------- + 1 file changed, 4 insertions(+), 16 deletions(-) + +diff --git a/src/sys/petsclib.cxx b/src/sys/petsclib.cxx +index 2ca46d68af..5b5c9d7965 100644 +--- a/src/sys/petsclib.cxx ++++ b/src/sys/petsclib.cxx +@@ -66,27 +66,15 @@ PetscLib::~PetscLib() { + } + + void PetscLib::setOptionsFromInputFile(KSP& ksp) { +- auto ierr = KSPSetOptionsPrefix(ksp, options_prefix.c_str()); +- if (ierr) { +- throw BoutException("KSPSetOptionsPrefix failed with error {}", ierr); +- } ++ assertIerr(KSPSetOptionsPrefix(ksp, options_prefix.c_str()), "KSPSetOptionsPrefix"); + +- ierr = KSPSetFromOptions(ksp); +- if (ierr) { +- throw BoutException("KSPSetFromOptions failed with error {}", ierr); +- } ++ assertIerr(KSPSetFromOptions(ksp), "KSPSetFromOptions"); + } + + void PetscLib::setOptionsFromInputFile(SNES& snes) { +- auto ierr = SNESSetOptionsPrefix(snes, options_prefix.c_str()); +- if (ierr) { +- throw BoutException("SNESSetOptionsPrefix failed with error %i", ierr); +- } ++ BOUT_DO_PETSC(SNESSetOptionsPrefix(snes, options_prefix.c_str())); + +- ierr = SNESSetFromOptions(snes); +- if (ierr) { +- throw BoutException("SNESSetFromOptions failed with error %i", ierr); +- } ++ BOUT_DO_PETSC(SNESSetFromOptions(snes)); + } + + void PetscLib::cleanup() { + +From d5748e87ac74881b8636f9e1c8f751616c1b7a75 Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 01:42:40 +0200 +Subject: [PATCH 06/10] Explicitly cast to int for fmt10 + +--- + include/bout/invertable_operator.hxx | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/include/bout/invertable_operator.hxx b/include/bout/invertable_operator.hxx +index 49b254187a..7168324b75 100644 +--- a/include/bout/invertable_operator.hxx ++++ b/include/bout/invertable_operator.hxx +@@ -430,7 +430,8 @@ public: + KSPConvergedReason reason; + ierr = KSPGetConvergedReason(ksp, &reason); + if (reason <= 0) { +- throw BoutException("KSPSolve failed with reason {:d}.", reason); ++ throw BoutException("KSPSolve failed. Reason {} ({:d})", ++ KSPConvergedReasons[reason], static_cast(reason)); + } + + // Probably want to remove the following in the long run + +From fbb976b65d4bb49ca103c4930c95f0ddfbc13f6d Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 01:53:54 +0200 +Subject: [PATCH 07/10] Static cast also for printing + +--- + src/solver/impls/snes/snes.cxx | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/solver/impls/snes/snes.cxx b/src/solver/impls/snes/snes.cxx +index 69280bd6c2..f5c84d7cd9 100644 +--- a/src/solver/impls/snes/snes.cxx ++++ b/src/solver/impls/snes/snes.cxx +@@ -726,7 +726,7 @@ int SNESSolver::run() { + // Print diagnostics to help identify source of the problem + + output.write("\n======== SNES failed =========\n"); +- output.write("\nReturn code: {}, reason: {}\n", ierr, reason); ++ output.write("\nReturn code: {}, reason: {}\n", ierr, static_cast(reason)); + for (const auto& f : f2d) { + output.write( + "{} : ({} -> {}), ddt: ({} -> {})\n", f.name, +@@ -816,7 +816,7 @@ int SNESSolver::run() { + + output.print("\r"); // Carriage return for printing to screen + output.write("Time: {}, timestep: {}, nl iter: {}, lin iter: {}, reason: {}", +- simtime, timestep, nl_its, lin_its, reason); ++ simtime, timestep, nl_its, lin_its, static_cast(reason)); + if (snes_failures > 0) { + output.write(", SNES failures: {}", snes_failures); + snes_failures = 0; + +From 947ce8ad4207da70e67c0339ec83276eca43c04d Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 09:14:18 +0200 +Subject: [PATCH 08/10] Add missing include + +--- + include/bout/petsclib.hxx | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/include/bout/petsclib.hxx b/include/bout/petsclib.hxx +index 670069dd61..dd3daa28aa 100644 +--- a/include/bout/petsclib.hxx ++++ b/include/bout/petsclib.hxx +@@ -64,6 +64,8 @@ class Options; + #include + #include + ++#include "bout/boutexception.hxx" ++ + #define BOUT_DO_PETSC(cmd) PetscLib::assertIerr(cmd, #cmd) + + /*! + +From ed11bd7fc020cb7a8202e25a9ce1843d6e304f89 Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 09:37:52 +0200 +Subject: [PATCH 09/10] Add missing include + +--- + src/sys/petsclib.cxx | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/sys/petsclib.cxx b/src/sys/petsclib.cxx +index 5b5c9d7965..ca2531681b 100644 +--- a/src/sys/petsclib.cxx ++++ b/src/sys/petsclib.cxx +@@ -6,9 +6,10 @@ + #include "bout/openmpwrap.hxx" + #include "bout/options.hxx" + #include +- + #include + ++#include "petscsnes.h" ++ + // Define all the static member variables + int PetscLib::count = 0; + char PetscLib::help[] = "BOUT++: Uses finite difference methods to solve plasma fluid " + +From c3f7e40bf1fea3df7d842d50ecff9126348b68b2 Mon Sep 17 00:00:00 2001 +From: David Bold +Date: Fri, 30 Jun 2023 16:18:17 +0200 +Subject: [PATCH 10/10] SNESGetConvergedReasonString was introduced only in + PETSc 3.15 + +--- + src/sys/petsclib.cxx | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/sys/petsclib.cxx b/src/sys/petsclib.cxx +index ca2531681b..1342a41f70 100644 +--- a/src/sys/petsclib.cxx ++++ b/src/sys/petsclib.cxx +@@ -125,9 +125,13 @@ void PetscLib::setPetscOptions(Options& options, const std::string& prefix) { + + BoutException PetscLib::SNESFailure(SNES& snes) { + SNESConvergedReason reason; +- const char* message; + BOUT_DO_PETSC(SNESGetConvergedReason(snes, &reason)); ++#if PETSC_VERSION_GE(3, 15, 0) ++ const char* message; + BOUT_DO_PETSC(SNESGetConvergedReasonString(snes, &message)); ++#else ++ const char* message{""}; ++#endif + return BoutException("SNES failed to converge. Reason: {} ({:d})", message, + static_cast(reason)); + }