From 5e6f8a1b049e87c8f21289628d2edff5afeeb8fa Mon Sep 17 00:00:00 2001
From: German <28149841+germa89@users.noreply.github.com>
Date: Thu, 15 Sep 2022 18:02:01 +0200
Subject: [PATCH] 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.
---
doc/source/getting_started/index.rst | 4 ++
doc/source/learning/index.rst | 5 ++
doc/source/troubleshoot/troubleshoot.rst | 6 +-
src/ansys/mapdl/core/launcher.py | 71 ++++++++++++++++++++----
tests/test_launcher.py | 36 +++++++++++-
5 files changed, 108 insertions(+), 14 deletions(-)
diff --git a/doc/source/getting_started/index.rst b/doc/source/getting_started/index.rst
index 3568e7393c..92adac4abf 100644
--- a/doc/source/getting_started/index.rst
+++ b/doc/source/getting_started/index.rst
@@ -8,6 +8,10 @@ available to you.
Visit `Ansys `_ for more information on
getting a licensed copy of Ansys.
+You can also try the Student Version of Ansys products in
+`Ansys Student Versions `_.
+These are versions valid during a year and with limited capabilities
+regarding number of nodes, elements, etc.
.. toctree::
:hidden:
diff --git a/doc/source/learning/index.rst b/doc/source/learning/index.rst
index 5df71058f5..838d415c6e 100644
--- a/doc/source/learning/index.rst
+++ b/doc/source/learning/index.rst
@@ -9,6 +9,11 @@ Ansys has prepared multiple resources to help you to learn and use PyMAPDL.
Resources
=========
+- You can also try the Student Version of Ansys products in
+ `Ansys Student Versions `_.
+ These are versions valid during a year and with limited capabilities
+ regarding number of nodes, elements, etc.
+
- View and download `PyMAPDL cheatsheet <../_static/Cheat_Sheet_PyMAPDL.pdf>`_.
diff --git a/doc/source/troubleshoot/troubleshoot.rst b/doc/source/troubleshoot/troubleshoot.rst
index 94dc11a95c..70cb25933a 100644
--- a/doc/source/troubleshoot/troubleshoot.rst
+++ b/doc/source/troubleshoot/troubleshoot.rst
@@ -243,14 +243,16 @@ shown. For Ansys MAPDL 2022 R2, ``222`` appears where ``XXX`` is shown.
C:\Program Files\ANSYS Inc\v222\CommonFiles\Language\en-us
+.. note:: Launching MAPDL Student Version
+ By default if a Student version is detected, PyMAPDL will launch the MAPDL instance in
+ ``SMP`` mode, unless another MPI option is specified.
*****************
Launching PyMAPDL
*****************
Even if you are able to correctly launch MAPDL, PyMAPDL might have some problems to launch
-MAPDL.
-
+MAPDL by itself.
Manually Set the Executable Location
diff --git a/src/ansys/mapdl/core/launcher.py b/src/ansys/mapdl/core/launcher.py
index 14f4ba92c7..41443b8f61 100644
--- a/src/ansys/mapdl/core/launcher.py
+++ b/src/ansys/mapdl/core/launcher.py
@@ -983,8 +983,11 @@ def check_lock_file(path, jobname, override):
)
-def _validate_add_sw(add_sw, exec_path, force_intel=False):
- """Validate additional switches.
+def _validate_MPI(add_sw, exec_path, force_intel=False):
+ """Validate MPI configuration.
+
+ Enforce Microsoft MPI in version 21.0 or later, to fix a
+ VPN issue on Windows.
Parameters
----------
@@ -1008,8 +1011,14 @@ def _validate_add_sw(add_sw, exec_path, force_intel=False):
if "smp" not in add_sw: # pragma: no cover
# Ubuntu ANSYS fails to launch without I_MPI_SHM_LMT
if _is_ubuntu():
+ LOG.debug("Ubuntu system detected. Adding 'I_MPI_SHM_LMT' env var.")
os.environ["I_MPI_SHM_LMT"] = "shm"
- if os.name == "nt" and not force_intel:
+
+ if (
+ os.name == "nt"
+ and not force_intel
+ and (222 > _version_from_path(exec_path) >= 210)
+ ):
# Workaround to fix a problem when launching ansys in 'dmp' mode in the
# recent windows version and using VPN.
#
@@ -1019,16 +1028,52 @@ def _validate_add_sw(add_sw, exec_path, force_intel=False):
# change for each client/person using the VPN.
#
# Adding '-mpi msmpi' to the launch parameter fix it.
-
if "intelmpi" in add_sw:
+ LOG.debug(
+ "Intel MPI flag detected. Removing it, if you want to enforce it, use ``force_intel`` keyword argument."
+ )
# Remove intel flag.
regex = "(-mpi)( *?)(intelmpi)"
add_sw = re.sub(regex, "", add_sw)
warnings.warn(INTEL_MSG)
- if _version_from_path(exec_path) >= 210:
- add_sw += " -mpi msmpi"
+ LOG.debug("Forcing Microsoft MPI (MSMPI) to avoid VPN issues.")
+ add_sw += " -mpi msmpi"
+
+ if (
+ "-mpi" not in add_sw and "-dmp" not in add_sw and "-smp" not in add_sw
+ ): # pragma: no cover
+ if "student" in exec_path.lower():
+ add_sw += " -smp"
+ LOG.debug("Student version detected, using '-smp' switch by default.")
+ return add_sw
+
+
+def _force_smp_student_version(add_sw, exec_path):
+ """Force SMP in student version.
+
+ Parameters
+ ----------
+ add_sw : str
+ Additional swtiches.
+ exec_path : str
+ Path to the MAPDL executable.
+
+ Returns
+ -------
+ str
+ Validated additional switches.
+ """
+ # Converting additional_switches to lower case to avoid mismatches.
+ add_sw = add_sw.lower()
+
+ if (
+ "-mpi" not in add_sw and "-dmp" not in add_sw and "-smp" not in add_sw
+ ): # pragma: no cover
+ if "student" in exec_path.lower():
+ add_sw += " -smp"
+ LOG.debug("Student version detected, using '-smp' switch by default.")
return add_sw
@@ -1208,6 +1253,9 @@ def launch_mapdl(
Notes
-----
+ If an Ansys Student version is detected, PyMAPDL will launch MAPDL in SMP mode
+ unless another option is specified.
+
These are the MAPDL switch options as of 2020R2 applicable for
running MAPDL as a service via gRPC. Excluded switches such as
``"-j"`` either not applicable or are set via keyword arguments.
@@ -1465,8 +1513,11 @@ def launch_mapdl(
check_lock_file(run_location, jobname, override)
mode = check_mode(mode, _version_from_path(exec_file))
- # cache start parameters
- additional_switches = _validate_add_sw(
+ # Setting SMP by default if student version is used.
+ additional_switches = _force_smp_student_version(additional_switches, exec_file)
+
+ #
+ additional_switches = _validate_MPI(
additional_switches, exec_file, kwargs.pop("force_intel", False)
)
@@ -1509,7 +1560,7 @@ def launch_mapdl(
elif "-p " in additional_switches:
# There is already a license request in additional switches.
- license_type = re.findall(r"-p \b(\w*)", additional_switches)[
+ license_type = re.findall(r"-p\s+\b(\w*)", additional_switches)[
0
] # getting only the first product license.
@@ -1602,7 +1653,7 @@ def launch_mapdl(
# to the license check
if license_server_check:
lic_check.check()
- # pass
+
raise exception
return mapdl
diff --git a/tests/test_launcher.py b/tests/test_launcher.py
index 5ebefefe3d..4813d88beb 100644
--- a/tests/test_launcher.py
+++ b/tests/test_launcher.py
@@ -8,7 +8,8 @@
from ansys.mapdl import core as pymapdl
from ansys.mapdl.core.launcher import (
- _validate_add_sw,
+ _force_smp_student_version,
+ _validate_MPI,
_version_from_path,
get_start_instance,
is_common_executable_path,
@@ -69,9 +70,12 @@ 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 = _validate_add_sw("", exec_path)
+ add_sw = _validate_MPI("", exec_path)
assert "msmpi" in add_sw
+ add_sw = _validate_MPI("-mpi intelmpi", exec_path)
+ assert "msmpi" in add_sw and "intelmpi" not in add_sw
+
@pytest.mark.skipif(
not get_start_instance(), reason="Skip when start instance is disabled"
@@ -383,3 +387,31 @@ def test_open_gui(mapdl):
mapdl.open_gui(include_result=False, inplace=False)
mapdl.open_gui(include_result=True, inplace=True)
+
+
+def test__force_smp_student_version():
+ add_sw = ""
+ exec_path = (
+ r"C:\Program Files\ANSYS Inc\ANSYS Student\v222\ansys\bin\winx64\ANSYS222.exe"
+ )
+ assert "-smp" in _force_smp_student_version(add_sw, exec_path)
+
+ add_sw = "-mpi"
+ exec_path = (
+ r"C:\Program Files\ANSYS Inc\ANSYS Student\v222\ansys\bin\winx64\ANSYS222.exe"
+ )
+ assert "-smp" not in _force_smp_student_version(add_sw, exec_path)
+
+ add_sw = "-dmp"
+ exec_path = (
+ r"C:\Program Files\ANSYS Inc\ANSYS Student\v222\ansys\bin\winx64\ANSYS222.exe"
+ )
+ assert "-smp" not in _force_smp_student_version(add_sw, exec_path)
+
+ add_sw = ""
+ exec_path = r"C:\Program Files\ANSYS Inc\v222\ansys\bin\winx64\ANSYS222.exe"
+ assert "-smp" not in _force_smp_student_version(add_sw, exec_path)
+
+ add_sw = "-smp"
+ exec_path = r"C:\Program Files\ANSYS Inc\v222\ansys\bin\winx64\ANSYS222.exe"
+ assert "-smp" in _force_smp_student_version(add_sw, exec_path)