Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor core/thread logic for mpibackend #3

Open
wants to merge 1 commit into
base: gui-mpi-available-cores
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions hnn_core/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import logging
import mimetypes
import numpy as np
import platform
import psutil
import sys
import json
import urllib.parse
Expand All @@ -36,7 +34,9 @@
get_L5Pyr_params_default)
from hnn_core.hnn_io import dict_to_network, write_network_configuration
from hnn_core.cells_default import _exp_g_at_dist
from hnn_core.parallel_backends import _has_mpi4py, _has_psutil
from hnn_core.parallel_backends import (_determine_cores_hwthreading,
_has_mpi4py,
_has_psutil)

hnn_core_root = Path(hnn_core.__file__).parent
default_network_configuration = (hnn_core_root / 'param' /
Expand Down Expand Up @@ -347,7 +347,10 @@ def __init__(self, theme_color="#802989",
self.params = self.load_parameters(network_configuration)

# Number of available cores
self.n_cores = self._available_cores()
[self.n_cores, _] = _determine_cores_hwthreading(
enable_hwthreading=False,
Copy link

Choose a reason for hiding this comment

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

Just curious, what are the pros/cons of having this false by default?

sensible_default_cores=True,
)

# In-memory storage of all simulation and visualization related data
self.simulation_data = defaultdict(lambda: dict(net=None, dpls=list()))
Expand Down Expand Up @@ -407,7 +410,8 @@ def __init__(self, theme_color="#802989",
self.widget_mpi_cmd = Text(value='mpiexec',
placeholder='Fill if applies',
description='MPI cmd:', disabled=False)
self.widget_n_jobs = BoundedIntText(value=1, min=1,
self.widget_n_jobs = BoundedIntText(value=1,
min=1,
max=self.n_cores,
description='Cores:',
disabled=False)
Expand Down Expand Up @@ -496,22 +500,6 @@ def __init__(self, theme_color="#802989",
self._init_ui_components()
self.add_logging_window_logger()

@staticmethod
def _available_cores():
"""Return the number of available cores to the process.

This is important for systems where the number of available cores is
partitioned such as on HPC systems. Linux and Windows can return cpu
affinity, which is the number of available cores. MacOS can only return
total system cores.
"""
# For macos
if platform.system() == 'Darwin':
return psutil.cpu_count()
# For Linux and Windows
else:
return len(psutil.Process().cpu_affinity())

@staticmethod
def _check_backend():
"""Checks for MPI and returns the default backend name"""
Expand Down Expand Up @@ -2108,7 +2096,10 @@ def run_button_clicked(widget_simulation_name, log_out, drive_widgets,
if backend_selection.value == "MPI":
backend = MPIBackend(
n_procs=n_jobs.value,
mpi_cmd=mpi_cmd.value)
mpi_cmd=mpi_cmd.value,
hwthreading=False,
oversubscribe=False,
)
else:
backend = JoblibBackend(n_jobs=n_jobs.value)
print(f"Using Joblib with {n_jobs.value} core(s).")
Expand Down
Loading