-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparaLonGP.m
78 lines (54 loc) · 1.76 KB
/
paraLonGP.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
function paraLonGP(resDir, iTarget, varargin)
% resDir: directory to store results, ith target variable will be stored in subdirectory "i" under resDir, i.e. "resDir/Results/i"
% iTarget: index of target, 0 is for task manager
% Lu Cheng
% 01.05.2018
%% pre check
global DEBUG
DEBUG=true;
assert(exist(resDir,'dir')>0, sprintf('Result directory %s does not exist!\n',resDir));
paraFile = sprintf('%s%sinput.para.txt',resDir,filesep);
assert(exist(paraFile,'file')>0, sprintf('Parameter file %s does not exist!\n',paraFile));
preprocFile = sprintf('%s%spreprocData.mat',resDir,filesep);
if ~exist(preprocFile,'file')
preprocData(paraFile);
end
load(preprocFile,'normData');
nTarget = normData.Y.nTarget;
clear normData
if DEBUG
fprintf('In paraLonGP, iTarget=%d\n',iTarget);
end
%% run appropriate jobs
targetDir = sprintf('%s%sResults%s%d',resDir,filesep,filesep,iTarget);
if iTarget==0
taskManager(resDir, varargin{:});
elseif iTarget>nTarget
% run slave
if DEBUG
fprintf('run slave, sleep for 60 seconds to wait taskManager. iTarget=%d\n',iTarget);
end
pause(60); % wait for task manager to get ready
slave(targetDir,varargin{:});
else
% run LonGP
if DEBUG
fprintf('run LonGP, sleep for 60 seconds to wait taskManager. iTarget=%d\n',iTarget);
end
pause(60); % wait for task manager to get ready
if ~exist(targetDir,'dir')
mkdir(targetDir);
end
runFile = sprintf('%s%sworker.run.txt',targetDir,filesep);
createFile(runFile);
lonGP(resDir,iTarget);
delFile(runFile);
slave(targetDir,varargin{:});
end
function createFile(filename)
fid = fopen(filename,'w');
fclose(fid);
function delFile(filename)
if exist(filename,'file')>0
delete(filename);
end