-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added debugMode for Master and Slaves. - in default mode master and slaves do not print the status or data information. modified: examples/demoCV.m modified: findMatlabPath.m modified: getBestParamIdx.m modified: getWorkersPids.m modified: launchWorkers.m modified: startMaster.m modified: startSlave.m modified: terminateSlaves.m
- Loading branch information
1 parent
cee05d8
commit 40a9b1d
Showing
8 changed files
with
85 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
%FINDMATLABPATH Summary of this function goes here | ||
% Detailed explanation goes here | ||
% created 07-03-2018 | ||
% last modification -- -- -- | ||
% last modification 07-30-2018 | ||
% Okba Bekhelifi, <[email protected]> | ||
|
||
% matlabPath = strcat( matlabroot, '\bin\matlab.exe'); | ||
matlabPath = sprintf('%s%s',matlabroot,'\bin\matlab.exe'); | ||
matlabPath = [matlabroot, '\bin\matlab.exe']; | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,7 @@ | |
% created 06-20-2018 | ||
% last modification -- -- -- | ||
% Okba Bekhelifi, <[email protected]> | ||
|
||
% [~,result] = system('tasklist /FI "imagename eq matlab.exe" /fo table /nh'); | ||
[~,result] = jsystem('tasklist /FI "imagename eq matlab.exe" /fo table /nh'); | ||
% pid_raw = strsplit(result,' '); | ||
pid_raw = splitstr(result,' '); | ||
pid_raw(cellfun('isempty',pid_raw)) = []; | ||
row = 5; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
function [pids] = launchWorkers(max_instances) | ||
function [pids] = launchWorkers(max_instances, debugMode) | ||
%LAUNCHWORKERS Summary of this function goes here | ||
% Detailed explanation goes here | ||
% created 06-20-2018 | ||
% last modification -- -- -- | ||
% last modification 07-30-2018 | ||
% Okba Bekhelifi, <[email protected]> | ||
matlabPath = ['"' findMatlabPath '"']; | ||
opts = ' -nodisplay -nosplash -nodesktop -noawt -r'; | ||
scriptToRun = ' run(''startSlave.m'');"'; | ||
% cmdToRun = strcat(matlabPath, opts, scriptToRun); | ||
% cmdToRun = CStrCatStr({matlabPath}, {opts}, {scriptToRun}); | ||
scriptToRun = [' run(''startSlave(',sprintf('%d',debugMode),')'');" ']; | ||
cmdToRun = [matlabPath, opts, scriptToRun]; | ||
for i = 1:(max_instances) | ||
% system(cmdToRun); | ||
jsystem(cmdToRun, 'noshell'); | ||
end | ||
pids = getWorkersPids(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
function [] = startSlave | ||
function [] = startSlave(debugMode) | ||
%STARTSLAVE Summary of this function goes here | ||
% Detailed explanation goes here | ||
% created 06-20-2018 | ||
% last modification -- -- -- | ||
% Okba Bekhelifi, <[email protected]> | ||
clc; | ||
fprintf('Recovering shared memory.\n'); | ||
if(debugMode) | ||
fprintf('Recovering shared memory.\n'); | ||
end | ||
wPids = getWorkersPids(); | ||
nWorkers = length(wPids); | ||
[~, workerRank] = find(sort(cellfun(@str2num, wPids))==feature('getPid')); | ||
% pid = num2str(workerRank); | ||
pid = sprintf('%d', workerRank); | ||
clear wPids | ||
% Set IPC | ||
masterPorts = 9091:9091+nWorkers; | ||
slavePorts = 9191:9191+nWorkers; | ||
fprintf('Worker %d Opening communication channel on port: %d\n', ... | ||
feature('getPid'), ... | ||
slavePorts(workerRank)... | ||
); | ||
if(debugMode) | ||
fprintf('Worker %d Opening communication channel on port: %d\n', ... | ||
feature('getPid'), ... | ||
slavePorts(workerRank)... | ||
); | ||
end | ||
slaveSocket = udp('Localhost', masterPorts(workerRank), ... | ||
'LocalPort', slavePorts(workerRank)... | ||
); | ||
fopen(slaveSocket); | ||
clear masterPorts slavePorts | ||
|
||
% Recover Shared Memory | ||
fHandle = SharedMemory('attach', 'shared_fhandle'); | ||
datacell = SharedMemory('attach', 'shared_data'); | ||
if(debugMode) | ||
fprintf('Data recovery succeded\n'); | ||
end | ||
param = SharedMemory('attach', ['shared_' pid]); | ||
workerResult = cell(1, length(param)); | ||
|
||
% Evaluate Functions | ||
fprintf('Worker %s Evaluating job\n', pid); | ||
% fprintf('Evaluatating function: %s\n', fhandle); | ||
|
||
if(debugMode) | ||
fprintf('Worker %s Evaluating job\n', pid); | ||
% fprintf('Evaluatating function: %s\n', fHandle); | ||
end | ||
if(isstruct(fHandle) && isstruct(datacell)) | ||
% Train & Predict mode | ||
mode = 'double'; | ||
|
@@ -68,28 +75,32 @@ | |
end | ||
end | ||
% Detach SharedMemroy | ||
fprintf('Worker %s Detaching sharedMemory\n', pid); | ||
if(debugMode) | ||
fprintf('Worker %s Detaching sharedMemory\n', pid); | ||
end | ||
SharedMemory('detach', 'shared_fhandle', fHandle); | ||
SharedMemory('detach', 'shared_data', datacell); | ||
SharedMemory('detach', ['shared_' pid], param); | ||
clear fhandle datacell param | ||
% | ||
% Write results in SharedMemory | ||
fprintf('Worker %s Writing results in sharedMemory\n', pid); | ||
resKey = ['res_' pid]; | ||
fprintf('Worker %s shared result key %s\n', pid, resKey); | ||
if(debugMode) | ||
fprintf('Worker %s Writing results in sharedMemory\n', pid); | ||
fprintf('Worker %s shared result key %s\n', pid, resKey); | ||
end | ||
SharedMemory('clone', resKey, workerResult); | ||
|
||
fprintf('Opening slave socket\n'); | ||
fprintf('writing data to socket \n'); | ||
|
||
if(debugMode) | ||
fprintf('Opening slave socket\n'); | ||
fprintf('writing data to socket \n'); | ||
end | ||
fprintf(slaveSocket, '%d', feature('getPid')); | ||
% fwrite(slaveSocket, feature('getPid'), 'int32'); | ||
|
||
fprintf('Data sent : %d to %d\n',... | ||
slaveSocket.ValuesSent, ... | ||
slaveSocket.propinfo.RemotePort.DefaultValue... | ||
); | ||
if(debugMode) | ||
fprintf('Data sent : %d to %d\n',... | ||
slaveSocket.ValuesSent, ... | ||
slaveSocket.propinfo.RemotePort.DefaultValue... | ||
); | ||
end | ||
fclose(slaveSocket); | ||
delete(slaveSocket); | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,9 @@ | |
% date created 06-14-2018 | ||
% last modified -- -- -- | ||
% Okba Bekhelifi, <[email protected]> | ||
|
||
% [~,result] = system('tasklist /FI "imagename eq matlab.exe" /fo table /nh'); | ||
% pid_raw = strsplit(result,' '); | ||
% row = 5; | ||
% col = (length(pid_raw) - 1) / row; | ||
% pid_raw = reshape(pid_raw(1:end-1), row, col); | ||
|
||
pids = getWorkersPids(); | ||
|
||
for proc = 1:length(pids) | ||
% system(['taskkill -f -PID ' pid_raw{2, proc}]); | ||
% system(['taskkill -f -PID ' pids{proc}]); | ||
jsystem(['taskkill -f -PID ' pids{proc}]); | ||
end | ||
|
||
end | ||
|