Skip to content

Commit

Permalink
FFT resource lock
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Feb 2, 2024
1 parent c686fba commit ca47563
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/core/MpiCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,13 @@ class MpiCallbacks {
}

~MpiCallbacks() {
auto const myrank = m_comm.rank();
printf("%i: ~MpiCallbacks()\n", myrank);
/* Release the clients on exit */
if (m_abort_on_exit && (m_comm.rank() == 0)) {
try {
abort_loop();
} catch (...) {
}
}
printf("%i: ~MpiCallbacks(): done\n", myrank);
}

private:
Expand Down Expand Up @@ -452,6 +449,10 @@ class MpiCallbacks {
*/
boost::mpi::communicator const &comm() const { return m_comm; }

std::shared_ptr<boost::mpi::environment> share_mpi_env() const {
return m_mpi_env;
}

private:
/**
* @brief Id for the @ref abort_loop. Has to be 0.
Expand Down
1 change: 0 additions & 1 deletion src/core/communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ Utils::Vector3i Communicator::calc_node_index() const {
}

std::shared_ptr<boost::mpi::environment> mpi_init(int argc, char **argv) {
// std::ignore = boost::mpi::detail::mpi_datatype_cache();
return std::make_shared<boost::mpi::environment>(argc, argv);
}

Expand Down
5 changes: 0 additions & 5 deletions src/python/espressomd/_init.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ script_interface.init(communication.mpiCallbacksHandle())


def session_shutdown():
print(f"{communication.this_node}: _init.pyx: session_shutdown()")
print(f"{communication.this_node}: _init.pyx: mpi_env.use_count() = {mpi_env.use_count()}")
print(f"{communication.this_node}: _init.pyx: m_callbacks.use_count() = {communication.mpiCallbacksHandle().use_count()}")
mpi_env.reset()
communication.deinit()
script_interface.deinit()
print(f"{communication.this_node}: _init.pyx: done")


atexit.register(session_shutdown)
Expand All @@ -48,5 +44,4 @@ atexit.register(session_shutdown)
# The head node is just returning to the user script.
if communication.this_node != 0:
communication.mpi_loop()
print(f"{communication.this_node}: sys.exit(0)")
sys.exit(0)
2 changes: 1 addition & 1 deletion src/python/espressomd/script_interface.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def script_interface_register(c):
return c


cdef void init(const shared_ptr[MpiCallbacks] &cb):
cdef void init(const shared_ptr[MpiCallbacks] & cb):
cdef Factory[ObjectHandle] f

initialize(& f)
Expand Down
10 changes: 10 additions & 0 deletions src/script_interface/walberla/EKFFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@
#include "LatticeWalberla.hpp"

#include <walberla_bridge/electrokinetics/ek_poisson_fft_init.hpp>
#include <walberla_bridge/utils/ResourceManager.hpp>

#include <script_interface/ScriptInterface.hpp>
#include <script_interface/auto_parameters/AutoParameters.hpp>

#include <core/communication.hpp>

#include <utils/math/int_pow.hpp>

#include <memory>

namespace ScriptInterface::walberla {

class EKFFT : public EKPoissonSolver {
std::unique_ptr<ResourceManager> m_resources_lock; // must appear first
std::shared_ptr<::walberla::PoissonSolver> m_instance;
std::shared_ptr<LatticeWalberla> m_lattice;
double m_conv_permittivity;
Expand All @@ -57,7 +61,13 @@ class EKFFT : public EKPoissonSolver {

m_instance = new_ek_poisson_fft(m_lattice->lattice(), permittivity,
m_single_precision);
m_resources_lock = std::make_unique<ResourceManager>();
// MPI communicator is needed to destroy the FFT plans
m_resources_lock->acquire_lock(
Communication::mpiCallbacksHandle()->share_mpi_env());
}

EKFFT() {
add_parameters({
{"permittivity",
[this](Variant const &v) {
Expand Down

0 comments on commit ca47563

Please sign in to comment.