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: using version instead of exec_path for the MPI checks #3528

Merged
merged 2 commits into from
Oct 30, 2024
Merged
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
1 change: 1 addition & 0 deletions doc/changelog.d/3528.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: using version instead of exec_path for the MPI checks
34 changes: 15 additions & 19 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def generate_mapdl_launch_command(

# Windows will spawn a new window, special treatment
if os.name == "nt":
exec_file = f'"{exec_file}"'
exec_file = f"{exec_file}"
# must start in batch mode on windows to hide APDL window
tmp_inp = ".__tmp__.inp"
command_parm = [
Expand Down Expand Up @@ -888,7 +888,7 @@ def check_lock_file(path, jobname, override):


def set_MPI_additional_switches(
add_sw: str, exec_path: str, force_intel: bool = False
add_sw: str, force_intel: bool = False, version: Optional[int] = None
) -> str:
"""Validate MPI configuration.

Expand All @@ -899,10 +899,10 @@ def set_MPI_additional_switches(
----------
add_sw : str
Additional switches.
exec_path : str
Path to the MAPDL executable.
force_intel : bool, optional
Force the usage of intelmpi. The default is :class:`False`.
version: int, optional
MAPDL version as integer

Returns
-------
Expand All @@ -915,21 +915,17 @@ def set_MPI_additional_switches(

# known issues with distributed memory parallel (DMP)
if "smp" not in add_sw_lower_case: # pragma: no cover
if _HAS_ATP:
condition = (
os.name == "nt"
and not force_intel
and (222 > version_from_path("mapdl", exec_path) >= 210)
)
if _HAS_ATP and os.name == "nt":
condition = not force_intel and version and (222 > version >= 210)
else:
if os.name == "nt":
warnings.warn(
"Because 'ansys-tools-path' is not installed, PyMAPDL cannot check\n"
"if this Ansys version requires the MPI fix, so if you are on Windows,\n"
"the fix is applied by default.\n"
"Use 'force_intel=True' to not apply the fix."
)
condition = os.name == "nt" and not force_intel
warnings.warn(
"Because 'ansys-tools-path' is not installed, PyMAPDL cannot check\n"
"if this Ansys version requires the MPI fix, so if you are on Windows,\n"
"the fix is applied by default.\n"
"Use 'force_intel=True' to not apply the fix."
)

condition = not force_intel

if condition:
# Workaround to fix a problem when launching ansys in 'dmp' mode in the
Expand Down Expand Up @@ -1465,8 +1461,8 @@ def launch_mapdl(
# Set compatible MPI
args["additional_switches"] = set_MPI_additional_switches(
args["additional_switches"],
args["exec_file"],
force_intel=args["force_intel"],
version=args["version"],
)

LOG.debug(f"Using additional switches {args['additional_switches']}.")
Expand Down
13 changes: 7 additions & 6 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ def fake_local_mapdl(mapdl):
def test_validate_sw():
# ensure that windows adds msmpi
# fake windows path
exec_path = "C:/Program Files/ANSYS Inc/v211/ansys/bin/win64/ANSYS211.exe"
add_sw = set_MPI_additional_switches("", exec_path)
version = 211
add_sw = set_MPI_additional_switches("", version=version)
assert "msmpi" in add_sw

add_sw = set_MPI_additional_switches("-mpi intelmpi", exec_path)
add_sw = set_MPI_additional_switches("-mpi intelmpi", version=version)
assert "msmpi" in add_sw and "intelmpi" not in add_sw

add_sw = set_MPI_additional_switches("-mpi INTELMPI", exec_path)
add_sw = set_MPI_additional_switches("-mpi INTELMPI", version=version)
assert "msmpi" in add_sw and "INTELMPI" not in add_sw


Expand Down Expand Up @@ -949,7 +949,7 @@ def test_generate_mapdl_launch_command_windows():

assert isinstance(cmd, list)

assert f'"{exec_file}"' in cmd
assert f"{exec_file}" in cmd
assert "-j" in cmd
assert f"{jobname}" in cmd
assert "-port" in cmd
Expand All @@ -967,7 +967,7 @@ def test_generate_mapdl_launch_command_windows():
assert ".__tmp__.out" in cmd

cmd = " ".join(cmd)
assert f'"{exec_file}"' in cmd
assert f"{exec_file}" in cmd
assert f" -j {jobname} " in cmd
assert f" -port {port} " in cmd
assert f" -m {ram*1024} " in cmd
Expand All @@ -978,6 +978,7 @@ def test_generate_mapdl_launch_command_windows():
assert f" -o .__tmp__.out " in cmd


@patch("os.name", "posix")
def test_generate_mapdl_launch_command_linux():
assert os.name != "nt" # Checking mocking is properly done

Expand Down
Loading