I'm currently working with a project where I use python functions wrapped in a module within a matlab code. The matlab part of the code is a MCMC (monte carlo multi chains) computation, therefore for speeding up the code I'm using a parfor loop on a cluster.
To be more specific the algorithm can be thought as follow:
- for i=1:number of chain steps(==number of iterations)
- parfor j=1:number of chains(==number of workers)
- load the module and use python functions defined there
- end
- do something related to the evolution of the chains
- end
My problem is that the only way I have for matlab to use the python's defined function is to re-load the python module per each parfor iteration, but as the code work this means also per each chain step (the parfor is nested inside) and there I spend some times.
My question is: is there a smarter-faster way to use python libraries within matlab? (something equivalent to MEX-?-) otherwise, is there a way to "store" the python module infos in each worker at the beginning without the need to reload the module every time I step forward in the outer loop as well?
Any hint will be really really appreciated!! Thanks a lot
Giulia