run_mdce

PURPOSE ^

SYNOPSIS ^

function [flag,tmdce,texe,test] = run_mdce(scheduler,modes,tpause,nX,datamode,Nmax,N,display_mode)

DESCRIPTION ^

 Script for testing the distributed calculations within MatLab (using the distributed MatLab toolbox)

 INPUTS : 
       - scheduler : override scheduler properties (type,enforce,display,...) [struct]
       - modes : list of mdce modes to test (0) : sequential, (1) mdce jobs, (2) dcluke, (3) mdce parfor [1,nmodes] 
       - tpause : pause time in function (s) [1,1]
       - mode : data transert mode : 0 (back and forth); (1) forth; (-1) back [1,1]
       - nX : size of transfer matrix (related memory = 8*nX^2 Bytes) [1,1]
       - datamode = 0 : data transert mode : 0 (back and forth); (1) forth; (-1) back [1,1]
       - Nmax : maximum cluster size [1,1]
       - N : number of iterations [1,1]
       - display_mode : (0) no figure display, (1) figure display [1,1]

 OUTPUTS : 
       - flag : list of output flags {nmodes,N}[1,n]
       - tmdce : total MDCE calculation time [nmodes,N]
       - texe : Internatal execution calculation time {nmodes,N}[1,n]
       - test : test for correct outputs [nmodes,N]

 by Y.Peysson CEA-IRFM <yves.peysson@cea.fr> and Joan Decker CEA-IRFM (joan.decker@cea.fr)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [flag,tmdce,texe,test] = run_mdce(scheduler,modes,tpause,nX,datamode,Nmax,N,display_mode)
0002 %
0003 % Script for testing the distributed calculations within MatLab (using the distributed MatLab toolbox)
0004 %
0005 % INPUTS :
0006 %       - scheduler : override scheduler properties (type,enforce,display,...) [struct]
0007 %       - modes : list of mdce modes to test (0) : sequential, (1) mdce jobs, (2) dcluke, (3) mdce parfor [1,nmodes]
0008 %       - tpause : pause time in function (s) [1,1]
0009 %       - mode : data transert mode : 0 (back and forth); (1) forth; (-1) back [1,1]
0010 %       - nX : size of transfer matrix (related memory = 8*nX^2 Bytes) [1,1]
0011 %       - datamode = 0 : data transert mode : 0 (back and forth); (1) forth; (-1) back [1,1]
0012 %       - Nmax : maximum cluster size [1,1]
0013 %       - N : number of iterations [1,1]
0014 %       - display_mode : (0) no figure display, (1) figure display [1,1]
0015 %
0016 % OUTPUTS :
0017 %       - flag : list of output flags {nmodes,N}[1,n]
0018 %       - tmdce : total MDCE calculation time [nmodes,N]
0019 %       - texe : Internatal execution calculation time {nmodes,N}[1,n]
0020 %       - test : test for correct outputs [nmodes,N]
0021 %
0022 % by Y.Peysson CEA-IRFM <yves.peysson@cea.fr> and Joan Decker CEA-IRFM (joan.decker@cea.fr)
0023 %
0024 if nargin < 1,
0025     scheduler.type = 'local';%'local','pbspro','xgrid',...
0026     scheduler.enforce = 0;% 1 to enforce sequential calculation if mdce problem
0027     scheduler.display = 1;
0028 end   
0029 if nargin < 2,
0030     modes = 0:3; 
0031 end   
0032 if nargin < 3,
0033     tpause = 10;
0034 end   
0035 if nargin < 4,
0036     nX = 100;
0037 end   
0038 if nargin < 5,
0039     datamode = 0;
0040 end   
0041 if nargin < 6,
0042     Nmax = Inf;
0043 end
0044 if nargin < 7,
0045     N = 16;
0046 end   
0047 if nargin < 8,
0048     display_mode = 2;% (0) no figure display, (1) figure display
0049 end 
0050 %
0051 if ~isstruct(scheduler),
0052     %
0053     scheduler.type = scheduler;
0054     scheduler.enforce = 0;% 1 to enforce sequential calculation if mdce problem
0055     scheduler.display = 1;
0056     %
0057 end
0058 %
0059 if ~isfield(scheduler,'memory'),
0060     scheduler.memory = 500 + round(8*nX^2/1e6);
0061 end
0062 %
0063 dkepath = load_structures_yp('dkepath','','');
0064 %
0065 modestrs = {'SEQUENTIAL','MDCE JOBS','DCLUKE','MDCE PARFOR'};
0066 colors = {'k','b','r','g'};
0067 markers = {'o','+','s','d'};
0068 %
0069 nmodes = length(modes);
0070 %
0071 tmdce = NaN*ones(nmodes,N);
0072 test = NaN*ones(nmodes,N);
0073 flag = cell(nmodes,N);
0074 texe = cell(nmodes,N);
0075 %
0076 X_in = cell(1,N);
0077 for j = 1:N,
0078     if datamode >= 0,%data transfered forth
0079         X_in{j} = rand(nX);
0080     else
0081         X_in{j} = nX;
0082     end
0083 end
0084 %
0085 for n=[1,1:N],% case 1 calculated twice to avoid preallocation time delays
0086     %
0087     for imode = 1:nmodes,
0088         %
0089         mode = modes(imode);
0090         modeindex = mode+1;
0091         modestr = modestrs{modeindex};
0092         %
0093         scheduler.mode = mode;
0094         scheduler.clustersize = min(n,Nmax);
0095         %
0096         [flag{imode,n},tmdce(imode,n),texe{imode,n},test(imode,n)] = nloop_mdce(modestr,dkepath,scheduler,X_in(1:n),tpause,datamode);
0097         %
0098     end
0099 end
0100 %
0101 if display_mode > 0,
0102     %
0103     figure(1),clf,set(1,'Name','Calculation time (s)')
0104     %
0105     % display total mdce time
0106     %
0107     leg = cell(1,nmodes);
0108     %
0109     for imode = 1:nmodes,
0110         %
0111         mode = modes(imode);
0112         modeindex = mode+1;
0113         mask = find(test(imode,:));
0114         leg{imode} = modestrs{modeindex};
0115         %
0116         if imode < nmodes,
0117             graph1D_jd(mask,tmdce(imode,mask),0,0,'','','',NaN,[0,N+1],NaN,'-',markers{modeindex},colors{modeindex},2,20+14i,gca);
0118         else
0119             leg = [leg,'Location','NorthWest'];
0120             graph1D_jd(mask,tmdce(imode,mask),0,0,'N processors','time (s)','Distributed computing calculations',leg,[0,N+1],NaN,'-',markers{modeindex},colors{modeindex},2,20+14i,gca,0.9,0.7,0.5);
0121         end
0122         %
0123     end
0124     %
0125     % display execution time
0126     %
0127     for imode = 1:nmodes,
0128         %
0129         mode = modes(imode);
0130         modeindex = mode+1;
0131         mask = find(test(imode,:));
0132         %
0133         texemax = NaN(1,N);
0134         for n=mask,
0135             texemax(n) = max(texe{imode,n});
0136         end
0137         %
0138         graph1D_jd(mask,texemax(mask),0,0,'','','',NaN,[0,N+1],NaN,'--','none',colors{modeindex},0.5,20+14i,gca);
0139         %
0140         print_jd(display_mode,'mdce_evaluation','./figures',1)
0141     end
0142 end
0143 end
0144 %
0145 function [flag,tmdce,texe,test] = nloop_mdce(modestr,dkepath,scheduler,X_in,tpause,datamode)
0146     %
0147     [dkecluster] = clustermode_luke(scheduler,'',dkepath);%All cluster parameters and paths
0148     %
0149     dkecluster.scheduler.clustersize = length(X_in);
0150     %
0151     tinit = tic;
0152     [flag,X_out,texe] = mdce_run(@frun_mdce,{tpause,datamode,''},3,X_in,dkecluster);
0153     tmdce = toc(tinit);
0154     texe = cell2mat(texe.');
0155     %
0156     if ~all(flag == scheduler.mode),
0157         disp('   --> WARNING: Distributed calculation problem occured.');
0158         disp(['   --> flag : ',num2str(flag)]);
0159     end        
0160     %
0161     if datamode == 0,% back and forth, test result
0162         test = comp_struct_jd(X_in,X_out.',0);
0163         if test == 1,
0164             disp('   --> Outputs and Inputs are identical');
0165         else
0166             disp('   --> WARNING: Outputs are different from inputs. Verify workflow.');
0167         end
0168     else
0169         test = 1;
0170     end
0171     %
0172     disp(['   --> time for n = ',int2str(length(X_in)),' ',modestr,' calculations on ',int2str(dkecluster.scheduler.clustersize),' proc. : ',num2str(tmdce),' s'])
0173     disp(['   --> Execution time for frun_mdce : min ',num2str(min(texe)),'; max ',num2str(max(texe)),'; mean ',num2str(mean(texe)),' s'])
0174     disp('-------------------------------------------------------------------------')
0175     %
0176 end

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.