- 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.
MATLAB On High Performance Computing (HPC)
7 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Ayush Kashyap
2023-7-10
Hi Mohamed,
To reslove the issue of speed of performance, you make try these two ways mainly:
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'.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Python Package Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!