Skip to content

Commit

Permalink
now MPI.finalize() is called with atexit() to ensure that the MPI pro…
Browse files Browse the repository at this point in the history
…cesses are terminated gracefully
  • Loading branch information
anand-avinash committed Jun 10, 2024
1 parent 15ddca6 commit 0df034b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import warnings
import brahmap
from mpi4py import MPI
import atexit

# Dictionaries to keep track of the results and parameter counts of parametrized test cases
test_results_status = {}
Expand Down Expand Up @@ -83,3 +85,15 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
# Clear the dictionaries
test_results_status.clear()
test_param_counts.clear()


def finalize_mpi():
"""A function to be called when the tests are over. Once registered with `atexit`, it will be called automatically at the end."""
try:
MPI.Finalize()
except Exception as e:
print(f"Caught an exception during MPI finalization: {e}")


# Registering the `finalize_mpi`` function to be called at exit
atexit.register(finalize_mpi)

0 comments on commit 0df034b

Please sign in to comment.