Search code examples
bashmatlabshellterminalgnu-parallel

run matlab scripts in parallel from macos terminal


Let's suppose I have 4 folders into a directory and each folder contains a matlab script example.m.

I want to run these scripts using GNU parallel from a macos terminal.

I correctly installed GNU parallel as per http://macappstore.org/parallel/ and tried the following from the terminal:

parallel ::: */example.m

but I get the following errors:

/bin/bash: 1/example.m: Permission denied

/bin/bash: 2/example.m: Permission denied

/bin/bash: 3/example.m: Permission denied

/bin/bash: 4/example.m: Permission denied

what is missing? shall the script(s) to be run by parallel be in the .sh format?


Solution

  • Disclaimer: I have never run MatLab.

    If you can run:

    /Applications/MATLAB_R2019a.app/bin/matlab -singleCompThread -nojvm -r "run('example1.m');exit;"
    

    Then try this:

    parallel --dry-run -q /Applications/MATLAB_R2019a.app/bin/matlab -singleCompThread -nojvm -r "run('{}');exit;" ::: */example*.m
    

    If the lines it prints out look correctly, remove --dry-run from the command line and run it without --dry-run:

    parallel -q /Applications/MATLAB_R2019a.app/bin/matlab -singleCompThread -nojvm -r "run('{}');exit;" ::: */example*.m