Skip to content

Commit 2ffc643

Browse files
germa89akaszynskijleonatti
authored
Fix/Set default mpi for dmp (#611)
* Added switch '-mpi msmpi' to the launcher when on windows and dmp is requested. Resolves #609 * Converted additional switches to lower case. Added version checking before adding flat msmpi. Added a flag to enforce 'intel'. Resolves #609 * Fixing grammar * Fixing over-indented error. * move additional switch validation to its own function * add unit test for msmpi * Apply suggestions from code review Co-authored-by: jleonatti <[email protected]> * Fixing naming * whitespace fixes * Fixed spacing Co-authored-by: Alex Kaszynski <[email protected]> Co-authored-by: jleonatti <[email protected]>
1 parent 1182240 commit 2ffc643

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

ansys/mapdl/core/launcher.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
LOCALHOST = "127.0.0.1"
3333
MAPDL_DEFAULT_PORT = 50052
3434

35+
INTEL_MSG = """Due to incompatibilites between 'DMP', Windows and VPN connections,
36+
the flat '-mpi INTELMPI' is overwritten by '-mpi msmpi'.
37+
38+
If you still want to use 'INTEL', set:
39+
40+
launch_mapdl(..., force_intel=True, additional_switches='-mpi INTELMPI')
41+
42+
Be aware of possible errors or unexpected behaviour with this configuration.
43+
"""
44+
3545

3646
def _is_ubuntu():
3747
"""Determine if running as Ubuntu
@@ -673,6 +683,55 @@ def check_lock_file(path, jobname, override):
673683
)
674684

675685

686+
def _validate_add_sw(add_sw, exec_path, force_intel=False):
687+
"""Validate additional switches.
688+
689+
Parameters
690+
----------
691+
add_sw : str
692+
Additional swtiches.
693+
exec_path : str
694+
Path to the MAPDL executable.
695+
force_intel : bool, optional
696+
Force the usage of intelmpi. The default is ``False``.
697+
698+
Returns
699+
-------
700+
str
701+
Validated additional switches.
702+
703+
"""
704+
# Converting additional_switches to lower case to avoid mismatches.
705+
add_sw = add_sw.lower()
706+
707+
# known issues with distributed memory parallel (DMP)
708+
if "smp" not in add_sw: # pragma: no cover
709+
# Ubuntu ANSYS fails to launch without I_MPI_SHM_LMT
710+
if _is_ubuntu():
711+
os.environ['I_MPI_SHM_LMT'] = 'shm'
712+
if os.name == 'nt' and not force_intel:
713+
# Workaround to fix a problem when launching ansys in 'dmp' mode in the
714+
# recent windows version and using VPN.
715+
#
716+
# There doesn't appear to be an easy way to check if we
717+
# are running VPN in Windows in python, it seems we will
718+
# need to know a local address where to ping but that will
719+
# change for each client/person using the VPN.
720+
#
721+
# Adding '-mpi msmpi' to the launch parameter fix it.
722+
723+
if 'intelmpi' in add_sw:
724+
# Remove intel flag.
725+
regex = "(-mpi)( *?)(intelmpi)"
726+
add_sw = re.sub(regex, '', add_sw)
727+
warnings.warn(INTEL_MSG)
728+
729+
if _version_from_path(exec_file) >= 210:
730+
add_sw += ' -mpi msmpi'
731+
732+
return add_sw
733+
734+
676735
def launch_mapdl(
677736
exec_file=None,
678737
run_location=None,
@@ -973,13 +1032,9 @@ def launch_mapdl(
9731032
check_lock_file(run_location, jobname, override)
9741033
mode = check_mode(mode, _version_from_path(exec_file))
9751034

976-
# known issue with distributed memory parallel
977-
# Ubuntu ANSYS fails to launch without I_MPI_SHM_LMT
978-
if "smp" not in additional_switches:
979-
if _is_ubuntu():
980-
os.environ["I_MPI_SHM_LMT"] = "shm"
981-
9821035
# cache start parameters
1036+
additional_switches = _validate_add_sw(additional_switches, exec_file,
1037+
kwargs.pop('force_intel', False))
9831038
start_parm = {
9841039
"exec_file": exec_file,
9851040
"run_location": run_location,

tests/test_launcher.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"195", # 2019R3
2828
"201", # 2020R1
2929
"202", # 2020R2
30+
"211", # 2021R1
31+
"212", # 2021R2
3032
]
3133

3234
valid_versions = []
@@ -46,11 +48,20 @@
4648

4749
paths = [
4850
("/usr/dir_v2019.1/slv/ansys_inc/v211/ansys/bin/ansys211", 211),
49-
("C:/Program Files/ANSYS Inc/v202\\ansys/bin/win64/ANSYS202.exe", 202),
51+
("C:/Program Files/ANSYS Inc/v202/ansys/bin/win64/ANSYS202.exe", 202),
5052
("/usr/ansys_inc/v211/ansys/bin/mapdl", 211),
5153
]
5254

5355

56+
@pytest.mark.skipif(os.name != "nt", reason="Requires Windows")
57+
def test_validate_sw():
58+
# ensure that windows adds msmpi
59+
# fake windows path
60+
exec_path = "C:/Program Files/ANSYS Inc/v211/ansys/bin/win64/ANSYS211.exe"
61+
add_sw = _validate_add_sw('', exec_path)
62+
assert 'msmpi' in add_sw
63+
64+
5465
@pytest.mark.parametrize("path_data", paths)
5566
def test_version_from_path(path_data):
5667
exec_file, version = path_data

0 commit comments

Comments
 (0)