Skip to content

Commit 5e6f8a1

Browse files
committed
Forcing SMP in student versions. (#1493)
* Forcing SMP in student versions. * Fixing unit tests. * Adding info to the docstring about the change. * Document the change in the docs and also notice the student version portal. * Fixing style.
1 parent fa99294 commit 5e6f8a1

File tree

5 files changed

+108
-14
lines changed

5 files changed

+108
-14
lines changed

doc/source/getting_started/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ available to you.
88
Visit `Ansys <https://www.ansys.com/>`_ for more information on
99
getting a licensed copy of Ansys.
1010

11+
You can also try the Student Version of Ansys products in
12+
`Ansys Student Versions <https://www.ansys.com/academic/students>`_.
13+
These are versions valid during a year and with limited capabilities
14+
regarding number of nodes, elements, etc.
1115

1216
.. toctree::
1317
:hidden:

doc/source/learning/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Ansys has prepared multiple resources to help you to learn and use PyMAPDL.
99
Resources
1010
=========
1111

12+
- You can also try the Student Version of Ansys products in
13+
`Ansys Student Versions <https://www.ansys.com/academic/students>`_.
14+
These are versions valid during a year and with limited capabilities
15+
regarding number of nodes, elements, etc.
16+
1217
- View and download `PyMAPDL cheatsheet <../_static/Cheat_Sheet_PyMAPDL.pdf>`_.
1318

1419

doc/source/troubleshoot/troubleshoot.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,16 @@ shown. For Ansys MAPDL 2022 R2, ``222`` appears where ``XXX`` is shown.
243243
C:\Program Files\ANSYS Inc\v222\CommonFiles\Language\en-us
244244
245245
246+
.. note:: Launching MAPDL Student Version
247+
By default if a Student version is detected, PyMAPDL will launch the MAPDL instance in
248+
``SMP`` mode, unless another MPI option is specified.
246249

247250
*****************
248251
Launching PyMAPDL
249252
*****************
250253

251254
Even if you are able to correctly launch MAPDL, PyMAPDL might have some problems to launch
252-
MAPDL.
253-
255+
MAPDL by itself.
254256

255257

256258
Manually Set the Executable Location

src/ansys/mapdl/core/launcher.py

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,11 @@ def check_lock_file(path, jobname, override):
983983
)
984984

985985

986-
def _validate_add_sw(add_sw, exec_path, force_intel=False):
987-
"""Validate additional switches.
986+
def _validate_MPI(add_sw, exec_path, force_intel=False):
987+
"""Validate MPI configuration.
988+
989+
Enforce Microsoft MPI in version 21.0 or later, to fix a
990+
VPN issue on Windows.
988991
989992
Parameters
990993
----------
@@ -1008,8 +1011,14 @@ def _validate_add_sw(add_sw, exec_path, force_intel=False):
10081011
if "smp" not in add_sw: # pragma: no cover
10091012
# Ubuntu ANSYS fails to launch without I_MPI_SHM_LMT
10101013
if _is_ubuntu():
1014+
LOG.debug("Ubuntu system detected. Adding 'I_MPI_SHM_LMT' env var.")
10111015
os.environ["I_MPI_SHM_LMT"] = "shm"
1012-
if os.name == "nt" and not force_intel:
1016+
1017+
if (
1018+
os.name == "nt"
1019+
and not force_intel
1020+
and (222 > _version_from_path(exec_path) >= 210)
1021+
):
10131022
# Workaround to fix a problem when launching ansys in 'dmp' mode in the
10141023
# recent windows version and using VPN.
10151024
#
@@ -1019,16 +1028,52 @@ def _validate_add_sw(add_sw, exec_path, force_intel=False):
10191028
# change for each client/person using the VPN.
10201029
#
10211030
# Adding '-mpi msmpi' to the launch parameter fix it.
1022-
10231031
if "intelmpi" in add_sw:
1032+
LOG.debug(
1033+
"Intel MPI flag detected. Removing it, if you want to enforce it, use ``force_intel`` keyword argument."
1034+
)
10241035
# Remove intel flag.
10251036
regex = "(-mpi)( *?)(intelmpi)"
10261037
add_sw = re.sub(regex, "", add_sw)
10271038
warnings.warn(INTEL_MSG)
10281039

1029-
if _version_from_path(exec_path) >= 210:
1030-
add_sw += " -mpi msmpi"
1040+
LOG.debug("Forcing Microsoft MPI (MSMPI) to avoid VPN issues.")
1041+
add_sw += " -mpi msmpi"
1042+
1043+
if (
1044+
"-mpi" not in add_sw and "-dmp" not in add_sw and "-smp" not in add_sw
1045+
): # pragma: no cover
1046+
if "student" in exec_path.lower():
1047+
add_sw += " -smp"
1048+
LOG.debug("Student version detected, using '-smp' switch by default.")
1049+
return add_sw
1050+
1051+
1052+
def _force_smp_student_version(add_sw, exec_path):
1053+
"""Force SMP in student version.
1054+
1055+
Parameters
1056+
----------
1057+
add_sw : str
1058+
Additional swtiches.
1059+
exec_path : str
1060+
Path to the MAPDL executable.
1061+
1062+
Returns
1063+
-------
1064+
str
1065+
Validated additional switches.
10311066
1067+
"""
1068+
# Converting additional_switches to lower case to avoid mismatches.
1069+
add_sw = add_sw.lower()
1070+
1071+
if (
1072+
"-mpi" not in add_sw and "-dmp" not in add_sw and "-smp" not in add_sw
1073+
): # pragma: no cover
1074+
if "student" in exec_path.lower():
1075+
add_sw += " -smp"
1076+
LOG.debug("Student version detected, using '-smp' switch by default.")
10321077
return add_sw
10331078

10341079

@@ -1208,6 +1253,9 @@ def launch_mapdl(
12081253
12091254
Notes
12101255
-----
1256+
If an Ansys Student version is detected, PyMAPDL will launch MAPDL in SMP mode
1257+
unless another option is specified.
1258+
12111259
These are the MAPDL switch options as of 2020R2 applicable for
12121260
running MAPDL as a service via gRPC. Excluded switches such as
12131261
``"-j"`` either not applicable or are set via keyword arguments.
@@ -1465,8 +1513,11 @@ def launch_mapdl(
14651513
check_lock_file(run_location, jobname, override)
14661514
mode = check_mode(mode, _version_from_path(exec_file))
14671515

1468-
# cache start parameters
1469-
additional_switches = _validate_add_sw(
1516+
# Setting SMP by default if student version is used.
1517+
additional_switches = _force_smp_student_version(additional_switches, exec_file)
1518+
1519+
#
1520+
additional_switches = _validate_MPI(
14701521
additional_switches, exec_file, kwargs.pop("force_intel", False)
14711522
)
14721523

@@ -1509,7 +1560,7 @@ def launch_mapdl(
15091560

15101561
elif "-p " in additional_switches:
15111562
# There is already a license request in additional switches.
1512-
license_type = re.findall(r"-p \b(\w*)", additional_switches)[
1563+
license_type = re.findall(r"-p\s+\b(\w*)", additional_switches)[
15131564
0
15141565
] # getting only the first product license.
15151566

@@ -1602,7 +1653,7 @@ def launch_mapdl(
16021653
# to the license check
16031654
if license_server_check:
16041655
lic_check.check()
1605-
# pass
1656+
16061657
raise exception
16071658

16081659
return mapdl

tests/test_launcher.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
from ansys.mapdl import core as pymapdl
1010
from ansys.mapdl.core.launcher import (
11-
_validate_add_sw,
11+
_force_smp_student_version,
12+
_validate_MPI,
1213
_version_from_path,
1314
get_start_instance,
1415
is_common_executable_path,
@@ -69,9 +70,12 @@ def test_validate_sw():
6970
# ensure that windows adds msmpi
7071
# fake windows path
7172
exec_path = "C:/Program Files/ANSYS Inc/v211/ansys/bin/win64/ANSYS211.exe"
72-
add_sw = _validate_add_sw("", exec_path)
73+
add_sw = _validate_MPI("", exec_path)
7374
assert "msmpi" in add_sw
7475

76+
add_sw = _validate_MPI("-mpi intelmpi", exec_path)
77+
assert "msmpi" in add_sw and "intelmpi" not in add_sw
78+
7579

7680
@pytest.mark.skipif(
7781
not get_start_instance(), reason="Skip when start instance is disabled"
@@ -383,3 +387,31 @@ def test_open_gui(mapdl):
383387

384388
mapdl.open_gui(include_result=False, inplace=False)
385389
mapdl.open_gui(include_result=True, inplace=True)
390+
391+
392+
def test__force_smp_student_version():
393+
add_sw = ""
394+
exec_path = (
395+
r"C:\Program Files\ANSYS Inc\ANSYS Student\v222\ansys\bin\winx64\ANSYS222.exe"
396+
)
397+
assert "-smp" in _force_smp_student_version(add_sw, exec_path)
398+
399+
add_sw = "-mpi"
400+
exec_path = (
401+
r"C:\Program Files\ANSYS Inc\ANSYS Student\v222\ansys\bin\winx64\ANSYS222.exe"
402+
)
403+
assert "-smp" not in _force_smp_student_version(add_sw, exec_path)
404+
405+
add_sw = "-dmp"
406+
exec_path = (
407+
r"C:\Program Files\ANSYS Inc\ANSYS Student\v222\ansys\bin\winx64\ANSYS222.exe"
408+
)
409+
assert "-smp" not in _force_smp_student_version(add_sw, exec_path)
410+
411+
add_sw = ""
412+
exec_path = r"C:\Program Files\ANSYS Inc\v222\ansys\bin\winx64\ANSYS222.exe"
413+
assert "-smp" not in _force_smp_student_version(add_sw, exec_path)
414+
415+
add_sw = "-smp"
416+
exec_path = r"C:\Program Files\ANSYS Inc\v222\ansys\bin\winx64\ANSYS222.exe"
417+
assert "-smp" in _force_smp_student_version(add_sw, exec_path)

0 commit comments

Comments
 (0)