Skip to content

Commit 747b6f3

Browse files
authored
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 dfaa864 commit 747b6f3

File tree

5 files changed

+102
-14
lines changed

5 files changed

+102
-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: 55 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
# This is due to the intel compiler, and only afects versions between
@@ -1021,19 +1030,49 @@ def _validate_add_sw(add_sw, exec_path, force_intel=False):
10211030
# change for each client/person using the VPN.
10221031
#
10231032
# Adding '-mpi msmpi' to the launch parameter fix it.
1024-
10251033
if "intelmpi" in add_sw:
1034+
LOG.debug(
1035+
"Intel MPI flag detected. Removing it, if you want to enforce it, use ``force_intel`` keyword argument."
1036+
)
10261037
# Remove intel flag.
10271038
regex = "(-mpi)( *?)(intelmpi)"
10281039
add_sw = re.sub(regex, "", add_sw)
10291040
warnings.warn(INTEL_MSG)
10301041

1031-
if 222 > _version_from_path(exec_path) >= 210:
1032-
add_sw += " -mpi msmpi"
1042+
LOG.debug("Forcing Microsoft MPI (MSMPI) to avoid VPN issues.")
1043+
add_sw += " -mpi msmpi"
10331044

10341045
return add_sw
10351046

10361047

1048+
def _force_smp_student_version(add_sw, exec_path):
1049+
"""Force SMP in student version.
1050+
1051+
Parameters
1052+
----------
1053+
add_sw : str
1054+
Additional swtiches.
1055+
exec_path : str
1056+
Path to the MAPDL executable.
1057+
1058+
Returns
1059+
-------
1060+
str
1061+
Validated additional switches.
1062+
1063+
"""
1064+
# Converting additional_switches to lower case to avoid mismatches.
1065+
add_sw = add_sw.lower()
1066+
1067+
if (
1068+
"-mpi" not in add_sw and "-dmp" not in add_sw and "-smp" not in add_sw
1069+
): # pragma: no cover
1070+
if "student" in exec_path.lower():
1071+
add_sw += " -smp"
1072+
LOG.debug("Student version detected, using '-smp' switch by default.")
1073+
return add_sw
1074+
1075+
10371076
def launch_mapdl(
10381077
exec_file=None,
10391078
run_location=None,
@@ -1220,6 +1259,9 @@ def launch_mapdl(
12201259
12211260
Notes
12221261
-----
1262+
If an Ansys Student version is detected, PyMAPDL will launch MAPDL in SMP mode
1263+
unless another option is specified.
1264+
12231265
These are the MAPDL switch options as of 2020R2 applicable for
12241266
running MAPDL as a service via gRPC. Excluded switches such as
12251267
``"-j"`` either not applicable or are set via keyword arguments.
@@ -1487,8 +1529,11 @@ def launch_mapdl(
14871529
check_lock_file(run_location, jobname, override)
14881530
mode = check_mode(mode, _version_from_path(exec_file))
14891531

1490-
# cache start parameters
1491-
additional_switches = _validate_add_sw(
1532+
# Setting SMP by default if student version is used.
1533+
additional_switches = _force_smp_student_version(additional_switches, exec_file)
1534+
1535+
#
1536+
additional_switches = _validate_MPI(
14921537
additional_switches, exec_file, kwargs.pop("force_intel", False)
14931538
)
14941539

@@ -1531,7 +1576,7 @@ def launch_mapdl(
15311576

15321577
elif "-p " in additional_switches:
15331578
# There is already a license request in additional switches.
1534-
license_type = re.findall(r"-p \b(\w*)", additional_switches)[
1579+
license_type = re.findall(r"-p\s+\b(\w*)", additional_switches)[
15351580
0
15361581
] # getting only the first product license.
15371582

@@ -1624,7 +1669,7 @@ def launch_mapdl(
16241669
# to the license check
16251670
if license_server_check:
16261671
lic_check.check()
1627-
# pass
1672+
16281673
raise exception
16291674

16301675
# Stopping license checker

tests/test_launcher.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from ansys.mapdl import core as pymapdl
1010
from ansys.mapdl.core.errors import LicenseServerConnectionError
1111
from ansys.mapdl.core.launcher import (
12-
_validate_add_sw,
12+
_force_smp_student_version,
13+
_validate_MPI,
1314
_version_from_path,
1415
get_start_instance,
1516
is_common_executable_path,
@@ -70,9 +71,12 @@ def test_validate_sw():
7071
# ensure that windows adds msmpi
7172
# fake windows path
7273
exec_path = "C:/Program Files/ANSYS Inc/v211/ansys/bin/win64/ANSYS211.exe"
73-
add_sw = _validate_add_sw("", exec_path)
74+
add_sw = _validate_MPI("", exec_path)
7475
assert "msmpi" in add_sw
7576

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

7781
@pytest.mark.skipif(
7882
not get_start_instance(), reason="Skip when start instance is disabled"
@@ -385,3 +389,31 @@ def test_open_gui(mapdl):
385389

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

0 commit comments

Comments
 (0)