-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqsub.m
102 lines (94 loc) · 3.63 KB
/
mqsub.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
%% This function submits another function to the queue
% Ideally I'd like this to handle data transfer on its own. Perhaps by
% having matlab write the result of the function to a mat file in a
% temporary working directory, and then retrieving it.
%
% The function called must live in the current directory when mqsub is
% called. The function probably needs all of its non-core matlab
% dependencies in this directory as well.
%
% The function must be referenced by a string containing its name as the
% first argument to mqsub.
%
% The second argument to mqsub is an arraylist containing the arguments
% that will be passed to the function.
%
% Subsequent arguments must come in a standard matlab 'Name','Value'
% pairing and control SLURM job submission flags, such as the number of
% cores to use.
%
% Warning: do not oversave the function during an mqsub call. A workaround
% is to make sure that a function has arguments that allow you to make any
% necessary adjustments by calling the function with different parameters.
%
% Warning: do not call tic or toc without arguments or use global variables
% while submitting jobs to be parallel processed.
%
% Example Call to the function:
% mqsub('simdecel',{},'Name','Brian_Compare','Cores',5,'Queue','batch')
function results = mqsub(varargin)
fname = varargin{1};
fargs = varargin{2};
if ~exist(fname,'file')
error(['Function ' fname ' is not found. Change directories, son.']);
end
job = struct(...
'Name','test_mqsub',...
'Cores',8,...
'Memory',1,... % memory requested in GB
'Partition','jila',... % jila, long, slow, standby
'Time','20:00:00',... %DD-HH:MM:SS
'Data','../Cluster' ...
);
for i=3:2:length(varargin)
fn = varargin{i};
if isfield(job,fn)
job.(fn) = varargin{i+1};
else
error(['Field ' fn ' not recognized.'])
end
end
startdirec = pwd;
t = datestr(now,'mmmm-dd-yyyy_HH-MM-SS');
dirname = [job.Data '/' job.Name '_' t];
mkdir(dirname)
cd(dirname);
datadirec = pwd;
save('fargs.mat','fargs');
fidm = fopen('mqsubwrap.m','w');
fprintf(fidm,[...
'%%%% Temporary Script for Qsubbing a matlab function \n',...
'%% Dave Reens, 4/28/15 \n',...
'cd %s \n',...
'fprintf(''%%s: Opening Pool.\\n'',datestr(now,''HH-MM-SS'')) \n',...
'parpool(%d) \n',...
'args = open(''fargs.mat''); \n',...
'args = args.fargs; \n',...
'cd %s ; \n',...
'fprintf(''%%s: Running Func.\\n'',datestr(now,''HH-MM-SS'')) \n',...
'r = %s(args{:}); \n',...
'cd %s ; \n',...
'save(''results_%s.mat'',''r''); \n',...
],datadirec,job.Cores,startdirec,fname,datadirec,job.Name);
fclose(fidm);
fidj = fopen('mqsubjob','w');
fprintf(fidj,[...
'#!/bin/bash \n',...
'module load matlab \n',...
'matlab -nosplash -nodisplay -nodesktop < mqsubwrap.m \n',...
]);
fclose(fidj);
disp('text of job script at time of qsub:')
fileread('mqsubjob')
systemcall = sprintf('sbatch -J %s -N 1 -n %d -t %s -p %s --mem=%dG mqsubjob',...
job.Name, job.Cores, job.Time, job.Partition, job.Memory);
disp('executing the following:')
disp(systemcall)
system(systemcall);
%delete('mqsubjob');
%delete('mqsubwrap')
cd(startdirec);
pause(0.05)
%system('squeue | grep dare');
results = 0;
end