From f1795cb90966fecc40c3d0873a28bcaf24453abf Mon Sep 17 00:00:00 2001 From: ratto <ratto@ac1d8469-bf42-47a9-8791-bf33cf982152> Date: Fri, 15 Jan 2010 10:01:21 +0000 Subject: [PATCH] 1) added ismac for MATLAB >= 7.4 2) some commenting added; 3) eliminated sshfs mounting 4) eliminate use of ifconfig, use hostname utility of linux/unix instead (still may not work for solaris environments?) git-svn-id: https://www.dynare.org/svn/dynare/trunk@3363 ac1d8469-bf42-47a9-8791-bf33cf982152 --- matlab/fMessageStatus.m | 12 +++++++++++- matlab/fParallel.m | 31 ++++++++++++++++--------------- matlab/masterParallel.m | 20 +++++++++++--------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/matlab/fMessageStatus.m b/matlab/fMessageStatus.m index ca7e4c9b31..0cc6d3b31e 100644 --- a/matlab/fMessageStatus.m +++ b/matlab/fMessageStatus.m @@ -1,4 +1,14 @@ function fMessageStatus(prtfrc, njob, waitbarString, waitbarTitle, Parallel, MasterName, DyMo) +% In a parallelization context, this function is launched on slave +% machines, and acts as a message passing device for the master machine. +% prtfrc [double], fraction of iteration performed +% njob [int], index number of this CPU among all CPUs in the +% cluster +% waitbarString [char], running message string to be displayed in the monitor window on master machine +% waitbarTitle [char], title to be displayed in the monitor window on master machine +% Parallel [struct], options_.parallel(ThisMatlab), i.e. the paralle settings for this slave machine in the cluster +% MasterName [char], IP address or PC name of the master +% DyMo [char], working directory of the master machine % Copyright (C) 2009 Dynare Team % @@ -25,7 +35,7 @@ end save(['comp_status_',funcName,int2str(njob),'.mat'],'prtfrc','njob','waitbarString','waitbarTitle'); if Parallel.Local==0, - if isunix, + if isunix || (~matlab_ver_less_than('7.4') && ismac), system(['scp comp_status_',funcName,int2str(njob),'.mat ',Parallel.user,'@',MasterName,':',DyMo]); else copyfile(['comp_status_',funcName,int2str(njob),'.mat'],['\\',MasterName,'\',DyMo(1),'$\',DyMo(4:end),'\']); diff --git a/matlab/fParallel.m b/matlab/fParallel.m index c8d3200201..aaa509636b 100644 --- a/matlab/fParallel.m +++ b/matlab/fParallel.m @@ -6,7 +6,7 @@ function fParallel(fblck,nblck,whoiam,ThisMatlab,fname) % INPUTS % fblck [int] index number of the first thread to run in this % MATLAB instance -% nblck [int] index number of the first thread to run in this +% nblck [int] number of threads to run in this % MATLAB instance % whoiam [int] index number of this CPU among all CPUs in the % cluster @@ -58,19 +58,20 @@ if exist('fGlobalVar'), end % On UNIX, mount the master working directory through SSH FS -if isunix & Parallel(ThisMatlab).Local==0, - system(['mkdir ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]); - system(['sshfs ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':/',fInputVar.DyMo,' ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]); -end - -% Special hack for MH directory -if isfield(fInputVar,'MhDirectoryName') & Parallel(ThisMatlab).Local==0, - if isunix, - fInputVar.MhDirectoryName = ['~/MasterRemoteMirror_',fname,'_',int2str(whoiam),'/',fInputVar.MhDirectoryName]; - else - fInputVar.MhDirectoryName = ['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\',fInputVar.MhDirectoryName]; - end -end +% if (isunix | (~matlab_ver_less_than('7.4') & ismac) ) & Parallel(ThisMatlab).Local==0, +% system(['mkdir ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]); +% system(['sshfs ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':/',fInputVar.DyMo,' ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]); +% end + +% Special hack for MH directory: possibly no longer needed ?????? now all +% files are managed locally and sent backwards later on in this routine! +% if isfield(fInputVar,'MhDirectoryName') & Parallel(ThisMatlab).Local==0, +% if isunix | (~matlab_ver_less_than('7.4') & ismac), +% fInputVar.MhDirectoryName = ['~/MasterRemoteMirror_',fname,'_',int2str(whoiam),'/',fInputVar.MhDirectoryName]; +% else +% fInputVar.MhDirectoryName = ['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\',fInputVar.MhDirectoryName]; +% end +% end fInputVar.Parallel = Parallel; % Launch the routine to be run in parallel @@ -92,7 +93,7 @@ if(whoiam) if Parallel(ThisMatlab).Local delete(['P_',fname,'_',int2str(whoiam),'End.txt']); else - if isunix, + if isunix || (~matlab_ver_less_than('7.4') && ismac), for j=1:size(OutputFileName,1), system(['scp ',OutputFileName{j,1},OutputFileName{j,2},' ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':',fInputVar.DyMo,'/',OutputFileName{j,1}]); end diff --git a/matlab/masterParallel.m b/matlab/masterParallel.m index 8510c52762..0709e98fb0 100644 --- a/matlab/masterParallel.m +++ b/matlab/masterParallel.m @@ -51,8 +51,9 @@ totCPU=0; % Determine my hostname and my working directory DyMo=pwd; fInputVar.DyMo=DyMo; -if isunix, - [tempo, MasterName]=system(['ifconfig | grep ''inet addr:''| grep -v ''127.0.0.1'' | cut -d: -f2 | awk ''{ print $1}''']); +if isunix || (~matlab_ver_less_than('7.4') && ismac) , +% [tempo, MasterName]=system(['ifconfig | grep ''inet addr:''| grep -v ''127.0.0.1'' | cut -d: -f2 | awk ''{ print $1}''']); + [tempo, MasterName]=system('hostname --fqdn'); else [tempo, MasterName]=system('hostname'); end @@ -105,7 +106,7 @@ for j=1:totCPU, fclose(fid1); if Parallel(indPC).Local == 1, % run on the local machine - if isunix, + if isunix || (~matlab_ver_less_than('7.4') && ismac), if exist('OCTAVE_VERSION') command1=['octave --eval fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &']; else @@ -119,8 +120,9 @@ for j=1:totCPU, end end else - if isunix, - [tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "ifconfig | grep \''inet addr:\''| grep -v \''127.0.0.1\'' | cut -d: -f2 | awk \''{ print $1}\''"']); + if isunix || (~matlab_ver_less_than('7.4') && ismac), +% [tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "ifconfig | grep \''inet addr:\''| grep -v \''127.0.0.1\'' | cut -d: -f2 | awk \''{ print $1}\''"']); + [tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "hostname --fqdn"']); RemoteName=RemoteName(1:end-1); RemoteFolder = Parallel(indPC).RemoteFolder; else @@ -137,7 +139,7 @@ for j=1:totCPU, end if remoteFlag, if j==nCPU0+1, - if isunix, + if isunix || (~matlab_ver_less_than('7.4') && ismac), system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/*']); else mydelete('*.*',['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']); @@ -150,7 +152,7 @@ for j=1:totCPU, end end - if isunix, + if isunix || (~matlab_ver_less_than('7.4') && ismac), system(['scp ',fname,'_input.mat ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]); for jfil=1:size(NamFileInput,1) if ~isempty(NamFileInput{jfil,1}) @@ -167,7 +169,7 @@ for j=1:totCPU, end end - if isunix, + if isunix || (~matlab_ver_less_than('7.4') && ismac), if exist('OCTAVE_VERSION'), command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder, '; octave --eval fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\);" &']; else @@ -199,7 +201,7 @@ end fclose(fid); % Run the slaves -if isunix, +if isunix || (~matlab_ver_less_than('7.4') && ismac), system('sh ConcurrentCommand1.bat &'); pause(1) else -- GitLab