@@ -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
0 commit comments