At Mark 22: | lwork was removed from the interface |
None.
Open in the MATLAB editor: f11gt_example
function f11gt_example fprintf('f11gt example results\n\n'); % Solve sparse Hermitian system Ax = b using CG method with % Incomplete Cholesky preconditioning (IC) % Define A and b n = int64(9); nz = int64(23); a = complex(zeros(3*nz,1)); irow = zeros(3*nz, 1, 'int64'); icol = zeros(3*nz, 1, 'int64'); a(1:nz) = [ 6 + 0i; -1 + 1i; 6 + 0i; 0 + 1i; 5 + 0i; 5 + 0i; 2 - 2i; 4 + 0i; 1 + 1i; 2 + 0i; 6 + 0i; -4 + 3i; 0 + 1i; -1 + 0i; 6 + 0i; -1 - 1i; 0 - 1i; 9 + 0i; 1 + 3i; 1 + 2i; -1 + 0i; 1 + 4i; 9 + 0i]; irow(1:nz) = [1; 2;2; 3;3; 4; 5;5; 6;6;6; 7;7;7;7; 8;8;8; 9;9;9;9;9]; icol(1:nz) = [1; 1;2; 2;3; 4; 1;5; 3;4;6; 2;5;6;7; 4;6;8; 1;5;6;8;9]; b = [ 8 + 54i; -10 - 92i; 25 + 27i; 26 - 28i; 54 + 12i; 26 - 22i; 47 + 65i; 71 - 57i; 60 + 70i]; % Setup IC factorization lfill = int64(0); dtol = 0; mic = 'N'; dscale = 0; ipiv = zeros(n, 1, 'int64'); [a, irow, icol, ipiv, istr, nnzc, npivm, ifail] = ... f11jn( ... nz, a, irow, icol, lfill, dtol, mic, dscale, ipiv); % Iterative method setup method = 'CG '; precon = 'Preconditioned'; tol = (x02aj)^(3/8); maxitn = int64(20); anorm = 0; sigmax = 0; maxits = int64(9); monit = int64(2); [lwreq, work, ifail] = ... f11gr( ... method, precon, int64(n), tol, maxitn, anorm, sigmax, ... maxits, monit, 'sigcmp', 's', 'norm_p', '1'); % Reverse communication loop calling f11ge irevcm = int64(0); u = complex(zeros(n,1)); v = b; wgt = zeros(n,1); while (irevcm ~= 4) [irevcm, u, v, work, ifail] = ... f11gs( ... irevcm, u, v, wgt, work); if (irevcm == 1) % v = Au [v, ifail] = f11xs( ... a(1:nz), irow(1:nz), icol(1:nz), 'N', u); elseif (irevcm == 2) % Solve (IC)v = u [v, ifail] = f11jp( ... a, irow, icol, ipiv, istr, 'N', u); elseif (irevcm == 3) % Monitoring [itn, stplhs, stprhs, anorm, sigmax, its, sigerr, ifail] = ... f11gt(work); fprintf('\nMonitoring at iteration number %2d\n',itn); fprintf('residual norm: %14.4e\n', stplhs); fprintf('\n Solution Vector\n'); disp(u); fprintf('\n Residual Vector\n'); disp(v); end end % Get information about the computation [itn, stplhs, stprhs, anorm, sigmax, its, sigerr, ifail] = ... f11gt(work); fprintf('\nNumber of iterations for convergence: %4d\n', itn); fprintf('Residual norm: %14.4e\n', stplhs); fprintf('Right-hand side of termination criteria: %14.4e\n', stprhs); fprintf('i-norm of matrix a: %14.4e\n', anorm); fprintf('\n Solution Vector\n'); disp(u); fprintf('\n Residual Vector\n'); disp(v);
f11gt example results Monitoring at iteration number 2 residual norm: 1.4937e+01 Solution Vector 0.2142 + 4.5333i -1.6589 -12.6722i 2.4101 + 7.4551i 4.4400 - 6.4174i 9.1135 + 3.7812i 4.4419 - 4.0382i 1.4757 + 1.2662i 8.4872 - 3.5347i 5.9948 + 0.9685i Residual Vector -1.8370 + 3.6956i -0.6501 + 0.2546i -0.1262 - 0.1362i -0.1312 + 0.1413i -1.1471 + 0.7339i -0.5505 - 1.0535i 1.7165 - 1.4614i -0.3583 + 0.2876i -0.3028 - 0.3532i Monitoring at iteration number 4 residual norm: 1.4602e+00 Solution Vector 1.0061 + 8.9847i 1.9637 - 7.9768i 3.0067 + 7.0285i 3.9830 - 5.9636i 5.0390 + 5.0432i 6.0488 - 4.0771i 6.9710 + 3.0168i 8.0118 - 1.9806i 9.0074 + 0.9646i Residual Vector 0.0115 - 0.0282i 0.0135 - 0.1734i 0.0182 + 0.0196i 0.0189 - 0.0204i -0.0909 - 0.1090i -0.2389 + 0.3244i 0.1903 - 0.0155i 0.0516 - 0.0414i 0.0436 + 0.0509i Number of iterations for convergence: 5 Residual norm: 9.0594e-14 Right-hand side of termination criteria: 2.8433e-03 i-norm of matrix a: 2.2000e+01 Solution Vector 1.0000 + 9.0000i 2.0000 - 8.0000i 3.0000 + 7.0000i 4.0000 - 6.0000i 5.0000 + 5.0000i 6.0000 - 4.0000i 7.0000 + 3.0000i 8.0000 - 2.0000i 9.0000 + 1.0000i Residual Vector 1.0e-13 * -0.0178 + 0.0000i 0.0355 - 0.2842i -0.0355 + 0.0355i 0.0355 - 0.0711i -0.0711 + 0.0355i -0.0711 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0711i 0.0000 - 0.1421i