Borrar filtros
Borrar filtros

MATLAB On High Performance Computing (HPC)

9 visualizaciones (últimos 30 días)
Mohamed AKI Ahmed
Mohamed AKI Ahmed el 10 de Jul. de 2023
Respondida: Ayush Kashyap el 10 de Jul. de 2023
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

Respuestas (1)

Ayush Kashyap
Ayush Kashyap el 10 de Jul. de 2023
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'.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by