Skip to content

Commit

Permalink
Free memory before starting a new loop (#206).
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Blondel committed Jan 29, 2025
1 parent 5c26600 commit 66840c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 3 additions & 2 deletions xolotl/core/include/xolotl/core/network/Reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace core
{
namespace network
{
template <typename TImpl> class ReactionNetwork;
template <typename TImpl>
class ReactionNetwork;
/**
* @brief General reaction class where
* reactants become products with a given rate
Expand All @@ -30,7 +31,7 @@ template <typename TImpl> class ReactionNetwork;
template <typename TNetwork, typename TDerived>
class Reaction
{
friend class ReactionNetwork<TNetwork>;
friend class ReactionNetwork<TNetwork>;
using Types = detail::ReactionNetworkTypes<TNetwork>;
using Props = detail::ReactionNetworkProperties<TNetwork>;

Expand Down
9 changes: 9 additions & 0 deletions xolotl/solver/src/PetscSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ PetscSolver::initialize(int loop, double time, DM oldDA, Vec oldC)
PetscCallVoid(PetscInitialize(NULL, NULL, NULL, help));
petscInitializedHere = true;
}
// Free memory
if (loop > 0) {
PetscCallVoid(PetscOptionsDestroy(&petscOptions));
PetscCallVoid(VecDestroy(&C));
PetscCallVoid(TSDestroy(&ts));
PetscCallVoid(DMDestroy(&da));
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Create the solver options
Expand Down Expand Up @@ -358,7 +365,9 @@ PetscSolver::solve()
while (reason == TS_CONVERGED_USER) {
// The interface already initialized the first loop
if (loopNumber > 0) {
PetscCallVoid(PetscOptionsPop());
initialize(loopNumber, time, oldDA, oldC);
PetscCallVoid(PetscOptionsPush(petscOptions));
}

/*
Expand Down
3 changes: 3 additions & 0 deletions xolotl/solver/src/monitor/PetscMonitor1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,9 @@ PetscMonitor1D::postEventFunction(TS ts, PetscInt nevents, PetscInt eventList[],
if (nGridPoints > 0) {
_solverHandler->setSurfaceOffset(nGridPoints);
PetscCall(TSSetConvergedReason(ts, TS_CONVERGED_USER));

// Restore the solutionArray
PetscCall(DMDAVecRestoreArrayDOF(da, solution, &solutionArray));
PetscFunctionReturn(0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions xolotl/util/include/xolotl/util/Atomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ KOKKOS_INLINE_FUNCTION
bool
atomicCompareExchangeStrong(T* ptr, T expected, T desired)
{
return expected == Kokkos::atomic_compare_exchange(ptr, expected, desired);
}
}
return expected == Kokkos::atomic_compare_exchange(ptr, expected, desired);
}
} // namespace util
} // namespace xolotl

0 comments on commit 66840c9

Please sign in to comment.