MATLAB On High Performance Computing (HPC)

16 ビュー (過去 30 日間)
Mohamed AKI Ahmed
Mohamed AKI Ahmed 2023 年 7 月 10 日
回答済み: Ayush Kashyap 2023 年 7 月 10 日
Hello all,
I have a python code that calles a MATLAB compiled file many times during a single run to get information from a model built in MATLAB. When I run this code on Windows, it doesn't take time since I have MATLAB installed on my machine. To use the speed of HPC, when I run the model there, it takes a very long time to get my result (triple the speed on Windows). I wanted to ask if there is anyway to speed the process. I tried using MCR but still, it is quite slow

回答 (1 件)

Ayush Kashyap
Ayush Kashyap 2023 年 7 月 10 日
Hi Mohamed,
To reslove the issue of speed of performance, you make try these two ways mainly:
  • You may try out parallelization and other techniques of optimizing your code and see if your performance improves.
  • If the problem still persists, then it must be due to delays in launching Matlab Runtime Environment multiple times. In this case you can try caching by using a Python Dictionary to store the results and try to avoid multiple access to the original Matlab file.
I am attaching a simple example of implementing caching using python dictionary:
def cache_function(*inputs):
if inputs in cache_dict:
return cache_dict[inputs]
else:
result = call_matlab_compiled_file(*inputs)
cache_dict[inputs] = result
return result
Don't forget to replace your direct calls to Matlab files as follows:
cache_dict = {}
result = cache_function(input1, input2, ...)
Hope this helps resolve your problem.
Alternatively, you may also try out other libraries like 'functools.lru_cache' or 'cachetools'.

カテゴリ

Help Center および File ExchangePython Package Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by