I run matlab in linux with a batch like this:
===matlab_batch.sh===============
#!/bin/bash
#this is my bash program to run matlab code matlab_program.m
#repeatedly without GUI
loopindices="1 2 3 4 5"
for loopind in $loopindices
do
echo running matlab $loopind
matlab -nodesktop <matlab_program
$loopind
EOF1
echo finished running matlab $loopind
done
==================
where matlab_program is another matlab code (matlab_program.m) which can run
in matlab command line prompt and it takes an integer $loopind as input
from matlab command line.
The code above (matlab_batch.sh) runs well, however, as the index $loopind
increases from 1 to 5, it slows down like crazy! Even if each time the
actual matlab program matlab_program.m is doing the same exact thing!!!
So what is going on with consecutive matlab processes being initialized from
linux shell ??? The "EOF1 EOF1" section above is a usual trick for
bash in linux to call a non-bash program like matlab. Within each for loop
of loopind, a matlab is invoked and then closed after matlab_program
finishes. So does an earlier matlab process affect a later matlab process?
If it does, how and why? Matlab must be leaking a lot of memory. Oops, my
program takes 2 hours to run when loopind =1, yet it takes 20 hrs to run by
the time loopind=5....
My program is not trivial (took me long time to code it up) to and it is
painstaking to see it would slow down like this. I have 24G memory on a
cluster and the matlab program is running on head node without any
parallelization.
Mathworks must be doing a very bad job in memory management especially with
the newer versions of matlab. Oops, time to abandon matlab for me.