Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance decline during loops after update to newer version of apdl-mapdl-core #2608

Closed
4 tasks done
lunabrun opened this issue Jan 4, 2024 · 6 comments · Fixed by #2778
Closed
4 tasks done

Performance decline during loops after update to newer version of apdl-mapdl-core #2608

lunabrun opened this issue Jan 4, 2024 · 6 comments · Fixed by #2778
Assignees

Comments

@lunabrun
Copy link

lunabrun commented Jan 4, 2024

🤓 Before submitting the issue

🔍 Description of the bug

Hello,

after updating ansys-mapdl-core from 0.65.2 to 0.66 and afterwards to 0.67, the time elapsed during execution increased significantly for loops with mapdl commands inside.

Running the same test code snippet (see below) with different combinations of package version (0.65.2 / 0.66 / 0.67), memory setting (smp / dmp) and performance optimization (chain_commands / non_interactive / mute=True), the versions 0.66 and 0.67 needed one order of magnitude more time for the same loop of commands when comparing with the version 0.65.2 using the same "performance optimization" (e.g., comparing non_interactive in 0.65.2 vs. non_interactive in 0.66 or 0.67, etc.). The base case (i.e., without performance optimization) also gets slower in 0.66 /0.67, but "only" by a factor <2.

The graphic below summarizes the results:
Version_vs_Execution_time

Legend:
SMP: Shared Memory Parallel
DMP: Distributed Memory Parallel
CC: Use of "with.mapdl.chain.command"
NI: Use of "with.mapdl.non_interactive"
MT: Use of "mute=True"
BC: Base case, i.e., none of CC/NI/MT.

All times shown in the figure above are average of four runs. Please see file below for the results of all runs:
Elapsed_Times_report.xlsx

My guess for this behaviour:
In the versions 0.66 and 0.67, a file called "anstmp" keeps being written and subsequently erased multiple times in the working folder. It does not seems to be the case for 0.65.2.

Thanks!

🕵️ Steps To Reproduce

from ansys.mapdl.core import launch_mapdl
import time

mapdl = launch_mapdl(additional_switches="-smp")  # "-smp" or "-dmp"
mapdl.prep7()
tic = time.time()
with mapdl.chain_commands:  # or with mapdl.non_interactive:
    for el in range(400):
        elansys = el + 1
        mapdl.mp(
            "EX", elansys, elansys
        )  # or mapdl.mp("EX", elansys, elansys, mute=True)
tac = time.time()
print("--- Elapsed time in loop: %s seconds ---" % (tac - tic))

💻 Which Operating System are you using?

Windows

🐍 Which Python version are you using?

3.12

📝 PyMAPDL Report

Show the Report!

-------------------------------------------------------------------------------


PyMAPDL Software and Environment Report


Packages Requirements
*********************

Core packages
-------------
ansys.mapdl.core    : 0.67.0
numpy               : 1.26.3
platformdirs        : 4.1.0
scipy               : 1.11.4
grpc                : Package not found
ansys.api.mapdl.v0  : Package not found
ansys.mapdl.reader  : 0.53.0
google.protobuf     : Package not found

Optional packages
-----------------
matplotlib          : 3.8.2
pyvista             : 0.43.1
pyiges              : 0.3.1
tqdm                : 4.66.1


Ansys Installation
******************
Version   Location
------------------
211       C:\Program Files\ANSYS Inc\v211
221       C:\Program Files\ANSYS Inc\v221


Ansys Environment Variables
***************************
ANSYS211_DIR                   C:\Program Files\ANSYS Inc\v211\ANSYS
ANSYS221_DIR                   C:\Program Files\ANSYS Inc\v221\ANSYS
ANSYSLI_ELASTIC                0
ANSYSLI_LCP                    0
ANSYS_SYSDIR                   winx64
ANSYS_SYSDIR32                 win32
AWP_LOCALE221                  en-us
AWP_ROOT211                    C:\Program Files\ANSYS Inc\v211
AWP_ROOT221                    C:\Program Files\ANSYS Inc\v221
CADOE_LIBDIR221                C:\Program Files\ANSYS Inc\v221\CommonFiles\Language\en-us

📝 Installed packages

Show the installed packages!

ansys-api-mapdl==0.5.1
ansys-api-platform-instancemanagement==1.0.0
ansys-mapdl-core==0.67.0
ansys-mapdl-reader==0.53.0
ansys-math-core==0.1.3
ansys-platform-instancemanagement==1.1.2
ansys-tools-path==0.4.0
appdirs==1.4.4
certifi==2023.11.17
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
contourpy==1.2.0
cycler==0.12.1
fonttools==4.47.0
geomdl==5.3.1
grpcio==1.60.0
idna==3.6
importlib-metadata==7.0.1
kiwisolver==1.4.5
matplotlib==3.8.2
numpy==1.26.3
packaging==23.2
pillow==10.2.0
platformdirs==4.1.0
pooch==1.8.0
protobuf==3.20.3
psutil==5.9.7
pyansys-tools-versioning==0.5.0
pyiges==0.3.1
pyparsing==3.1.1
python-dateutil==2.8.2
pyvista==0.43.1
requests==2.31.0
scipy==1.11.4
scooby==0.9.2
six==1.16.0
tqdm==4.66.1
urllib3==2.1.0
vtk==9.3.0
zipp==3.17.0

📝 Logger output file

Show the logger output file.


===============================================================================
       NEW SESSION - 01/04/2024, 20:39:25
===============================================================================
LEVEL - INSTANCE NAME - MODULE - FUNCTION - MESSAGE
DEBUG - pymapdl_global -  launcher - launch_mapdl - No IP address was supplied. Using the default IP address: 127.0.0.1
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using default port 50052
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using 'start_instance' equal to True
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using default executable.
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using default run location.
DEBUG - pymapdl_global -  launcher - launch_mapdl - Created run location at C:\Users\dell\AppData\Local\Temp\ansys_kulhaskirp
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using run location at C:\Users\dell\AppData\Local\Temp\ansys_kulhaskirp
DEBUG - pymapdl_global -  launcher - check_lock_file - Checking for lock file
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using mode grpc
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using additional switches -smp.
DEBUG - pymapdl_global -  launcher - launch_mapdl - Using start parameters {'exec_file': 'C:\\Program Files\\ANSYS Inc\\v221\\ansys\\bin\\winx64\\ansys221.exe', 'run_location': 'C:\\Users\\dell\\AppData\\Local\\Temp\\ansys_kulhaskirp', 'additional_switches': '-smp', 'jobname': 'file', 'nproc': 2, 'print_com': False, 'ram': None, 'override': False, 'timeout': 45}
DEBUG - pymapdl_global -  launcher - launch_mapdl - Checking license server.
DEBUG - pymapdl_global -  launcher - launch_mapdl - Starting MAPDL
DEBUG - pymapdl_global -  launcher - launch_grpc - Starting 'launch_mapdl'.
DEBUG - pymapdl_global -  launcher - check_lock_file - Checking for lock file
DEBUG - pymapdl_global -  launcher - launch_grpc - Writing temporary input file: .__tmp__.inp with 'FINISH' command.
DEBUG - pymapdl_global -  launcher - launch_grpc - Starting MAPDL with command: "C:\Program Files\ANSYS Inc\v221\ansys\bin\winx64\ansys221.exe" -j file -np 2  -b -i .__tmp__.inp -o .__tmp__.out -smp -port 50052 -grpc
INFO - pymapdl_global -  launcher - launch_grpc - Running in 127.0.0.1:50052 the following command: '"C:\Program Files\ANSYS Inc\v221\ansys\bin\winx64\ansys221.exe" -j file -np 2  -b -i .__tmp__.inp -o .__tmp__.out -smp -port 50052 -grpc'
DEBUG - pymapdl_global -  launcher - launch_grpc - MAPDL starting in background.
DEBUG - pymapdl_global -  launcher - launch_grpc - Generating queue object for stdout
DEBUG - pymapdl_global -  launcher - launch_grpc - Checking process is alive
DEBUG - pymapdl_global -  launcher - launch_grpc - Checking file error is created
DEBUG - pymapdl_global -  licensing - _check_license_file_iterator - PyMAPDL is taking longer than expected to connect to an MAPDL session.
Checking if there are any available licenses...
DEBUG - pymapdl_global -  launcher - _check_file_error_created - MAPDL session successfully started (Error file found)
DEBUG - GRPC_127.0.0.1:50052 -  mapdl - __init__ - Logging set to DEBUG
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - __init__ - Creating channel to 127.0.0.1:50052
DEBUG - pymapdl_global -  licensing - _check_license_file_iterator - Output from C:\Users\dell\AppData\Local\Temp\.ansys\licdebug.dell-dellpc.FEAT_ANSYS.221.out:
2024/01/04 20:39:35    INFO                Starting Licensing Client Proxy server.
2024/01/04 20:39:35    INFO                C:\Program Files\ANSYS Inc\v221\licensingclient\winx64\ansyscl.exe -acl 24248.11185 -nodaemon -log C:\Users\dell\AppData\Local\Temp\.ansys\ansyscl.dell-dellpc.24248.11185.log

DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _create_channel - Opening insecure channel at 127.0.0.1:50052
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _multi_connect - Connection attempt 1
DEBUG - pymapdl_global -  licensing - _check_license_file_iterator - Output from C:\Users\dell\AppData\Local\Temp\.ansys\licdebug.dell-dellpc.FEAT_ANSYS.221.out:
2024/01/04 20:39:35    INFO                Started ANSYSLI server.

DEBUG - pymapdl_global -  licensing - _check_license_file_iterator - Output from C:\Users\dell\AppData\Local\Temp\.ansys\licdebug.dell-dellpc.FEAT_ANSYS.221.out:
2024/01/04 20:39:38    CLIENT_CONNECT                                                                                           1/1/1/1   24248:FEAT_ANSYS:dell@dell-dellpc.DIR.dell.com:winx64     6896:192.168.178.50 

DEBUG - pymapdl_global -  licensing - _check_license_file_iterator - Output from C:\Users\dell\AppData\Local\Temp\.ansys\licdebug.dell-dellpc.FEAT_ANSYS.221.out:
2024/01/04 20:39:38    NEW_CONNECTION      Connected to Licensing Client Proxy server: 52806@127.0.0.1.

DEBUG - pymapdl_global -  licensing - _check_license_file_iterator - Output from C:\Users\dell\AppData\Local\Temp\.ansys\licdebug.dell-dellpc.FEAT_ANSYS.221.out:
2024/01/04 20:39:43    DENIED              ansys                           22.1 (2021.1108)             1/0/0/0                 1/1/1/1   24248:FEAT_ANSYS:dell@dell-dellpc.DIR.dell.com:winx64     6896:192.168.178.50 
		Request name ansys does not exist in the licensing pool.
		No such feature exists.
		Feature:       ansys
		License path:  1055@199.6.204.157;
		FlexNet Licensing error:-5,147

DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _multi_connect - Connection attempt 2
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _connect - Established connection to MAPDL gRPC
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _multi_connect - Connected
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - __init__ - Connection established
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - __init__ - Attached MAPDL object to MapdlMesh.
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
DEBUG - GRPC_127.0.0.1:50052 -  mapdl - __enter__ - Caching routine Begin level
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
DEBUG - GRPC_127.0.0.1:50052 -  mapdl - __exit__ - Restoring routine Begin level
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
INFO - GRPC_127.0.0.1:50052 -  mapdl - run - /SHOW SWITCH PLOTS TO  PNG         - RASTER MODE.
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
INFO - GRPC_127.0.0.1:50052 -  mapdl - run - PARAMETER  = C:\Users\dell\AppData\Local\Temp\ansys_kulhaskirp
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
INFO - GRPC_127.0.0.1:50052 -  mapdl - run - PARAMETER  = C:\Users\dell\AppData\Local\Temp\ansys_kulhaskirp
DEBUG - pymapdl_global -  launcher - launch_mapdl - Stopping license server check.
DEBUG - pymapdl_global -  licensing - is_connected - PyMAPDL has connected to a MAPDL session.
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
INFO - GRPC_127.0.0.1:50052 -  mapdl - run - *** ANSYS - ENGINEERING ANALYSIS SYSTEM  RELEASE 2022 R1          22.1     ***
 Ansys Mechanical Enterprise Solver                
 00000000  VERSION=WINDOWS x64   20:39:47  JAN 04, 2024 CP=      0.375

                                                                               



          ***** ANSYS ANALYSIS DEFINITION (PREP7) *****
DEBUG - GRPC_127.0.0.1:50052 -  mapdl - __enter__ - Entering chained command mode
DEBUG - GRPC_127.0.0.1:50052 -  mapdl - __exit__ - Entering chained command mode
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
INFO - GRPC_127.0.0.1:50052 -  mapdl - run - PARAMETER  = C:\Users\dell\AppData\Local\Temp\ansys_kulhaskirp
DEBUG - pymapdl_global -  launcher - get_start_instance - PYMAPDL_START_INSTANCE is unset, using default value True
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - exit - Exiting MAPDL
DEBUG - GRPC_127.0.0.1:50052 -  mesh_grpc - _reset_cache - Resetting cache
INFO - GRPC_127.0.0.1:50052 -  mapdl - run - PARAMETER  = C:\Users\dell\AppData\Local\Temp\ansys_kulhaskirp
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_server - Killing MAPDL server
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _ctrl - Issuing CtrlRequest "EXIT"
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_server - Killing MAPDL server
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _ctrl - Issuing CtrlRequest "EXIT"
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_process - Killing process using subprocess.Popen.terminate
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_child_process - Killing MAPDL process: 27332
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_child_process - Process 27332 killed properly.
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_child_process - Killing MAPDL process: 24248
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_child_process - Process 24248 killed properly.
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_child_process - Killing MAPDL process: 13180
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_child_process - Process 13180 killed properly.
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _remove_lock_file - Removing lock file after exit.
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_server - Killing MAPDL server
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _ctrl - Issuing CtrlRequest "EXIT"
DEBUG - GRPC_127.0.0.1:50052 -  mapdl_grpc - _kill_process - Killing process using subprocess.Popen.terminate


@pmaroneh
Copy link
Contributor

pmaroneh commented Jan 5, 2024

Thanks for reporting this @lunabrun.
I'm wondering whether there is some link with issue 2564 .
@germa89 @FredAns @pthieffry FYI

@germa89
Copy link
Collaborator

germa89 commented Jan 5, 2024

Ohh.. this is very interesting....... I shall have a look the coming weeks. I cannot give an ETA yet.

@germa89
Copy link
Collaborator

germa89 commented Feb 14, 2024

Hi @lunabrun

Thank you a lot for opening this issue. Indeed, there is a significant performance decrease across latest versions.

The reason for that is the session ID check, which was not properly set to not check the ID every command we send. Now I have disabled it.

I ran the following code:

from ansys.mapdl.core import launch_mapdl
import time

mapdl = launch_mapdl(additional_switches="-smp", log_apdl="main2.txt")  # "-smp" or "-dmp"
mapdl.prep7()
tic = time.time()
with mapdl.non_interactive:
    for el in range(400):
        elansys = el + 1
        mapdl.mp(
            "EX", elansys, elansys
        )  # or mapdl.mp("EX", elansys, elansys, mute=True)
tac = time.time()
print("--- Elapsed time in loop: %s seconds ---" % (tac - tic))

getting:

Version Time (approx)
0.65.2 0.3s
0.67 0.8s
#2778 0.3s

PR #2778 should fix this issue.

Thank you a lot for posting this!

@germa89 germa89 self-assigned this Feb 14, 2024
@lunabrun
Copy link
Author

Hi @germa89,

thanks for taking a look on the matter and correcting it!
Then it makes sense that this issue only got obvious (at least to me) in loops with the same command being called hundreds of times.

@lunabrun
Copy link
Author

lunabrun commented Mar 14, 2024

Hello,

the issue is already closed, so this post might not be really necessary, but I only re-run all the tests recently.
Just wanted to confirm, the performance as far as this issue goes is for the 0.68.0 again at the level of the 0.65.2.

The graphic below summarizes the results:
Version_vs_Execution_time_incl_068
Legend:
SMP: Shared Memory Parallel
DMP: Distributed Memory Parallel
CC: Use of "with.mapdl.chain.command"
NI: Use of "with.mapdl.non_interactive"
MT: Use of "mute=True"
BC: Base case, i.e., none of CC/NI/MT.

All times shown in the figure above are average of four runs. Please see file below for the results of all runs:
Elapsed_Times_report.xlsx

@germa89
Copy link
Collaborator

germa89 commented Apr 1, 2024

Hi @lunabrun

Thank you a lot for checking this out again! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants