clear warning off 'MATLAB:nearlySingularMatrix' warning off 'MATLAB:singularMatrix' index = UFget ; MatrixList = find (index.posdef) ; [ignore i] = sort (index.amd_lnz (MatrixList)) ; MatrixList = MatrixList (i) ; nmat = length (MatrixList) ; Tcholmod = -ones (nmat,1) ; Tbackslash = -ones (nmat,1) ; Tpcg = -ones (nmat,1) ; TpcgN = -ones (nmat,1) ; Rcholmod = -ones (nmat,1) ; Rbackslash = -ones (nmat,1) ; Rpcg = -ones (nmat,1) ; RpcgN = -ones (nmat,1) ; for k = 1:nmat rand ('state', 0) ; id = MatrixList (k) ; Problem = UFget (id) A = Problem.A ; clear Problem clear b x n = size (A,1) ; b = rand (n,1); % backslash try tic ; x = A\b ; t1=toc ; r1 = norm (A*x-b,1) / norm (A,1) ; catch t1 = Inf ; r1 = Inf ; end fprintf ('x=A\\b time %10.4f resid: %8.2e\n', t1, r1) ; Tbackslash (k) = t1 ; Rbackslash (k) = r1 ; % cholmod with METIS try tic ; x = cholmod2 (A,b) ; t4=toc ; r4 = norm (A*x-b,1) / norm (A,1) ; catch t4 = Inf ; r4 = Inf ; end fprintf ('CHOLMOD time %10.4f resid: %8.2e\n', t4, r4) ; Tcholmod (k) = t4 ; Rcholmod (k) = r4 ; % preconditioned conjugate-gradient try M = diag (diag (A)) ; % NOTE: excluded from timing tic % use defaults for tol and itmax [x flag relres iter relres] = pcg (A, b, [ ], [ ], M) ; t2=toc ; r2 = norm (A*x-b,1) / norm (A,1) ; catch t2 = Inf ; r2 = Inf ; end fprintf ('PCG time %10.4f resid: %8.2e flag: %d iter: %d\n', ... t2, r2, flag, length(relres)) ; Tpcg (k) = t2 ; Rpcg (k) = r2 ; % preconditioned conjugate-gradient - many iterations try tic % use defaults for tol, but large itmax [x flag relres iter relres] = pcg (A, b, [ ], 200, M) ; t3=toc ; r3 = norm (A*x-b,1) / norm (A,1) ; catch t3 = Inf ; r3 = Inf ; end fprintf ('PCG time %10.4f resid: %8.2e flag: %d iter: %d\n', ... t3, r3, flag, length(relres)) ; TpcgN (k) = t3 ; RpcgN (k) = r3 ; diary off diary on save Results2 Tcholmod Tbackslash Tpcg Rcholmod Rbackslash Rpcg TpcgN RpcgN MatrixList end