Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into cbrain_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
poquirion committed May 25, 2016
2 parents dc858ab + 446887f commit 0f791b8
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 72 deletions.
4 changes: 2 additions & 2 deletions psom_clean.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
if nargin < 2
opt = struct();
end
if isbool(opt)
if islogical(opt)
opt = struct('flag_verbose',opt);
end
opt = psom_struct_defaults(opt,{'flag_verbose'},{true});
Expand Down Expand Up @@ -127,4 +127,4 @@
else
warning(['I could not find the file or folder ' file_name]);
end
end
end
19 changes: 4 additions & 15 deletions psom_deamon.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@

if (nb_resub<opt.nb_resub)||~flag_started(num_w)
if num_w <= opt.max_queued
[flag_failed,msg] = psom_run_script(cmd_worker{num_w},script_worker{num_w},opt_worker(num_w),opt_logs_worker(num_w),opt.flag_verbose);
[flag_failed,msg] = psom_run_script(cmd_worker{num_w},script_worker{num_w},opt_worker(num_w),opt_logs_worker(num_w));
elseif num_w == opt.max_queued+1
[flag_failed,msg] = psom_run_script(cmd_pipe,script_pipe,opt_pipe,opt_logs_pipe,opt.flag_verbose);
[flag_failed,msg] = psom_run_script(cmd_pipe,script_pipe,opt_pipe,opt_logs_pipe);
elseif num_w == opt.max_queued+2
[flag_failed,msg] = psom_run_script(cmd_garb,script_garb,opt_garb,opt_logs_garb,opt.flag_verbose);
[flag_failed,msg] = psom_run_script(cmd_garb,script_garb,opt_garb,opt_logs_garb);
end
if ~flag_failed
flag_wait(num_w) = true;
Expand Down Expand Up @@ -355,7 +355,7 @@
time = clock;
save(file_end,'time');
end
sub_sleep(opt.time_between_checks)
pause(opt.time_between_checks)
flag_pipe_finished = ~psom_exist(file_pipe_running);
end

Expand Down Expand Up @@ -391,14 +391,3 @@
end
status_pipe = 0;
end

%%%%%%%%%%%%%%%%%%
%% subfunctions %%
%%%%%%%%%%%%%%%%%%
function [] = sub_sleep(time_sleep)

if exist('OCTAVE_VERSION','builtin')
[res,msg] = system(sprintf('sleep %1.3f',time_sleep));
else
pause(time_sleep);
end
29 changes: 12 additions & 17 deletions psom_garbage.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@
end

%% Start heartbeat
main_pid = getpid;
if exist('OCTAVE_VERSION','builtin')
main_pid = getpid;
else
main_pid = feature('getpid');
end
cmd = sprintf('psom_heartbeat(''%s'',''%s'',%i)',file_heartbeat,file_kill,main_pid);
if strcmp(gb_psom_language,'octave')
instr_heartbeat = sprintf('"%s" %s "addpath(''%s''), %s,exit"',gb_psom_command_octave,gb_psom_opt_matlab,gb_psom_path_psom,cmd);
Expand Down Expand Up @@ -180,16 +184,16 @@
end

%% Update the status/logs/profile
save(file_logs,'-struct','-append','new_logs');
save(file_logs_backup,'-struct','-append','new_logs');
save(file_status,'-struct','-append','new_status');
save(file_status_backup,'-struct','-append','new_status');
save(file_profile,'-struct','-append','new_prof');
save(file_profile_backup,'-struct','-append','new_prof');
save(file_logs,'-append','-struct','new_logs');
save(file_logs_backup,'-append','-struct','new_logs');
save(file_status,'-append','-struct','new_status');
save(file_status_backup,'-append','-struct','new_status');
save(file_profile,'-append','-struct','new_prof');
save(file_profile_backup,'-append','-struct','new_prof');

%% Wait if necessary
if flag_nothing_happened && psom_exist(file_pipe_running)
sub_sleep(opt.time_between_checks)
pause(opt.time_between_checks)

if (nb_checks >= opt.nb_checks_per_point)
nb_checks = 0;
Expand Down Expand Up @@ -266,12 +270,3 @@
events{num_e,1} = news_line{num_e}(1:pos-1);
events{num_e,2} = news_line{num_e}(pos+3:end);
end

%% Work around thee 'pause' bug in octave
function [] = sub_sleep(time_sleep)

if exist('OCTAVE_VERSION','builtin')
[res,msg] = system(sprintf('sleep %1.3f',time_sleep));
else
pause(time_sleep);
end
10 changes: 3 additions & 7 deletions psom_heartbeat.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
if exist('OCTAVE_VERSION','builtin')
[err,msg] = kill(pid,0); % use the kill octave command
else
[err,msg] = system(sprintf('kill %i',pid)); % kill is not available, try a system call
[err,msg] = system(sprintf('kill -0 %i',pid)); % kill is not available, try a system call
end
flag_beat = err==0;
curr_time = clock;
Expand All @@ -64,10 +64,6 @@
end
exit
end
if exist('OCTAVE_VERSION','builtin')
[res,msg] = system('sleep 5');
else
sleep(5);
end
pause(5);
end


16 changes: 6 additions & 10 deletions psom_manager.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
end

%% Start heartbeat
main_pid = getpid;
if exist('OCTAVE_VERSION','builtin')
main_pid = getpid;
else
main_pid = feature('getpid');
end
cmd = sprintf('psom_heartbeat(''%s'',''%s'',%i)',file_heartbeat,file_kill,main_pid);
if strcmp(gb_psom_language,'octave')
instr_heartbeat = sprintf('"%s" %s "addpath(''%s''), %s,exit"',gb_psom_command_octave,gb_psom_opt_matlab,gb_psom_path_psom,cmd);
Expand Down Expand Up @@ -324,7 +328,7 @@
%% Sleep if nothing happened
flag_loop = (any(mask_todo) || any(mask_running)) && psom_exist(file_pipe_running) && ~psom_exist(file_pipe_end);
if flag_nothing_happened && flag_loop
sub_sleep(opt.time_between_checks)
pause(opt.time_between_checks)

if (nb_checks >= opt.nb_checks_per_point)
nb_checks = 0;
Expand Down Expand Up @@ -471,11 +475,3 @@
fprintf('%s',str_write)
end
fprintf(file_write,'%s',str_write);

function [] = sub_sleep(time_sleep)

if exist('OCTAVE_VERSION','builtin')
[res,msg] = system(sprintf('sleep %1.3f',time_sleep));
else
pause(time_sleep);
end
6 changes: 1 addition & 5 deletions psom_pipeline_visu.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,7 @@
flag_wait = ~psom_exist(file_monitor) && psom_exist(file_pipe_running);
while flag_wait % the pipeline started but the log file has not yet been created
fprintf('I could not find any log file. This pipeline has not been started (yet?). Press CTRL-C to cancel.\n');
if exist('OCTAVE_VERSION','builtin')
[res,msg] = system('sleep 1');
else
sleep(1);
end
pause(1);
flag_wait = ~psom_exist(file_monitor) && psom_exist(file_pipe_running) && (nargin<3);
end

Expand Down
8 changes: 2 additions & 6 deletions psom_run_pipeline.m
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@
else
script_deamon = [path_deamon filesep 'psom_deamon.sh'];
end
[flag_failed,msg] = psom_run_script(cmd_deamon,script_deamon,opt_script,opt_logs,opt.flag_verbose);
[flag_failed,msg] = psom_run_script(cmd_deamon,script_deamon,opt_script,opt_logs);

%% If not in session mode, monitor the output of the pipeline
flag_exit = false;
Expand All @@ -517,11 +517,7 @@
nb_chars_old = nb_chars;
nb_chars = psom_pipeline_visu(opt.path_logs,'monitor',nb_chars);
if ~any(nb_chars ~= nb_chars_old)
if exist('OCTAVE_VERSION','builtin')
[res,msg] = system('sleep 0.2');
else
sleep(0.2);
end
pause(0.2);
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions psom_struct_defaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
%
% FLAG_WARNING
% (boolean, default true) if FLAG_WARNING is true, issue warnings for
% unrecognized fields and remove them. Otherwise do nothing about
% unrecognized fields.
%
% _________________________________________________________________________
Expand All @@ -43,8 +44,8 @@
% i.e. they won't be copied into OPT_UP.
%
% Copyright (c) Pierre Bellec, Centre de recherche de l'institut de
% Gériatrie de Montréal, Département d'informatique et de recherche
% opérationnelle, Université de Montréal, 2010
% Griatrie de Montral, Dpartement d'informatique et de recherche
% oprationnelle, Universit de Montral, 2010
% Maintainer : [email protected]
% See licensing information in the code.

Expand Down
16 changes: 8 additions & 8 deletions psom_worker.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@
end

%% Start a heartbeat
main_pid = getpid;
if exist('OCTAVE_VERSION','builtin')
main_pid = getpid;
else
main_pid = feature('getpid');
end
cmd = sprintf('psom_heartbeat(''%s'',''%s'',%i)',file_heartbeat,file_kill,main_pid);
if strcmp(gb_psom_language,'octave')
instr_heartbeat = sprintf('"%s" %s "addpath(''%s''), %s,exit"',gb_psom_command_octave,gb_psom_opt_matlab,gb_psom_path_psom,cmd);
Expand Down Expand Up @@ -170,7 +174,7 @@
new_prof.time_scheduled = time_scheduled.(name_job);
new_prof.time_running = time_running.(name_job);
new_prof.worker = num_worker;
save(file_prof_job,'-struct','-append','new_prof');
save(file_prof_job,'-append','-struct','new_prof');
end

test_loop = psom_exist(file_lock)&&(~flag_end||(num_job<length(list_jobs)));
Expand All @@ -180,11 +184,7 @@
end

if (num_job == length(list_jobs))&&test_loop
if exist('OCTAVE_VERSION','builtin')
[res,msg] = system('sleep 0.1');
else
sleep(0.1);
end
pause(0.1);
end
end % While there are jobs to do

Expand Down Expand Up @@ -216,4 +216,4 @@
else
str_txt = fread(hf,Inf,'uint8=>char')';
fclose(hf);
end
end

0 comments on commit 0f791b8

Please sign in to comment.