function [C, comptime] = matmul_serial %=============================================================================== % MATLAB EXAMPLE: SERIAL HELLO WORLD % -> matrix-matrix multiplication C = A*B % % OUTPUT % C ................ result % comptime ......... computation time (matrix product only) %=============================================================================== %=============================================================================== % Get input from environment variables %=============================================================================== size_A = str2num(getenv('DIM_A')); size_B = str2num(getenv('DIM_B')); if isempty(size_A) || isempty(size_B) error('Missing input arguments!'); end if size_A(2)~=size_B(1) error(sprintf('Dimension mismatch of A (%d columns) and B (%d rows)!',... size_A(2), size_B(1))); end %=============================================================================== % Work %=============================================================================== % Hello message from compute node fprintf('Hello from MATLAB process PID=%d running on node %s!\n',... feature('getpid'),... strtrim(evalc('system(''hostname'');'))); % generate well-defined matrices NA = prod(size_A); NB = prod(size_B); A = reshape( linspace( 1,NA, NA), size_A ); B = reshape( linspace(NB, 1, NB), size_B ); % compute tic; C = A*B; comptime = toc; fprintf('serial computation of matrix-matrix product:\n'); fprintf('\ttime = %.2f s\n', comptime);