How to execute Matlab program on a HPC cluster with passing data through argument?
How to execute Matlab program on a HPC cluster with passing data through argument?
I have a MATLAB program needed to be run on a HPC cluster. What I want to do is running the program with passing data in the argument.
addpath('path')
savepath
% a and b need to be passed through an argument
c = addition(a,b);
fileID=fopen('test.txt','w');
fprintf(fileID,'Numn');
fprintf(fileID,'%fn',c);
fclose(fileID);
I have two questions:
1. How to write the argument to pass the data?
2. How to write code in MATLAB to get the data passed from the argument?
Thank you in advance.
1 Answer
1
You can either write an Matlab m-file script (for example here named mymfile.m) with your arguments and run that on the cluster as (it may need to be started with a shell script depending on your cluster)
matlab -r mymfile.m
(note that only scripts can be run like this, not Matlab functions (although functions can be called from the script)). Or alternatively you can just run pure commands explicitly as
matlab -r 'addpath('path'),savepath,c=addition(a,b); ... , exit'
where you would maybe pass a and b from the shell script. If you use a linux cluster/server and want to execute multiple parameter runs of the same Matlab script one can use xargs.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.