How to optimize nested forloops with matrix exponentials

Hi, I'm trying to optimize a piece of code that's essentially something like this
for ii = 1:N1
for jj = 1:N2
for kk = 1:N3
for tt = 1:N4
return(1:size(myMat,1),1:size(myMat,2),ii,jj,kk,tt) = func(myMat,ii,jj,kk,tt);
end
end
end
end
func is some function I've written, the main computational component of which involves a few matrix exponentials of reasonably sized matrices, myMat (64x64). Obviously the reason why it takes so long is the fact that I have 4 nested loops, however I do not see an easy way to vectorize this because func is a fairly complicated function, furthermore I'm running this on MATLAB 2018a, and I've read that the JIT accelerator can make vectorizing not really necessary anymore. My question is if anyone sees any other way to improve performance? I've tried a few other versions of expm floating around on the web and none have been as fast as MATLAB's built-in one. I also have a portion of the code paralellized via parfor, so I do not think that introducing another parfor in here will actually speed this up (in essence this whole block of code is being called via parfor). Any help or guidance would be greatly appreciated.

Asked:

on 10 Apr 2018

Answered:

on 11 Apr 2018

Community Treasure Hunt

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

Start Hunting!