Skip to content

Commit

Permalink
Forcing SMP in student versions. (#1493)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
germa89 committed Oct 11, 2022
1 parent fa99294 commit 5e6f8a1
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 14 deletions.
4 changes: 4 additions & 0 deletions doc/source/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ available to you.
Visit `Ansys <https://www.ansys.com/>`_ for more information on
getting a licensed copy of Ansys.

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

.. toctree::
:hidden:
Expand Down
5 changes: 5 additions & 0 deletions doc/source/learning/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.ansys.com/academic/students>`_.
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>`_.


Expand Down
6 changes: 4 additions & 2 deletions doc/source/troubleshoot/troubleshoot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 61 additions & 10 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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.
#
Expand All @@ -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


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
)

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -1602,7 +1653,7 @@ def launch_mapdl(
# to the license check
if license_server_check:
lic_check.check()
# pass

raise exception

return mapdl
Expand Down
36 changes: 34 additions & 2 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)

0 comments on commit 5e6f8a1

Please sign in to comment.