From fischej at umich.edu Mon Aug 2 15:52:39 2010 From: fischej at umich.edu (John-Michael Fischer) Date: Mon, 2 Aug 2010 16:52:39 -0400 Subject: [petsc-users] PETSC with-debugging and petsc errors Message-ID: <42982681-6D3A-4A2C-9CE5-6B061746EAD4@umich.edu> I was wondering if when PETSC is compiled with-debugging=1 (or any other configure flag for that matter) I can get it to report the line and filename that errors occur on in my source. It's dutifully reporting the file and line # of the PETSC source, but I know the error is mine and not a problem with petsc (the error is [0]PETSC ERROR: Argument out of range! ). Since PETSC catches it, even when I run the program in GDB it doesn't segfault or anything so execution just keeps on going. Thanks John-Michael Fischer From balay at mcs.anl.gov Mon Aug 2 15:58:22 2010 From: balay at mcs.anl.gov (Satish Balay) Date: Mon, 2 Aug 2010 15:58:22 -0500 (CDT) Subject: [petsc-users] PETSC with-debugging and petsc errors In-Reply-To: <42982681-6D3A-4A2C-9CE5-6B061746EAD4@umich.edu> References: <42982681-6D3A-4A2C-9CE5-6B061746EAD4@umich.edu> Message-ID: On Mon, 2 Aug 2010, John-Michael Fischer wrote: > I was wondering if when PETSC is compiled with-debugging=1 (or any other configure flag for that matter) I can get it to report the line and filename that errors occur on in my source. > > It's dutifully reporting the file and line # of the PETSC source, but I know the error is mine and not a problem with petsc (the error is [0]PETSC ERROR: Argument out of range! ). > For some errrors - it can give a bit more info if you have the __FUNCT__ macro defined for each of your functions. For eg: check src/ksp/ksp/examples/tutorials/ex2.c, src/mat/interface/matrix.c. [This is not possible from fortran sources] > Since PETSC catches it, even when I run the program in GDB it doesn't segfault or anything so execution just keeps on going. > You can place a breakpoint in PetscError() - and then work thorugh the function stack. [using a debugger should be prefered over the relaince of messages printed by petsc error handlers] Satish From bsmith at mcs.anl.gov Mon Aug 2 16:07:49 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Mon, 2 Aug 2010 16:07:49 -0500 Subject: [petsc-users] PETSC with-debugging and petsc errors In-Reply-To: <42982681-6D3A-4A2C-9CE5-6B061746EAD4@umich.edu> References: <42982681-6D3A-4A2C-9CE5-6B061746EAD4@umich.edu> Message-ID: Use the run time option -on_error_abort then it aborts at exactly the line it finds the problem; this is a good option when you run in the debugger. Note that if you use the option -start_in_debugger or -on_error_attach_debugger it automatically does the abort on error detection. Barry On Aug 2, 2010, at 3:52 PM, John-Michael Fischer wrote: > I was wondering if when PETSC is compiled with-debugging=1 (or any other configure flag for that matter) I can get it to report the line and filename that errors occur on in my source. > > It's dutifully reporting the file and line # of the PETSC source, but I know the error is mine and not a problem with petsc (the error is [0]PETSC ERROR: Argument out of range! ). > > Since PETSC catches it, even when I run the program in GDB it doesn't segfault or anything so execution just keeps on going. > > > Thanks > John-Michael Fischer From filippo.spiga at disco.unimib.it Tue Aug 3 07:27:21 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Tue, 03 Aug 2010 08:27:21 -0400 Subject: [petsc-users] Problems with preconditioners, which one? Message-ID: <4C580B29.8040305@disco.unimib.it> Dear all, I'm not an expert so probably the answer of my problem is very easy (I hope so!). I have a linear system (a distributed linear system) and I want to solve it using SNES. I know the form of the solution (this is a test case, then we want to apply the same method on another class of problems). I already use part this code that works for another problem. I only changed is the Jacobian and the Jacobian evaluation routine. I tested the Jacobian using the option "-snes_type test" and the differences between mine compared with the one calculated by PETSc is "0" (*). The matrix is very simple but is "singular" (determinant = 1.0519e-55) and probably is also bad conditioned. At this point I tried the preconditioners. ILU is not good because it doesn't work in a parallel environment. HYPRE doesn't work, SNES diverges. I tried some basic tuning of HYPRE without success. But I'm not an expert. So, what can I do? I used this options (**) and SNES doesn't converge (***). Jacobian and the Residual vector are (**). I also tried (without success) to change rtol/atol, increasing the accurancy until 1.e-13. Any suggestion to try to find a good preconditioner (and a good tuning of that preconditioner) is really appreciate. Thank you very much in advance! Regards (*) Testing hand-coded Jacobian, if the ratio is,O(1.e-8), the hand-coded Jacobian is probably correct. (**) -log_summary -pc_type hypre -snes_type ls -snes_max_it 100000 -snes_rtol 1.e-8 -snes_atol 1.e-4 -snes_monitor -snes_monitor_solution -snes_monitor_true_residual true -snes_monitor_solution_update -snes_view (***) [0]: start=0, end=7 [1]: start=7, end=13 [2]: start=13, end=20 [3]: start=20, end=27 0 SNES Function norm 7.421625102155e-02 1 SNES Function norm 1.979632611100e-02 2 SNES Function norm 1.978787365526e-02 3 SNES Function norm 1.978784197958e-02 SNES Object: type: ls line search variant: SNESLineSearchCubic alpha=0.0001, maxstep=1e+08, minlambda=1e-12 maximum iterations=100000, maximum function evaluations=10000 tolerances: relative=1e-08, absolute=0.0001, solution=1e-08 total number of linear solver iterations=9 total number of function evaluations=55 KSP Object: type: gmres GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement GMRES: happy breakdown tolerance 1e-30 maximum iterations=10000, initial guess is zero tolerances: relative=1e-05, absolute=1e-50, divergence=10000 left preconditioning using PRECONDITIONED norm type for convergence test PC Object: type: hypre HYPRE BoomerAMG preconditioning HYPRE BoomerAMG: Cycle type V HYPRE BoomerAMG: Maximum number of levels 25 HYPRE BoomerAMG: Maximum number of iterations PER hypre call 1 HYPRE BoomerAMG: Convergence tolerance PER hypre call 0 HYPRE BoomerAMG: Threshold for strong coupling 0.25 HYPRE BoomerAMG: Interpolation truncation factor 0 HYPRE BoomerAMG: Interpolation: max elements per row 0 HYPRE BoomerAMG: Number of levels of aggressive coarsening 0 HYPRE BoomerAMG: Number of paths for aggressive coarsening 1 HYPRE BoomerAMG: Maximum row sums 0.9 HYPRE BoomerAMG: Sweeps down 1 HYPRE BoomerAMG: Sweeps up 1 HYPRE BoomerAMG: Sweeps on coarse 1 HYPRE BoomerAMG: Relax down symmetric-SOR/Jacobi HYPRE BoomerAMG: Relax up symmetric-SOR/Jacobi HYPRE BoomerAMG: Relax on coarse Gaussian-elimination HYPRE BoomerAMG: Relax weight (all) 1 HYPRE BoomerAMG: Outer relax weight (all) 1 HYPRE BoomerAMG: Using CF-relaxation HYPRE BoomerAMG: Measure type local HYPRE BoomerAMG: Coarsen type Falgout HYPRE BoomerAMG: Interpolation type classical linear system matrix = precond matrix: Matrix Object: type=mpiaij, rows=27, cols=27 total: nonzeros=223, allocated nonzeros=223 not using I-node (on process 0) routines SNES Diverged. Reason LS_FAILURE |residual|_2=1.978784e-02 |residualb|_inf=1.588862e-02 |Au-b|_2=1.978784e-02 |Au-b|_inf=1.588862e-02 (****) Jacobian is stored as Sparse matrix Jacobian = (1,1) 0.0185 (3,1) -0.0093 (4,1) -0.0093 (5,1) -0.0093 (26,1) -0.0278 (2,2) 0.0031 (5,2) -0.0093 (5,3) 0.0046 (7,3) -0.0046 (10,3) -0.0046 (13,3) -0.0139 (15,3) -0.0093 (26,3) -0.0093 (5,4) 0.0046 (6,4) -0.0139 (7,4) -0.0046 (16,4) -0.0093 (26,4) -0.0093 (27,4) -0.0046 (3,5) -0.0046 (4,5) -0.0046 (7,5) -0.0093 (26,5) -0.0093 (4,6) 0.0139 (6,6) 0.0139 (7,6) 0.0046 (16,6) 0.0093 (26,6) 0.0093 (27,6) 0.0046 (3,7) 0.0046 (4,7) 0.0046 (5,7) 0.0093 (7,7) 0.0093 (26,7) 0.0093 (3,8) -0.0046 (8,8) 0.0031 (10,8) -0.0046 (3,9) -0.0139 (5,9) -0.0046 (9,9) 0.0062 (3,10) 0.0046 (11,10) -0.0046 (13,10) -0.0046 (15,10) -0.0046 (10,11) 0.0046 (11,11) 0.0046 (13,11) 0.0046 (15,11) 0.0046 (6,12) 0.0093 (7,12) 0.0093 (12,12) 0.0278 (13,12) 0.0093 (14,12) 0.0093 (15,12) 0.0093 (16,12) 0.0093 (26,12) 0.0278 (3,13) 0.0139 (7,13) 0.0046 (10,13) 0.0046 (13,13) 0.0139 (15,13) 0.0093 (26,13) 0.0093 (12,14) -0.0093 (15,14) 0.0046 (16,14) 0.0046 (17,14) -0.0093 (18,14) -0.0046 (19,14) -0.0046 (26,14) 0.0093 (3,15) 0.0093 (10,15) 0.0046 (11,15) -0.0046 (12,15) -0.0093 (13,15) -0.0093 (14,15) -0.0046 (18,15) -0.0139 (26,15) 0.0093 (4,16) 0.0093 (6,16) -0.0093 (12,16) -0.0093 (14,16) -0.0046 (19,16) -0.0139 (20,16) -0.0046 (26,16) 0.0093 (27,16) 0.0046 (12,17) 0.0093 (14,17) 0.0093 (17,17) 0.0093 (18,17) 0.0046 (19,17) 0.0046 (11,18) 0.0046 (12,18) 0.0093 (13,18) 0.0093 (14,18) 0.0046 (15,18) 0.0139 (18,18) 0.0139 (6,19) 0.0093 (12,19) 0.0093 (14,19) 0.0046 (16,19) 0.0139 (19,19) 0.0139 (20,19) 0.0046 (6,20) 0.0046 (16,20) 0.0046 (20,20) 0.0046 (27,20) 0.0046 (14,21) -0.0093 (15,21) -0.0046 (16,21) -0.0046 (21,21) 0.0093 (26,21) -0.0093 (3,22) -0.0093 (10,22) -0.0046 (15,22) -0.0139 (22,22) 0.0123 (26,22) -0.0093 (4,23) -0.0093 (16,23) -0.0139 (23,23) 0.0123 (26,23) -0.0093 (27,23) -0.0046 (4,24) -0.0046 (24,24) 0.0031 (27,24) -0.0046 (4,25) -0.0139 (5,25) -0.0046 (25,25) 0.0062 (3,26) 0.0093 (4,26) 0.0093 (5,26) 0.0093 (6,26) -0.0093 (7,26) -0.0093 (12,26) -0.0278 (13,26) -0.0093 (14,26) -0.0093 (15,26) -0.0093 (16,26) -0.0093 (26,26) -0.0000 (4,27) 0.0046 (6,27) -0.0046 (16,27) -0.0046 (20,27) -0.0046 Residual = 0 0 0.0001 -0.0101 0.0001 -0.0001 -0.0001 0 0 0.0000 0.0000 -0.0004 -0.0001 -0.0001 -0.0040 -0.0040 0.0000 0.0000 0.0000 0.0000 0 0 0 0 0 -0.0159 -0.0021 -- =============================================================== Filippo SPIGA MSc, HPC and GRID Technologist tel.: +39 340 8387735 skype: filippo.spiga =============================================================== ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From hzhang at mcs.anl.gov Tue Aug 3 08:57:36 2010 From: hzhang at mcs.anl.gov (Hong Zhang) Date: Tue, 3 Aug 2010 08:57:36 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C580B29.8040305@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> Message-ID: Run your code sequentially with option '-pc_type lu'. Does it still diverge? Hong On Tue, Aug 3, 2010 at 7:27 AM, Filippo Spiga wrote: > ?Dear all, > ? ?I'm not an expert so probably the answer of my problem is very easy (I > hope so!). I have a linear system (a distributed linear system) and I want > to solve it using SNES. I know the form of the solution (this is a test > case, then we want to apply the same method on another class of problems). I > already use part this code that works for another problem. ?I only changed > is the Jacobian and the Jacobian evaluation routine. I tested the Jacobian > using the option "-snes_type test" and the differences between mine compared > with the one calculated by PETSc is "0" (*). > > The matrix is very simple but is "singular" (determinant = 1.0519e-55) and > probably is also bad conditioned. At this point I tried the preconditioners. > ILU is not good because it doesn't work in a parallel environment. HYPRE > doesn't work, SNES diverges. I tried some basic tuning of HYPRE without > success. But I'm not an expert. So, what can I do? > > I used this options (**) and SNES doesn't converge (***). Jacobian and the > Residual vector are (**). I also tried (without success) to change > rtol/atol, increasing the accurancy until 1.e-13. Any suggestion to try to > find a good preconditioner (and a good tuning of that preconditioner) is > really appreciate. > > Thank you very much in advance! > > Regards > > > (*) > Testing hand-coded Jacobian, if the ratio is,O(1.e-8), the hand-coded > Jacobian is probably correct. > > (**) > -log_summary > -pc_type hypre > -snes_type ls > -snes_max_it 100000 > -snes_rtol 1.e-8 > -snes_atol 1.e-4 > -snes_monitor > -snes_monitor_solution > -snes_monitor_true_residual true > -snes_monitor_solution_update > -snes_view > > (***) > [0]: ?start=0, end=7 > [1]: ?start=7, end=13 > [2]: ?start=13, end=20 > [3]: ?start=20, end=27 > ?0 SNES Function norm 7.421625102155e-02 > ?1 SNES Function norm 1.979632611100e-02 > ?2 SNES Function norm 1.978787365526e-02 > ?3 SNES Function norm 1.978784197958e-02 > SNES Object: > ?type: ls > ? ?line search variant: SNESLineSearchCubic > ? ?alpha=0.0001, maxstep=1e+08, minlambda=1e-12 > ?maximum iterations=100000, maximum function evaluations=10000 > ?tolerances: relative=1e-08, absolute=0.0001, solution=1e-08 > ?total number of linear solver iterations=9 > ?total number of function evaluations=55 > ?KSP Object: > ? ?type: gmres > ? ? ?GMRES: restart=30, using Classical (unmodified) Gram-Schmidt > Orthogonalization with no iterative refinement > ? ? ?GMRES: happy breakdown tolerance 1e-30 > ? ?maximum iterations=10000, initial guess is zero > ? ?tolerances: ?relative=1e-05, absolute=1e-50, divergence=10000 > ? ?left preconditioning > ? ?using PRECONDITIONED norm type for convergence test > ?PC Object: > ? ?type: hypre > ? ? ?HYPRE BoomerAMG preconditioning > ? ? ?HYPRE BoomerAMG: Cycle type V > ? ? ?HYPRE BoomerAMG: Maximum number of levels 25 > ? ? ?HYPRE BoomerAMG: Maximum number of iterations PER hypre call 1 > ? ? ?HYPRE BoomerAMG: Convergence tolerance PER hypre call 0 > ? ? ?HYPRE BoomerAMG: Threshold for strong coupling 0.25 > ? ? ?HYPRE BoomerAMG: Interpolation truncation factor 0 > ? ? ?HYPRE BoomerAMG: Interpolation: max elements per row 0 > ? ? ?HYPRE BoomerAMG: Number of levels of aggressive coarsening 0 > ? ? ?HYPRE BoomerAMG: Number of paths for aggressive coarsening 1 > ? ? ?HYPRE BoomerAMG: Maximum row sums 0.9 > ? ? ?HYPRE BoomerAMG: Sweeps down ? ? ? ? 1 > ? ? ?HYPRE BoomerAMG: Sweeps up ? ? ? ? ? 1 > ? ? ?HYPRE BoomerAMG: Sweeps on coarse ? ?1 > ? ? ?HYPRE BoomerAMG: Relax down ? ? ? ? ?symmetric-SOR/Jacobi > ? ? ?HYPRE BoomerAMG: Relax up ? ? ? ? ? ?symmetric-SOR/Jacobi > ? ? ?HYPRE BoomerAMG: Relax on coarse ? ? Gaussian-elimination > ? ? ?HYPRE BoomerAMG: Relax weight ?(all) ? ? ?1 > ? ? ?HYPRE BoomerAMG: Outer relax weight (all) 1 > ? ? ?HYPRE BoomerAMG: Using CF-relaxation > ? ? ?HYPRE BoomerAMG: Measure type ? ? ? ?local > ? ? ?HYPRE BoomerAMG: Coarsen type ? ? ? ?Falgout > ? ? ?HYPRE BoomerAMG: Interpolation type ?classical > ? ?linear system matrix = precond matrix: > ? ?Matrix Object: > ? ? ?type=mpiaij, rows=27, cols=27 > ? ? ?total: nonzeros=223, allocated nonzeros=223 > ? ? ? ?not using I-node (on process 0) routines > SNES Diverged. Reason LS_FAILURE > |residual|_2=1.978784e-02 > |residualb|_inf=1.588862e-02 > |Au-b|_2=1.978784e-02 > |Au-b|_inf=1.588862e-02 > > > (****) Jacobian is stored as Sparse matrix > Jacobian = > > ? (1,1) ? ? ? 0.0185 > ? (3,1) ? ? ?-0.0093 > ? (4,1) ? ? ?-0.0093 > ? (5,1) ? ? ?-0.0093 > ?(26,1) ? ? ?-0.0278 > ? (2,2) ? ? ? 0.0031 > ? (5,2) ? ? ?-0.0093 > ? (5,3) ? ? ? 0.0046 > ? (7,3) ? ? ?-0.0046 > ?(10,3) ? ? ?-0.0046 > ?(13,3) ? ? ?-0.0139 > ?(15,3) ? ? ?-0.0093 > ?(26,3) ? ? ?-0.0093 > ? (5,4) ? ? ? 0.0046 > ? (6,4) ? ? ?-0.0139 > ? (7,4) ? ? ?-0.0046 > ?(16,4) ? ? ?-0.0093 > ?(26,4) ? ? ?-0.0093 > ?(27,4) ? ? ?-0.0046 > ? (3,5) ? ? ?-0.0046 > ? (4,5) ? ? ?-0.0046 > ? (7,5) ? ? ?-0.0093 > ?(26,5) ? ? ?-0.0093 > ? (4,6) ? ? ? 0.0139 > ? (6,6) ? ? ? 0.0139 > ? (7,6) ? ? ? 0.0046 > ?(16,6) ? ? ? 0.0093 > ?(26,6) ? ? ? 0.0093 > ?(27,6) ? ? ? 0.0046 > ? (3,7) ? ? ? 0.0046 > ? (4,7) ? ? ? 0.0046 > ? (5,7) ? ? ? 0.0093 > ? (7,7) ? ? ? 0.0093 > ?(26,7) ? ? ? 0.0093 > ? (3,8) ? ? ?-0.0046 > ? (8,8) ? ? ? 0.0031 > ?(10,8) ? ? ?-0.0046 > ? (3,9) ? ? ?-0.0139 > ? (5,9) ? ? ?-0.0046 > ? (9,9) ? ? ? 0.0062 > ? (3,10) ? ? ?0.0046 > ?(11,10) ? ? -0.0046 > ?(13,10) ? ? -0.0046 > ?(15,10) ? ? -0.0046 > ?(10,11) ? ? ?0.0046 > ?(11,11) ? ? ?0.0046 > ?(13,11) ? ? ?0.0046 > ?(15,11) ? ? ?0.0046 > ? (6,12) ? ? ?0.0093 > ? (7,12) ? ? ?0.0093 > ?(12,12) ? ? ?0.0278 > ?(13,12) ? ? ?0.0093 > ?(14,12) ? ? ?0.0093 > ?(15,12) ? ? ?0.0093 > ?(16,12) ? ? ?0.0093 > ?(26,12) ? ? ?0.0278 > ? (3,13) ? ? ?0.0139 > ? (7,13) ? ? ?0.0046 > ?(10,13) ? ? ?0.0046 > ?(13,13) ? ? ?0.0139 > ?(15,13) ? ? ?0.0093 > ?(26,13) ? ? ?0.0093 > ?(12,14) ? ? -0.0093 > ?(15,14) ? ? ?0.0046 > ?(16,14) ? ? ?0.0046 > ?(17,14) ? ? -0.0093 > ?(18,14) ? ? -0.0046 > ?(19,14) ? ? -0.0046 > ?(26,14) ? ? ?0.0093 > ? (3,15) ? ? ?0.0093 > ?(10,15) ? ? ?0.0046 > ?(11,15) ? ? -0.0046 > ?(12,15) ? ? -0.0093 > ?(13,15) ? ? -0.0093 > ?(14,15) ? ? -0.0046 > ?(18,15) ? ? -0.0139 > ?(26,15) ? ? ?0.0093 > ? (4,16) ? ? ?0.0093 > ? (6,16) ? ? -0.0093 > ?(12,16) ? ? -0.0093 > ?(14,16) ? ? -0.0046 > ?(19,16) ? ? -0.0139 > ?(20,16) ? ? -0.0046 > ?(26,16) ? ? ?0.0093 > ?(27,16) ? ? ?0.0046 > ?(12,17) ? ? ?0.0093 > ?(14,17) ? ? ?0.0093 > ?(17,17) ? ? ?0.0093 > ?(18,17) ? ? ?0.0046 > ?(19,17) ? ? ?0.0046 > ?(11,18) ? ? ?0.0046 > ?(12,18) ? ? ?0.0093 > ?(13,18) ? ? ?0.0093 > ?(14,18) ? ? ?0.0046 > ?(15,18) ? ? ?0.0139 > ?(18,18) ? ? ?0.0139 > ? (6,19) ? ? ?0.0093 > ?(12,19) ? ? ?0.0093 > ?(14,19) ? ? ?0.0046 > ?(16,19) ? ? ?0.0139 > ?(19,19) ? ? ?0.0139 > ?(20,19) ? ? ?0.0046 > ? (6,20) ? ? ?0.0046 > ?(16,20) ? ? ?0.0046 > ?(20,20) ? ? ?0.0046 > ?(27,20) ? ? ?0.0046 > ?(14,21) ? ? -0.0093 > ?(15,21) ? ? -0.0046 > ?(16,21) ? ? -0.0046 > ?(21,21) ? ? ?0.0093 > ?(26,21) ? ? -0.0093 > ? (3,22) ? ? -0.0093 > ?(10,22) ? ? -0.0046 > ?(15,22) ? ? -0.0139 > ?(22,22) ? ? ?0.0123 > ?(26,22) ? ? -0.0093 > ? (4,23) ? ? -0.0093 > ?(16,23) ? ? -0.0139 > ?(23,23) ? ? ?0.0123 > ?(26,23) ? ? -0.0093 > ?(27,23) ? ? -0.0046 > ? (4,24) ? ? -0.0046 > ?(24,24) ? ? ?0.0031 > ?(27,24) ? ? -0.0046 > ? (4,25) ? ? -0.0139 > ? (5,25) ? ? -0.0046 > ?(25,25) ? ? ?0.0062 > ? (3,26) ? ? ?0.0093 > ? (4,26) ? ? ?0.0093 > ? (5,26) ? ? ?0.0093 > ? (6,26) ? ? -0.0093 > ? (7,26) ? ? -0.0093 > ?(12,26) ? ? -0.0278 > ?(13,26) ? ? -0.0093 > ?(14,26) ? ? -0.0093 > ?(15,26) ? ? -0.0093 > ?(16,26) ? ? -0.0093 > ?(26,26) ? ? -0.0000 > ? (4,27) ? ? ?0.0046 > ? (6,27) ? ? -0.0046 > ?(16,27) ? ? -0.0046 > ?(20,27) ? ? -0.0046 > > > Residual = > > ? ? ? ? 0 > ? ? ? ? 0 > ? ?0.0001 > ? -0.0101 > ? ?0.0001 > ? -0.0001 > ? -0.0001 > ? ? ? ? 0 > ? ? ? ? 0 > ? ?0.0000 > ? ?0.0000 > ? -0.0004 > ? -0.0001 > ? -0.0001 > ? -0.0040 > ? -0.0040 > ? ?0.0000 > ? ?0.0000 > ? ?0.0000 > ? ?0.0000 > ? ? ? ? 0 > ? ? ? ? 0 > ? ? ? ? 0 > ? ? ? ? 0 > ? ? ? ? 0 > ? -0.0159 > ? -0.0021 > > -- > > =============================================================== > ?Filippo SPIGA ? ? ? ? ? ? ? ?MSc, HPC and GRID Technologist > ?tel.: ? +39 340 8387735 ? ? ?skype: filippo.spiga > =============================================================== > > ?Nobody will drive us out of Cantor's paradise.? > ? ? -- David Hilbert > > From filippo.spiga at disco.unimib.it Tue Aug 3 10:35:15 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Tue, 03 Aug 2010 11:35:15 -0400 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: References: <4C580B29.8040305@disco.unimib.it> Message-ID: <4C583733.702@disco.unimib.it> Hi Hong, using 1 processor and these parameters: -log_summary -pc_type lu -snes_type ls -snes_max_it 100000 -snes_rtol 1.e-8 -snes_atol 1.e-4 -snes_monitor -snes_monitor_solution -snes_monitor_true_residual true -snes_monitor_solution_update -snes_view produces this error 0 SNES Function norm 7.421625102155e-02 [0|11:22:07]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance 2.77778e-14 * rowsum 0.0277778 Anyway, if I use "ilu" instead if "lu" SNES converges and the results is "reasonable" (*). But, if I well understood, it is not possible to use ILU using more than one processor... Cheers (*) Solution_computed = [ 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 3.7156349997233107e-02 2.7984940757539362e-01 1.7704468685117958e-01 2.7984964478539093e-01 3.8521416335084396e-01 2.3436084771103685e-01 1.7702464718082261e-01 2.3435582721155149e-01 2.2028936911050551e-01 7.0392659462312190e-01 8.3483864004318586e-01 6.2136685999260521e-01 8.3483987578535479e-01 7.9245140231855016e-01 6.6647854925988304e-01 6.2137752252899703e-01 6.6646262901401532e-01 7.1376045502521746e-01 ]; real_Solution = [ 0 0 0 0 0 0 0 0 0 1/3 1/3 1/3 1/3 1/3 1/3 1/3 1/3 1/3 2/3 2/3 2/3 2/3 2/3 2/3 2/3 2/3 2/3 ]; Hong Zhang ha scritto: > Run your code sequentially with option '-pc_type lu'. > Does it still diverge? FS From jed at 59A2.org Tue Aug 3 10:57:23 2010 From: jed at 59A2.org (Jed Brown) Date: Tue, 03 Aug 2010 07:57:23 -0800 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C580B29.8040305@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> Message-ID: <87aap3eljw.fsf@59A2.org> On Tue, 03 Aug 2010 08:27:21 -0400, Filippo Spiga wrote: > Dear all, > I'm not an expert so probably the answer of my problem is very easy > (I hope so!). I have a linear system (a distributed linear system) and I > want to solve it using SNES. I know the form of the solution (this is a > test case, then we want to apply the same method on another class of > problems). I already use part this code that works for another problem. > I only changed is the Jacobian and the Jacobian evaluation routine. I > tested the Jacobian using the option "-snes_type test" and the > differences between mine compared with the one calculated by PETSc is > "0" (*). If you use the matrix (rather than some underlying nonlinear function) to evaluate residuals, then this would be expected. > The matrix is very simple but is "singular" (determinant = 1.0519e-55) Determinant isn't very meaningful for large matrices, 0.1*eye(55) (matlab notation) is a very nice matrix with determinant 1e-55. I suggest reading your matrix into Matlab/Octave/Scipy [1] and computing the small eigen/singular values and associated vectors. If the matrix really is singular, this will tell you what the null space is, then you can tell PETSc about the null space (KSPSetNullSpace) and you should be able to get a good solution. Jed [1] You can output the PETSc matrix and vector using -ksp_view_binary, then read it in using bin/matlab/PetscBinaryRead.m. From hzhang at mcs.anl.gov Tue Aug 3 10:59:53 2010 From: hzhang at mcs.anl.gov (Hong Zhang) Date: Tue, 3 Aug 2010 10:59:53 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C583733.702@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> Message-ID: This confirms that your Jacobian is singular, thus none of linear solvers would work. You need fix your function formulation (i.e., original model) and Jacobian evaluation. Hong On Tue, Aug 3, 2010 at 10:35 AM, Filippo Spiga wrote: > ?Hi Hong, > ? ?using 1 processor and ?these parameters: > > -log_summary -pc_type lu -snes_type ls -snes_max_it 100000 -snes_rtol 1.e-8 > -snes_atol 1.e-4 -snes_monitor -snes_monitor_solution > -snes_monitor_true_residual true -snes_monitor_solution_update -snes_view > > produces this error > > ?0 SNES Function norm 7.421625102155e-02 > [0|11:22:07]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in > src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance > 2.77778e-14 * rowsum 0.0277778 > > Anyway, if I use "ilu" instead if "lu" SNES converges and the results is > "reasonable" (*). But, if I well understood, it is not possible to use ILU > using more than one processor... > > Cheers > > (*) > Solution_computed = [ > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 0.0000000000000000e+00 > 3.7156349997233107e-02 > 2.7984940757539362e-01 > 1.7704468685117958e-01 > 2.7984964478539093e-01 > 3.8521416335084396e-01 > 2.3436084771103685e-01 > 1.7702464718082261e-01 > 2.3435582721155149e-01 > 2.2028936911050551e-01 > 7.0392659462312190e-01 > 8.3483864004318586e-01 > 6.2136685999260521e-01 > 8.3483987578535479e-01 > 7.9245140231855016e-01 > 6.6647854925988304e-01 > 6.2137752252899703e-01 > 6.6646262901401532e-01 > 7.1376045502521746e-01 > ]; > > real_Solution = [ > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 1/3 > 1/3 > 1/3 > 1/3 > 1/3 > 1/3 > 1/3 > 1/3 > 1/3 > 2/3 > 2/3 > 2/3 > 2/3 > 2/3 > 2/3 > 2/3 > 2/3 > 2/3 > ]; > > Hong Zhang ha scritto: >> >> Run your code sequentially with option '-pc_type lu'. >> Does it still diverge? > > FS > From rallycoops at gmail.com Tue Aug 3 18:12:35 2010 From: rallycoops at gmail.com (Chris Cooper) Date: Wed, 4 Aug 2010 09:12:35 +1000 Subject: [petsc-users] gpu? Message-ID: Hi, I have used some of PETSc's linear solvers in the past, and was wondering is there any high level documentation on gpu support in PETSc? I couldn't find anything in the online pdf. I can see in the code some level of support for cuda vec/matrix and use of the cusp library etc. Things I'm wondering about include... - current status / roadmap - applicable solvers - any benchmarks (even experimental) - target hardware (cpu/gpu configuration, interconnect etc) - other issues cheers, Chris Cooper Dr. D Studios From knepley at gmail.com Tue Aug 3 19:24:13 2010 From: knepley at gmail.com (Matthew Knepley) Date: Tue, 3 Aug 2010 19:24:13 -0500 Subject: [petsc-users] gpu? In-Reply-To: References: Message-ID: On Tue, Aug 3, 2010 at 6:12 PM, Chris Cooper wrote: > Hi, > > I have used some of PETSc's linear solvers in the past, and was > wondering is there any high level documentation on gpu support in > PETSc? I couldn't find anything in the online pdf. I can see in the > code some level of support for cuda vec/matrix and use of the cusp > library etc. Things I'm wondering about include... > > - current status / roadmap > alpha > - applicable solvers > all KSP, no PC > - any benchmarks (even experimental) > - target hardware (cpu/gpu configuration, interconnect etc) > CUDA/NVIDIA > - other issues > We are writing up a description now. Hopefully it done in a few weeks. Matt > cheers, > Chris Cooper > Dr. D Studios > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From filippo.spiga at disco.unimib.it Tue Aug 3 22:54:00 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Tue, 03 Aug 2010 23:54:00 -0400 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> Message-ID: <4C58E458.3080401@disco.unimib.it> Dear Hong, > This confirms that your Jacobian is singular, thus none of linear > solvers would work. So do any preconditioner not help me to solve the problem? I put some stuff here: http://tinyurl.com/fil-petsc - "A_LS.m" is matrix (saved by PETSc) - "b_LS-m" - the file "eigenvalues_A" contains the eigenvalues of the matrix A, computed by MATLAB. I used "-pc_type lu" and 1 only processor. The result is the same of my previous email (*). Anyway if I solve the problem using MATLAB I get the right solution. The formulation seems correct. To be honest, the eigenvalues don't say me nothing. But I'm a computer scientist, not a mathematician. I'm not able to recognize which preconditioner I should use or which modifications (scaling all/part of the rows? reformulate the system in another way?...) do to solve the problem. From my side, it is not possible to try all the preconditioners and also it is not the right way... Once again, thanks. (*) [0|23:14:58]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance 2.77778e-14 * rowsum 0.0277778 -- Filippo SPIGA ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From bsmith at mcs.anl.gov Tue Aug 3 22:59:36 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 3 Aug 2010 22:59:36 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C58E458.3080401@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> Message-ID: <610B3D0F-7ED1-476F-8A04-C0EADB48AA18@mcs.anl.gov> Is this coming from a Stokes-like problem? Barry On Aug 3, 2010, at 10:54 PM, Filippo Spiga wrote: > Dear Hong, >> This confirms that your Jacobian is singular, thus none of linear >> solvers would work. > > So do any preconditioner not help me to solve the problem? > > I put some stuff here: http://tinyurl.com/fil-petsc > - "A_LS.m" is matrix (saved by PETSc) > - "b_LS-m" > - the file "eigenvalues_A" contains the eigenvalues of the matrix A, computed by MATLAB. > > I used "-pc_type lu" and 1 only processor. The result is the same of my previous email (*). > > Anyway if I solve the problem using MATLAB I get the right solution. The formulation seems correct. To be honest, the eigenvalues don't say me nothing. But I'm a computer scientist, not a mathematician. I'm not able to recognize which preconditioner I should use or which modifications (scaling all/part of the rows? reformulate the system in another way?...) do to solve the problem. From my side, it is not possible to try all the preconditioners and also it is not the right way... > > Once again, thanks. > > (*) > [0|23:14:58]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance 2.77778e-14 * rowsum 0.0277778 > > -- > > Filippo SPIGA > > ?Nobody will drive us out of Cantor's paradise.? > -- David Hilbert > From knepley at gmail.com Tue Aug 3 23:03:03 2010 From: knepley at gmail.com (Matthew Knepley) Date: Tue, 3 Aug 2010 23:03:03 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C58E458.3080401@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> Message-ID: On Tue, Aug 3, 2010 at 10:54 PM, Filippo Spiga < filippo.spiga at disco.unimib.it> wrote: > Dear Hong, > >> This confirms that your Jacobian is singular, thus none of linear >> solvers would work. >> > > So do any preconditioner not help me to solve the problem? > There can exist no solutions when the matrix is singular, thus you have a problem with either: a) the problem definition b) the creation of your matrix in PETSc > I put some stuff here: http://tinyurl.com/fil-petsc > - "A_LS.m" is matrix (saved by PETSc) > - "b_LS-m" > - the file "eigenvalues_A" contains the eigenvalues of the matrix A, > computed by MATLAB. > > I used "-pc_type lu" and 1 only processor. The result is the same of my > previous email (*). > This shows that your matrix is singular. > Anyway if I solve the problem using MATLAB I get the right solution. The > formulation seems correct. To be What does this mean? What method in MATLAB? Some methods (like CG) can iterate on rank deficient matrices with a compatible rhs and get a solution, but other Krylov methods will fail. Most preconditioners will fail. > honest, the eigenvalues don't say me nothing. But I'm a computer scientist, > not a mathematician. I'm not able to recognize which preconditioner I should > use or which modifications (scaling all/part of the rows? reformulate the > system in another way?...) do to solve the problem. From my side, it is not > possible to try all the preconditioners and also it is not the right way... > Actually, I strongly disagree. Preconditioners are very problem specific, and it is often impossible to prove which one will work for a certain problem. There are many well-known results along these lines, such as the paper of Greenbaum, Strakos, and Ptak on GMRES. Experimentation is essential. Matt > Once again, thanks. > > (*) > [0|23:14:58]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in > src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance > 2.77778e-14 * rowsum 0.0277778 > > -- > > Filippo SPIGA > > ?Nobody will drive us out of Cantor's paradise.? > -- David Hilbert > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From filippo.spiga at disco.unimib.it Tue Aug 3 23:04:37 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Wed, 04 Aug 2010 00:04:37 -0400 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <610B3D0F-7ED1-476F-8A04-C0EADB48AA18@mcs.anl.gov> References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> <610B3D0F-7ED1-476F-8A04-C0EADB48AA18@mcs.anl.gov> Message-ID: <4C58E6D5.9060101@disco.unimib.it> Hi Barry, the problem comes from a Control Volume approach applied to a 3D domain. I can prepare a PDF reporting more details, if it is useful... Regards Barry Smith ha scritto: > Is this coming from a Stokes-like problem? > > Barry -- Filippo SPIGA ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From bsmith at mcs.anl.gov Tue Aug 3 23:09:50 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 3 Aug 2010 23:09:50 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> Message-ID: <64E0AF51-CCF4-405C-898F-2BBCC595576C@mcs.anl.gov> Matt and Hong, The eigenvalues are all nonzero, so I don't see how the matrix could be singular, all the real parts are positive so it is even a nice matrix. But a bunch of diagonal entries are identically zero, this screws up most LU factorization schemes that do not do pivoting. (Matlab does pivoting). 0.0109 + 0.0453i 0.0109 - 0.0453i 0.0071 + 0.0131i 0.0071 - 0.0131i 0.0072 + 0.0121i 0.0072 - 0.0121i 0.0049 + 0.0062i 0.0049 - 0.0062i 0.0059 + 0.0012i 0.0059 - 0.0012i 0.0034 + 0.0031i 0.0034 - 0.0031i 0.0068 + 0.0226i 0.0068 - 0.0226i 0.0061 + 0.0061i 0.0061 - 0.0061i 0.0033 + 0.0028i 0.0033 - 0.0028i 6.0000 8.0000 2.0000 8.0000 12.0000 4.0000 2.0000 4.0000 2.0000 On Aug 3, 2010, at 11:03 PM, Matthew Knepley wrote: > On Tue, Aug 3, 2010 at 10:54 PM, Filippo Spiga wrote: > Dear Hong, > This confirms that your Jacobian is singular, thus none of linear > solvers would work. > > So do any preconditioner not help me to solve the problem? > > There can exist no solutions when the matrix is singular, thus you have a problem > with either: > > a) the problem definition > > b) the creation of your matrix in PETSc > > I put some stuff here: http://tinyurl.com/fil-petsc > - "A_LS.m" is matrix (saved by PETSc) > - "b_LS-m" > - the file "eigenvalues_A" contains the eigenvalues of the matrix A, computed by MATLAB. > > I used "-pc_type lu" and 1 only processor. The result is the same of my previous email (*). > > This shows that your matrix is singular. > > Anyway if I solve the problem using MATLAB I get the right solution. The formulation seems correct. To be > > What does this mean? What method in MATLAB? Some methods (like CG) can iterate on rank deficient > matrices with a compatible rhs and get a solution, but other Krylov methods will fail. Most preconditioners > will fail. > > honest, the eigenvalues don't say me nothing. But I'm a computer scientist, not a mathematician. I'm not able to recognize which preconditioner I should use or which modifications (scaling all/part of the rows? reformulate the system in another way?...) do to solve the problem. From my side, it is not possible to try all the preconditioners and also it is not the right way... > > Actually, I strongly disagree. Preconditioners are very problem specific, and it is often impossible > to prove which one will work for a certain problem. There are many well-known results along these > lines, such as the paper of Greenbaum, Strakos, and Ptak on GMRES. Experimentation is essential. > > Matt > > Once again, thanks. > > (*) > [0|23:14:58]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance 2.77778e-14 * rowsum 0.0277778 > > -- > > Filippo SPIGA > > ?Nobody will drive us out of Cantor's paradise.? > -- David Hilbert > > > > > -- > What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. > -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From jed at 59A2.org Wed Aug 4 00:53:40 2010 From: jed at 59A2.org (Jed Brown) Date: Tue, 03 Aug 2010 21:53:40 -0800 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C58DFB6.7090800@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> <87aap3eljw.fsf@59A2.org> <4C58DFB6.7090800@disco.unimib.it> Message-ID: <874ofaexej.fsf@59A2.org> On Tue, 03 Aug 2010 23:34:14 -0400, Filippo Spiga wrote: > Dear Jed, > sorry if I bother you with this private email but I'm not an expert... No problem, replying to the list because you may not be the only one with this question. > Jed Brown wrote: > > If you use the matrix (rather than some underlying nonlinear function) > > to evaluate residuals, then this would be expected. > > could you explain me shortly this point? Usually people use SNES for nonlinear problems (there's nothing wrong with using it for linear problems, and I often recommend doing so, but it's usually used for nonlinear problems). In that case, there will be some difference, usually around sqrt(epsilon) (roughly 1e-8), between the analytic Jacobian (computed by you) and the finite differenced Jacobian. If you define the residual in terms of the matrix, then the finite difference Jacobian will agree with the analytic one. As Barry concluded, your matrix just needs pivoting, build PETSc with support for one of the third-party direct solvers (e.g. umfpack, superlu, and/or mumps) and it should work fine with -pc_type lu -pc_factor_mat_solver_package umfpack. If you want to use a domain decomposition method, you will probably need to be careful when defining the partition, but then you should be able to do direct subdomain solves as above. You might also consider a different formulation, or ordering your unknowns so that the fields with zero on the diagonal come last (then the diagonal entries fill up during factorization and dynamic pivoting is no longer needed). Jed From filippo.spiga at disco.unimib.it Wed Aug 4 07:35:57 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Wed, 04 Aug 2010 08:35:57 -0400 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> Message-ID: <4C595EAD.2020101@disco.unimib.it> Dear Matthew, Matthew Knepley wrote: > Actually, I strongly disagree. Preconditioners are very problem > specific, and it is often impossible > to prove which one will work for a certain problem. There are many > well-known results along these > lines, such as the paper of Greenbaum, Strakos, and Ptak on GMRES. > Experimentation is essential. In principle I agree with you: experimentations are essentials. But only if you know the "path", if you know what are you doing. Before wrote my first email, I tried to so something for two days: I checked the method, I checked the code, I tried to verify the problem in other ways. But my knowledge about the solvers and the library is limited so trying to continue to do experimentations would has been useless. Then I decided to consult experts (-: -- Filippo SPIGA ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From filippo.spiga at disco.unimib.it Wed Aug 4 07:53:16 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Wed, 04 Aug 2010 08:53:16 -0400 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <874ofaexej.fsf@59A2.org> References: <4C580B29.8040305@disco.unimib.it> <87aap3eljw.fsf@59A2.org> <4C58DFB6.7090800@disco.unimib.it> <874ofaexej.fsf@59A2.org> Message-ID: <4C5962BC.2030707@disco.unimib.it> Dear Jed, Jed Brown wrote: > Usually people use SNES for nonlinear problems (there's nothing wrong > with using it for linear problems, and I often recommend doing so, but > it's usually used for nonlinear problems). In that case, there will be > some difference, usually around sqrt(epsilon) (roughly 1e-8), between > the analytic Jacobian (computed by you) and the finite differenced > Jacobian. If you define the residual in terms of the matrix, then the > finite difference Jacobian will agree with the analytic one. In my case that test is not useful, right? > As Barry concluded, your matrix just needs pivoting, build PETSc with > support for one of the third-party direct solvers (e.g. umfpack, > superlu, and/or mumps) and it should work fine with -pc_type lu > -pc_factor_mat_solver_package umfpack. If you want to use a domain > decomposition method, you will probably need to be careful when defining > the partition, but then you should be able to do direct subdomain solves > as above. You might also consider a different formulation, or ordering > your unknowns so that the fields with zero on the diagonal come last > (then the diagonal entries fill up during factorization and dynamic > pivoting is no longer needed). I didn't try UMFPACK and probably that external library is not compiled. I will do that. But can I use "-pc_type lu,-pc_factor_mat_solver_package umfpack" in a parallel execution? Anyway, I will try this solution this morning. I will keep you updated if I will have success or not. Many thanks to all of you! Regards -- Filippo SPIGA ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From hzhang at mcs.anl.gov Wed Aug 4 09:53:42 2010 From: hzhang at mcs.anl.gov (Hong Zhang) Date: Wed, 4 Aug 2010 09:53:42 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <64E0AF51-CCF4-405C-898F-2BBCC595576C@mcs.anl.gov> References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> <64E0AF51-CCF4-405C-898F-2BBCC595576C@mcs.anl.gov> Message-ID: Filippo, Yes, the matrix is well conditioned. Using ~petsc-dev/src/mat/examples/tests/ex78.c, I converted your matlab matrix and rhs into petsc binary format. Then run it with petsc-dev/src/ksp/ksp/examples/tutorials/ex10.c: ./ex10 -f0 $D/A_rhs_spiga -pc_type lu which gives same error on numerical factorization as yours. Then switching to superlu and mumps LU direct sovler, I get ./ex10 -f0 $D/A_rhs_spiga -pc_type lu -pc_factor_mat_solver_package superlu Number of iterations = 1 Residual norm < 1.e-12 Using petsc default sovler (gmres+ilu): ./ex10 -f0 $D/A_rhs_spiga -ksp_monitor 0 KSP Residual norm 1.011174511507e+01 1 KSP Residual norm 1.498441679989e+00 2 KSP Residual norm 1.657440211742e-01 3 KSP Residual norm 7.568788163764e-02 4 KSP Residual norm 3.158616884464e-02 5 KSP Residual norm 6.169977289081e-08 Number of iterations = 5 Residual norm 0.0162922 As you see, it converges well. For you info., I attached the binary file A_rhs_spiga here. Hong On Tue, Aug 3, 2010 at 11:09 PM, Barry Smith wrote: > > ??Matt and Hong, > ??The eigenvalues are all nonzero, so I don't see how the matrix could be > singular, all the real parts are positive so it is even a nice matrix. But a > bunch of diagonal entries are identically zero, this screws up most LU > factorization schemes that do not do pivoting. (Matlab does pivoting). > > 0.0109 + 0.0453i > 0.0109 - 0.0453i > 0.0071 + 0.0131i > 0.0071 - 0.0131i > 0.0072 + 0.0121i > 0.0072 - 0.0121i > 0.0049 + 0.0062i > 0.0049 - 0.0062i > 0.0059 + 0.0012i > 0.0059 - 0.0012i > 0.0034 + 0.0031i > 0.0034 - 0.0031i > 0.0068 + 0.0226i > 0.0068 - 0.0226i > 0.0061 + 0.0061i > 0.0061 - 0.0061i > 0.0033 + 0.0028i > 0.0033 - 0.0028i > 6.0000 > 8.0000 > 2.0000 > 8.0000 > 12.0000 > 4.0000 > 2.0000 > 4.0000 > 2.0000 > > On Aug 3, 2010, at 11:03 PM, Matthew Knepley wrote: > > On Tue, Aug 3, 2010 at 10:54 PM, Filippo Spiga > wrote: >> >> ?Dear Hong, >>> >>> This confirms that your Jacobian is singular, thus none of linear >>> solvers would work. >> >> So do any preconditioner not help me to solve the problem? > > There can exist no solutions when the matrix is singular, thus you have a > problem > with either: > ??a) the problem definition > ??b) the creation of your matrix in PETSc > >> >> I put some stuff here: http://tinyurl.com/fil-petsc >> - "A_LS.m" is matrix (saved by PETSc) >> - "b_LS-m" >> - the file "eigenvalues_A" contains the eigenvalues of the matrix A, >> computed by MATLAB. >> >> I used "-pc_type lu" and 1 only processor. The result is the same of my >> previous email (*). > > This shows that your matrix is singular. > >> >> Anyway if I solve the problem using MATLAB I get the right solution. The >> formulation seems correct. To be > > What does this mean? What method in MATLAB? Some methods (like CG) can > iterate on rank deficient > matrices with a compatible rhs and get a solution, but other Krylov methods > will fail. Most preconditioners > will fail. > >> >> honest, the eigenvalues don't say me nothing. But I'm a computer >> scientist, not a mathematician. I'm not able to recognize which >> preconditioner I should use or which modifications (scaling all/part of the >> rows? reformulate the system in another way?...) do to solve the problem. >> From my side, it is not possible to try all the preconditioners and also it >> is not the right way... > > Actually, I strongly disagree. Preconditioners are very problem specific, > and it is often impossible > to prove which one will work for a certain problem. There are many > well-known results along these > lines, such as the paper of Greenbaum, Strakos, and Ptak on GMRES. > Experimentation is essential. > ?? ?Matt > >> >> Once again, thanks. >> >> (*) >> [0|23:14:58]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in >> src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance >> 2.77778e-14 * rowsum 0.0277778 >> >> -- >> >> Filippo SPIGA >> >> ?Nobody will drive us out of Cantor's paradise.? >> ? ? -- David Hilbert >> > > > > -- > What most experimenters take for granted before they begin their experiments > is infinitely more interesting than any results to which their experiments > lead. > -- Norbert Wiener > > -------------- next part -------------- A non-text attachment was scrubbed... Name: A_rhs_spiga Type: application/octet-stream Size: 3024 bytes Desc: not available URL: From jed at 59A2.org Wed Aug 4 10:07:17 2010 From: jed at 59A2.org (Jed Brown) Date: Wed, 04 Aug 2010 07:07:17 -0800 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C5962BC.2030707@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> <87aap3eljw.fsf@59A2.org> <4C58DFB6.7090800@disco.unimib.it> <874ofaexej.fsf@59A2.org> <4C5962BC.2030707@disco.unimib.it> Message-ID: <871vaee7ru.fsf@59A2.org> On Wed, 04 Aug 2010 08:53:16 -0400, Filippo Spiga wrote: > In my case that test is not useful, right? Correct, if you have f(x) = A x - b then -snes_type test doesn't check anything new. > I didn't try UMFPACK and probably that external library is not compiled. > I will do that. But can I use "-pc_type lu,-pc_factor_mat_solver_package > umfpack" in a parallel execution? You can use mumps and superlu_dist in parallel. Or a domain decomposition method with direct subdomain solves, but then my earlier comment regarding being careful about the partition applies. Jed From hzhang at mcs.anl.gov Wed Aug 4 10:10:16 2010 From: hzhang at mcs.anl.gov (Hong Zhang) Date: Wed, 4 Aug 2010 10:10:16 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> <64E0AF51-CCF4-405C-898F-2BBCC595576C@mcs.anl.gov> Message-ID: Filippo, Sorry, your matrix is ill-conditioned, gmres+ilu does not converge in true residual (not preconditioned residual!): ./ex10 -f0 $D/A_rhs_spiga -ksp_monitor_true_residual 0 KSP preconditioned resid norm 1.011174511507e+01 true resid norm 2.084628109126e-02 ||r(i)||/||b|| 1.000000000000e+00 1 KSP preconditioned resid norm 1.498441679989e+00 true resid norm 4.919980218651e-02 ||r(i)||/||b|| 2.360123706052e+00 2 KSP preconditioned resid norm 1.657440211742e-01 true resid norm 1.624190902280e-02 ||r(i)||/||b|| 7.791274113447e-01 3 KSP preconditioned resid norm 7.568788163764e-02 true resid norm 1.516900048065e-02 ||r(i)||/||b|| 7.276597880572e-01 4 KSP preconditioned resid norm 3.158616884464e-02 true resid norm 1.703303336172e-02 ||r(i)||/||b|| 8.170777937395e-01 5 KSP preconditioned resid norm 6.169977289081e-08 true resid norm 1.629219484085e-02 ||r(i)||/||b|| 7.815396314348e-01 Using superlu, I get condition number ./ex10 -f0 $D/A_rhs_spiga -pc_type lu -pc_factor_mat_solver_package superlu -mat_superlu_conditionnumber Recip. condition number = 1.171784e-04 For such tiny matrix (27x27), condition number=1.e+4. Using superlu_dist or mumps LU as precondition might be the only option for your application. Hong On Wed, Aug 4, 2010 at 9:53 AM, Hong Zhang wrote: > Filippo, > > Yes, the matrix is well conditioned. > Using ~petsc-dev/src/mat/examples/tests/ex78.c, I converted your > matlab matrix and rhs > into petsc binary format. Then run it with > petsc-dev/src/ksp/ksp/examples/tutorials/ex10.c: > > ./ex10 -f0 $D/A_rhs_spiga -pc_type lu > which gives same error on numerical factorization as yours. > > Then switching to superlu and mumps LU direct sovler, I get > ./ex10 -f0 $D/A_rhs_spiga -pc_type lu -pc_factor_mat_solver_package superlu > Number of iterations = ? 1 > Residual norm < 1.e-12 > > Using petsc default sovler (gmres+ilu): > ./ex10 -f0 $D/A_rhs_spiga -ksp_monitor > ?0 KSP Residual norm 1.011174511507e+01 > ?1 KSP Residual norm 1.498441679989e+00 > ?2 KSP Residual norm 1.657440211742e-01 > ?3 KSP Residual norm 7.568788163764e-02 > ?4 KSP Residual norm 3.158616884464e-02 > ?5 KSP Residual norm 6.169977289081e-08 > Number of iterations = ? 5 > Residual norm 0.0162922 > > As you see, it converges well. > For you info., I attached the binary file A_rhs_spiga here. > > Hong > > On Tue, Aug 3, 2010 at 11:09 PM, Barry Smith wrote: >> >> ??Matt and Hong, >> ??The eigenvalues are all nonzero, so I don't see how the matrix could be >> singular, all the real parts are positive so it is even a nice matrix. But a >> bunch of diagonal entries are identically zero, this screws up most LU >> factorization schemes that do not do pivoting. (Matlab does pivoting). >> >> ? ?0.0109 + 0.0453i >> ? ?0.0109 - 0.0453i >> ? ?0.0071 + 0.0131i >> ? ?0.0071 - 0.0131i >> ? ?0.0072 + 0.0121i >> ? ?0.0072 - 0.0121i >> ? ?0.0049 + 0.0062i >> ? ?0.0049 - 0.0062i >> ? ?0.0059 + 0.0012i >> ? ?0.0059 - 0.0012i >> ? ?0.0034 + 0.0031i >> ? ?0.0034 - 0.0031i >> ? ?0.0068 + 0.0226i >> ? ?0.0068 - 0.0226i >> ? ?0.0061 + 0.0061i >> ? ?0.0061 - 0.0061i >> ? ?0.0033 + 0.0028i >> ? ?0.0033 - 0.0028i >> ? ?6.0000 >> ? ?8.0000 >> ? ?2.0000 >> ? ?8.0000 >> ? 12.0000 >> ? ?4.0000 >> ? ?2.0000 >> ? ?4.0000 >> ? ?2.0000 >> >> On Aug 3, 2010, at 11:03 PM, Matthew Knepley wrote: >> >> On Tue, Aug 3, 2010 at 10:54 PM, Filippo Spiga >> wrote: >>> >>> ?Dear Hong, >>>> >>>> This confirms that your Jacobian is singular, thus none of linear >>>> solvers would work. >>> >>> So do any preconditioner not help me to solve the problem? >> >> There can exist no solutions when the matrix is singular, thus you have a >> problem >> with either: >> ??a) the problem definition >> ??b) the creation of your matrix in PETSc >> >>> >>> I put some stuff here: http://tinyurl.com/fil-petsc >>> - "A_LS.m" is matrix (saved by PETSc) >>> - "b_LS-m" >>> - the file "eigenvalues_A" contains the eigenvalues of the matrix A, >>> computed by MATLAB. >>> >>> I used "-pc_type lu" and 1 only processor. The result is the same of my >>> previous email (*). >> >> This shows that your matrix is singular. >> >>> >>> Anyway if I solve the problem using MATLAB I get the right solution. The >>> formulation seems correct. To be >> >> What does this mean? What method in MATLAB? Some methods (like CG) can >> iterate on rank deficient >> matrices with a compatible rhs and get a solution, but other Krylov methods >> will fail. Most preconditioners >> will fail. >> >>> >>> honest, the eigenvalues don't say me nothing. But I'm a computer >>> scientist, not a mathematician. I'm not able to recognize which >>> preconditioner I should use or which modifications (scaling all/part of the >>> rows? reformulate the system in another way?...) do to solve the problem. >>> From my side, it is not possible to try all the preconditioners and also it >>> is not the right way... >> >> Actually, I strongly disagree. Preconditioners are very problem specific, >> and it is often impossible >> to prove which one will work for a certain problem. There are many >> well-known results along these >> lines, such as the paper of Greenbaum, Strakos, and Ptak on GMRES. >> Experimentation is essential. >> ?? ?Matt >> >>> >>> Once again, thanks. >>> >>> (*) >>> [0|23:14:58]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in >>> src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance >>> 2.77778e-14 * rowsum 0.0277778 >>> >>> -- >>> >>> Filippo SPIGA >>> >>> ?Nobody will drive us out of Cantor's paradise.? >>> ? ? -- David Hilbert >>> >> >> >> >> -- >> What most experimenters take for granted before they begin their experiments >> is infinitely more interesting than any results to which their experiments >> lead. >> -- Norbert Wiener >> >> > From bsmith at mcs.anl.gov Wed Aug 4 10:29:20 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Wed, 4 Aug 2010 10:29:20 -0500 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: References: <4C580B29.8040305@disco.unimib.it> <4C583733.702@disco.unimib.it> <4C58E458.3080401@disco.unimib.it> <64E0AF51-CCF4-405C-898F-2BBCC595576C@mcs.anl.gov> Message-ID: If you look at the eigenvalues of the matrix closely you will see it has two parts. Eigenvalues with real part between .0033 and .01 and eigenvalues between 2 and 12. I suspect this two levels of well-conditioned pieces is due to the parts of the matrix have zeros on the diagonals and the rest without zeros (this is why I asked if the problem was a Stokes problem). Perhaps a Schur complement type preconditioner done with the PCFieldSplit preconditioner is the way to go, you would eliminate in the Schur complement the rows/columns of the matrix that do not have the zeros on the diagonal. Barry On Aug 4, 2010, at 10:10 AM, Hong Zhang wrote: > Filippo, > Sorry, your matrix is ill-conditioned, gmres+ilu does not converge in > true residual > (not preconditioned residual!): > ./ex10 -f0 $D/A_rhs_spiga -ksp_monitor_true_residual > 0 KSP preconditioned resid norm 1.011174511507e+01 true resid norm > 2.084628109126e-02 ||r(i)||/||b|| 1.000000000000e+00 > 1 KSP preconditioned resid norm 1.498441679989e+00 true resid norm > 4.919980218651e-02 ||r(i)||/||b|| 2.360123706052e+00 > 2 KSP preconditioned resid norm 1.657440211742e-01 true resid norm > 1.624190902280e-02 ||r(i)||/||b|| 7.791274113447e-01 > 3 KSP preconditioned resid norm 7.568788163764e-02 true resid norm > 1.516900048065e-02 ||r(i)||/||b|| 7.276597880572e-01 > 4 KSP preconditioned resid norm 3.158616884464e-02 true resid norm > 1.703303336172e-02 ||r(i)||/||b|| 8.170777937395e-01 > 5 KSP preconditioned resid norm 6.169977289081e-08 true resid norm > 1.629219484085e-02 ||r(i)||/||b|| 7.815396314348e-01 > > Using superlu, I get condition number > ./ex10 -f0 $D/A_rhs_spiga -pc_type lu -pc_factor_mat_solver_package > superlu -mat_superlu_conditionnumber > > Recip. condition number = 1.171784e-04 > > For such tiny matrix (27x27), condition number=1.e+4. > Using superlu_dist or mumps LU as precondition might be the only > option for your application. > > Hong > > > > On Wed, Aug 4, 2010 at 9:53 AM, Hong Zhang wrote: >> Filippo, >> >> Yes, the matrix is well conditioned. >> Using ~petsc-dev/src/mat/examples/tests/ex78.c, I converted your >> matlab matrix and rhs >> into petsc binary format. Then run it with >> petsc-dev/src/ksp/ksp/examples/tutorials/ex10.c: >> >> ./ex10 -f0 $D/A_rhs_spiga -pc_type lu >> which gives same error on numerical factorization as yours. >> >> Then switching to superlu and mumps LU direct sovler, I get >> ./ex10 -f0 $D/A_rhs_spiga -pc_type lu -pc_factor_mat_solver_package superlu >> Number of iterations = 1 >> Residual norm < 1.e-12 >> >> Using petsc default sovler (gmres+ilu): >> ./ex10 -f0 $D/A_rhs_spiga -ksp_monitor >> 0 KSP Residual norm 1.011174511507e+01 >> 1 KSP Residual norm 1.498441679989e+00 >> 2 KSP Residual norm 1.657440211742e-01 >> 3 KSP Residual norm 7.568788163764e-02 >> 4 KSP Residual norm 3.158616884464e-02 >> 5 KSP Residual norm 6.169977289081e-08 >> Number of iterations = 5 >> Residual norm 0.0162922 >> >> As you see, it converges well. >> For you info., I attached the binary file A_rhs_spiga here. >> >> Hong >> >> On Tue, Aug 3, 2010 at 11:09 PM, Barry Smith wrote: >>> >>> Matt and Hong, >>> The eigenvalues are all nonzero, so I don't see how the matrix could be >>> singular, all the real parts are positive so it is even a nice matrix. But a >>> bunch of diagonal entries are identically zero, this screws up most LU >>> factorization schemes that do not do pivoting. (Matlab does pivoting). >>> >>> 0.0109 + 0.0453i >>> 0.0109 - 0.0453i >>> 0.0071 + 0.0131i >>> 0.0071 - 0.0131i >>> 0.0072 + 0.0121i >>> 0.0072 - 0.0121i >>> 0.0049 + 0.0062i >>> 0.0049 - 0.0062i >>> 0.0059 + 0.0012i >>> 0.0059 - 0.0012i >>> 0.0034 + 0.0031i >>> 0.0034 - 0.0031i >>> 0.0068 + 0.0226i >>> 0.0068 - 0.0226i >>> 0.0061 + 0.0061i >>> 0.0061 - 0.0061i >>> 0.0033 + 0.0028i >>> 0.0033 - 0.0028i >>> 6.0000 >>> 8.0000 >>> 2.0000 >>> 8.0000 >>> 12.0000 >>> 4.0000 >>> 2.0000 >>> 4.0000 >>> 2.0000 >>> >>> On Aug 3, 2010, at 11:03 PM, Matthew Knepley wrote: >>> >>> On Tue, Aug 3, 2010 at 10:54 PM, Filippo Spiga >>> wrote: >>>> >>>> Dear Hong, >>>>> >>>>> This confirms that your Jacobian is singular, thus none of linear >>>>> solvers would work. >>>> >>>> So do any preconditioner not help me to solve the problem? >>> >>> There can exist no solutions when the matrix is singular, thus you have a >>> problem >>> with either: >>> a) the problem definition >>> b) the creation of your matrix in PETSc >>> >>>> >>>> I put some stuff here: http://tinyurl.com/fil-petsc >>>> - "A_LS.m" is matrix (saved by PETSc) >>>> - "b_LS-m" >>>> - the file "eigenvalues_A" contains the eigenvalues of the matrix A, >>>> computed by MATLAB. >>>> >>>> I used "-pc_type lu" and 1 only processor. The result is the same of my >>>> previous email (*). >>> >>> This shows that your matrix is singular. >>> >>>> >>>> Anyway if I solve the problem using MATLAB I get the right solution. The >>>> formulation seems correct. To be >>> >>> What does this mean? What method in MATLAB? Some methods (like CG) can >>> iterate on rank deficient >>> matrices with a compatible rhs and get a solution, but other Krylov methods >>> will fail. Most preconditioners >>> will fail. >>> >>>> >>>> honest, the eigenvalues don't say me nothing. But I'm a computer >>>> scientist, not a mathematician. I'm not able to recognize which >>>> preconditioner I should use or which modifications (scaling all/part of the >>>> rows? reformulate the system in another way?...) do to solve the problem. >>>> From my side, it is not possible to try all the preconditioners and also it >>>> is not the right way... >>> >>> Actually, I strongly disagree. Preconditioners are very problem specific, >>> and it is often impossible >>> to prove which one will work for a certain problem. There are many >>> well-known results along these >>> lines, such as the paper of Greenbaum, Strakos, and Ptak on GMRES. >>> Experimentation is essential. >>> Matt >>> >>>> >>>> Once again, thanks. >>>> >>>> (*) >>>> [0|23:14:58]: unknown: MatLUFactorNumeric_SeqAIJ() line 668 in >>>> src/mat/impls/aij/seq/aijfact.c: Zero pivot row 1 value 0 tolerance >>>> 2.77778e-14 * rowsum 0.0277778 >>>> >>>> -- >>>> >>>> Filippo SPIGA >>>> >>>> ?Nobody will drive us out of Cantor's paradise.? >>>> -- David Hilbert >>>> >>> >>> >>> >>> -- >>> What most experimenters take for granted before they begin their experiments >>> is infinitely more interesting than any results to which their experiments >>> lead. >>> -- Norbert Wiener >>> >>> >> From nemanja.ilic.81 at gmail.com Wed Aug 4 12:18:31 2010 From: nemanja.ilic.81 at gmail.com (=?utf-8?b?0J3QtdC80LDRmtCwINCY0LvQuNGb?= (Nemanja Ilic)) Date: Wed, 4 Aug 2010 19:18:31 +0200 Subject: [petsc-users] Finding determinant and inverse matrix Message-ID: <201008041918.31186.nemanja.ilic.81@gmail.com> Hello, Thank you for you previous help. I wrote the code for calculating matrix determinant and inverse matrix and they don't break anymore. Still I have problems. I try to find determinant in the following way: First get LU factor of a matrix and then multiply it's diagonal elements. I don't get correct results. Could you tell me wheather the problem is maybe in info structure? What information do you need to be able to help me? I find the inverse matrix in the following way: I create linear problem A * X = B where A is the input matrix, X is the inverse matrix, and B is identity matrix. I solve it using MatMatSolve. Could you possibly help me and what info do you need? Thank you in advance, Best regards, Nemanja From knepley at gmail.com Wed Aug 4 16:19:37 2010 From: knepley at gmail.com (Matthew Knepley) Date: Wed, 4 Aug 2010 16:19:37 -0500 Subject: [petsc-users] Finding determinant and inverse matrix In-Reply-To: <201008041918.31186.nemanja.ilic.81@gmail.com> References: <201008041918.31186.nemanja.ilic.81@gmail.com> Message-ID: On Wed, Aug 4, 2010 at 12:18 PM, ?????? ???? (Nemanja Ilic) < nemanja.ilic.81 at gmail.com> wrote: > Hello, > > Thank you for you previous help. I wrote the code for calculating matrix > determinant and inverse matrix and they don't break anymore. Still I have > problems. I try to find determinant in the following way: First get LU > factor of a matrix and then multiply it's diagonal elements. I don't get > correct results. Could you tell me wheather the problem That description does not help. What do you get? What is the correct answer? Did you try it on a small problem that you can factor by hand? > is maybe in info structure? What information do you need to be able to help > me? I find the inverse matrix in the following way: I create linear problem > A * X = B where A is the input matrix, X is the inverse matrix, and B is > identity matrix. I solve it using MatMatSolve. Could you possibly help me > and what info do you need? > That should work. Matt > Thank you in advance, > Best regards, > Nemanja > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From filippo.spiga at disco.unimib.it Thu Aug 5 10:39:29 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Thu, 05 Aug 2010 11:39:29 -0400 Subject: [petsc-users] Compile and link correctly using conf/petscvariables and conf/variables Message-ID: <4C5ADB31.1090209@disco.unimib.it> Dear users, I look at different examples but I'm not sure to have well understood how to compile and link correctly using the contents of "conf/petscvariables" and "conf/variables". My program uses both linear and non linear solvers and different external packages such as superlu_dist, hypre and umfpack. I looked at "${PETSC_ROOT}/${PETSC_ARCH}/conf/petscvariables" to extract the right path to compile and link my code. Inside this file there are all these lines: PETSC_CONTRIB_BASIC = -lpetsc PETSC_SNES_LIB_BASIC = -lpetsc PETSC_KSP_LIB_BASIC = -lpetsc PETSC_MAT_LIB_BASIC = -lpetsc PETSC_LIB_BASIC = -lpetsc PETSC_VEC_LIB_BASIC = -lpetsc PETSC_DM_LIB_BASIC = -lpetsc PETSC_TS_LIB_BASIC = -lpetsc PETSC_SYS_LIB_BASIC = -lpetsc PACKAGES_LIBS = ... but there isn't a single entry that collect in the right order all of them. Then if I look at "${PETSC_ROOT}/${PETSC_ARCH}/conf/variables" I can find these lines: PETSC_EXTERNAL_LIB_BASIC = ${EXTERNAL_LIB} ${PACKAGES_LIBS} ${PCC_LINKER_LIBS} PETSC_SYS_LIB_BASIC = -lpetscsys PETSC_VEC_LIB_BASIC = -lpetscvec ${PETSC_SYS_LIB_BASIC} PETSC_MAT_LIB_BASIC = -lpetscmat ${PETSC_VEC_LIB_BASIC} PETSC_DM_LIB_BASIC = -lpetscdm ${PETSC_MAT_LIB_BASIC} PETSC_KSP_LIB_BASIC = -lpetscksp ${PETSC_DM_LIB_BASIC} PETSC_SNES_LIB_BASIC = -lpetscsnes ${PETSC_KSP_LIB_BASIC} PETSC_TS_LIB_BASIC = -lpetscts ${PETSC_SNES_LIB_BASIC} PETSC_LIB_BASIC = ${PETSC_TS_LIB_BASIC} PETSC_CONTRIB_BASIC = -lpetsccontrib PETSC_SYS_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_SYS_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_VEC_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_VEC_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_MAT_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_MAT_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_DM_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_DM_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_KSP_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_KSP_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_SNES_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_SNES_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_TS_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_TS_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} PETSC_CONTRIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_CONTRIB_BASIC} that are pretty clear. However if I look inside "${PETSC_ROOT}/${PETSC_ARCH}/lib" I don't see all the -lpetsc* libraries mentioned above" I only have one single "libpetsc.a" So, what's the right env variable to use? what is the right order of -lpetsc* statements? Can I only link "libpetsc.a"? In this last case, is my Makefile fully compatible and maintenable with all the future version of PETSc? Thank you very much in advance, Regards -- Filippo SPIGA ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From knepley at gmail.com Thu Aug 5 10:44:43 2010 From: knepley at gmail.com (Matthew Knepley) Date: Thu, 5 Aug 2010 10:44:43 -0500 Subject: [petsc-users] Compile and link correctly using conf/petscvariables and conf/variables In-Reply-To: <4C5ADB31.1090209@disco.unimib.it> References: <4C5ADB31.1090209@disco.unimib.it> Message-ID: On Thu, Aug 5, 2010 at 10:39 AM, Filippo Spiga < filippo.spiga at disco.unimib.it> wrote: > Dear users, > I look at different examples but I'm not sure to have well understood > how to compile and link correctly using the contents of > "conf/petscvariables" and "conf/variables". My program uses both linear and > non linear solvers and different external packages such as superlu_dist, > hypre and umfpack. I looked at > "${PETSC_ROOT}/${PETSC_ARCH}/conf/petscvariables" to extract the right path > to compile and link my code. Inside this file there are all these lines: > > PETSC_CONTRIB_BASIC = -lpetsc > PETSC_SNES_LIB_BASIC = -lpetsc > PETSC_KSP_LIB_BASIC = -lpetsc > PETSC_MAT_LIB_BASIC = -lpetsc > PETSC_LIB_BASIC = -lpetsc > PETSC_VEC_LIB_BASIC = -lpetsc > PETSC_DM_LIB_BASIC = -lpetsc > PETSC_TS_LIB_BASIC = -lpetsc > PETSC_SYS_LIB_BASIC = -lpetsc > PACKAGES_LIBS = ... > > but there isn't a single entry that collect in the right order all of them. > Then if I look at "${PETSC_ROOT}/${PETSC_ARCH}/conf/variables" I can find > these lines: > > PETSC_EXTERNAL_LIB_BASIC = ${EXTERNAL_LIB} ${PACKAGES_LIBS} > ${PCC_LINKER_LIBS} > PETSC_SYS_LIB_BASIC = -lpetscsys > PETSC_VEC_LIB_BASIC = -lpetscvec ${PETSC_SYS_LIB_BASIC} > PETSC_MAT_LIB_BASIC = -lpetscmat ${PETSC_VEC_LIB_BASIC} > PETSC_DM_LIB_BASIC = -lpetscdm ${PETSC_MAT_LIB_BASIC} > PETSC_KSP_LIB_BASIC = -lpetscksp ${PETSC_DM_LIB_BASIC} > PETSC_SNES_LIB_BASIC = -lpetscsnes ${PETSC_KSP_LIB_BASIC} > PETSC_TS_LIB_BASIC = -lpetscts ${PETSC_SNES_LIB_BASIC} > PETSC_LIB_BASIC = ${PETSC_TS_LIB_BASIC} > PETSC_CONTRIB_BASIC = -lpetsccontrib > > PETSC_SYS_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_SYS_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_VEC_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_VEC_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_MAT_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_MAT_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_DM_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_DM_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_KSP_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_KSP_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_SNES_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_SNES_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_TS_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_TS_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_CONTRIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_CONTRIB_BASIC} > > that are pretty clear. However if I look inside > "${PETSC_ROOT}/${PETSC_ARCH}/lib" I don't see all the -lpetsc* libraries > mentioned above" I only have one single "libpetsc.a" > > So, what's the right env variable to use? what is the right order of > -lpetsc* statements? Can I only link "libpetsc.a"? In this last case, is my > Makefile fully compatible and maintenable with all the future version of > PETSc? > Is is always correct to use include ${PETSC_DIR}/conf/variables include ${PETSC_DIR}/conf/rules foo: foo.o ${CLINKER} -o foo foo.o ${PETSC_TS_LIB} We switched in the latest release to having a single library, libpetsc. Matt > Thank you very much in advance, > Regards > > -- > > Filippo SPIGA > > ?Nobody will drive us out of Cantor's paradise.? > -- David Hilbert > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From balay at mcs.anl.gov Thu Aug 5 10:48:18 2010 From: balay at mcs.anl.gov (Satish Balay) Date: Thu, 5 Aug 2010 10:48:18 -0500 (CDT) Subject: [petsc-users] Compile and link correctly using conf/petscvariables and conf/variables In-Reply-To: <4C5ADB31.1090209@disco.unimib.it> References: <4C5ADB31.1090209@disco.unimib.it> Message-ID: The idea here is - you would: include "conf/variables" in your makefile and use PETSC_LIB in the target - so everything works correctly. The complexity you mention is to manage --with-single-lib=0/1. So Instead of trying to list libraries directly in your makefile [which becomes unportable] - I suggest you use the recommended procedure above. PETSC_LIB will pick up all exteranlpackages currently installed with PETSc [so even this part of the makefile will become portable] The best thing would be to also use "conf/rules" as well in your makefile and use PETSc compile targets for both petsc & non-petsc sources that go into your application. Satish On Thu, 5 Aug 2010, Filippo Spiga wrote: > Dear users, > I look at different examples but I'm not sure to have well understood how > to compile and link correctly using the contents of "conf/petscvariables" and > "conf/variables". My program uses both linear and non linear solvers and > different external packages such as superlu_dist, hypre and umfpack. I looked > at "${PETSC_ROOT}/${PETSC_ARCH}/conf/petscvariables" to extract the right path > to compile and link my code. Inside this file there are all these lines: > > PETSC_CONTRIB_BASIC = -lpetsc > PETSC_SNES_LIB_BASIC = -lpetsc > PETSC_KSP_LIB_BASIC = -lpetsc > PETSC_MAT_LIB_BASIC = -lpetsc > PETSC_LIB_BASIC = -lpetsc > PETSC_VEC_LIB_BASIC = -lpetsc > PETSC_DM_LIB_BASIC = -lpetsc > PETSC_TS_LIB_BASIC = -lpetsc > PETSC_SYS_LIB_BASIC = -lpetsc > PACKAGES_LIBS = ... > > but there isn't a single entry that collect in the right order all of them. > Then if I look at "${PETSC_ROOT}/${PETSC_ARCH}/conf/variables" I can find > these lines: > > PETSC_EXTERNAL_LIB_BASIC = ${EXTERNAL_LIB} ${PACKAGES_LIBS} ${PCC_LINKER_LIBS} > PETSC_SYS_LIB_BASIC = -lpetscsys > PETSC_VEC_LIB_BASIC = -lpetscvec ${PETSC_SYS_LIB_BASIC} > PETSC_MAT_LIB_BASIC = -lpetscmat ${PETSC_VEC_LIB_BASIC} > PETSC_DM_LIB_BASIC = -lpetscdm ${PETSC_MAT_LIB_BASIC} > PETSC_KSP_LIB_BASIC = -lpetscksp ${PETSC_DM_LIB_BASIC} > PETSC_SNES_LIB_BASIC = -lpetscsnes ${PETSC_KSP_LIB_BASIC} > PETSC_TS_LIB_BASIC = -lpetscts ${PETSC_SNES_LIB_BASIC} > PETSC_LIB_BASIC = ${PETSC_TS_LIB_BASIC} > PETSC_CONTRIB_BASIC = -lpetsccontrib > > PETSC_SYS_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_SYS_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_VEC_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_VEC_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_MAT_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_MAT_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_DM_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_DM_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_KSP_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_KSP_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_SNES_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} > ${PETSC_SNES_LIB_BASIC} ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_TS_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_TS_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_LIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_LIB_BASIC} > ${PETSC_EXTERNAL_LIB_BASIC} > PETSC_CONTRIB = ${C_SH_LIB_PATH} -L${PETSC_LIB_DIR} ${PETSC_CONTRIB_BASIC} > > that are pretty clear. However if I look inside > "${PETSC_ROOT}/${PETSC_ARCH}/lib" I don't see all the -lpetsc* libraries > mentioned above" I only have one single "libpetsc.a" > > So, what's the right env variable to use? what is the right order of -lpetsc* > statements? Can I only link "libpetsc.a"? In this last case, is my Makefile > fully compatible and maintenable with all the future version of PETSc? > > Thank you very much in advance, > Regards > > From filippo.spiga at disco.unimib.it Thu Aug 5 10:55:13 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Thu, 05 Aug 2010 11:55:13 -0400 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <871vaee7ru.fsf@59A2.org> References: <4C580B29.8040305@disco.unimib.it> <87aap3eljw.fsf@59A2.org> <4C58DFB6.7090800@disco.unimib.it> <874ofaexej.fsf@59A2.org> <4C5962BC.2030707@disco.unimib.it> <871vaee7ru.fsf@59A2.org> Message-ID: <4C5ADEE1.1030901@disco.unimib.it> Dear Jed, Hong, Barry and Matthew, first of all thank ou very much for you help. I really appreciate it! I tired all your suggestions and now I'm able to solve my problem. Good news! The system reachs the convergence using 'superlu_dist', 'umfpack' and 'mumps'. However I experienced some problems using umfpack and mumps. In details: - umpfpack: sometimes a values like '-1.3363470411775628e-16' or '1.1111231822598224e-15' appears instead of '0.0000000000000000e+00' - mumps: for large system (~30k x 30k matrix) it seems to be stuck after a while. I used 8 processors. I cannot understand why this happens but I'm investigating... SuperLU_DIST seems to work perfectly even if is slower that the other two. But I didn't do a exaustive performance comparison. Now my idea is do a lot of tests to measure the accuracy and the timing varying the dimension of the problem (I have different cubes to test), ksp_atol and ksp_rtol. I'm able for all simple cube cases to costruct by myself the analitical solution so I will compare the computed one with the "analitical" one. That's perfect to tune the solver, isn't it? Once again, thank you very much for your support. Regards Jed Brown ha scritto: > You can use mumps and superlu_dist in parallel. Or a domain > decomposition method with direct subdomain solves, but then my earlier > comment regarding being careful about the partition applies. -- Filippo SPIGA ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From jed at 59A2.org Thu Aug 5 11:11:22 2010 From: jed at 59A2.org (Jed Brown) Date: Thu, 05 Aug 2010 08:11:22 -0800 Subject: [petsc-users] Problems with preconditioners, which one? In-Reply-To: <4C5ADEE1.1030901@disco.unimib.it> References: <4C580B29.8040305@disco.unimib.it> <87aap3eljw.fsf@59A2.org> <4C58DFB6.7090800@disco.unimib.it> <874ofaexej.fsf@59A2.org> <4C5962BC.2030707@disco.unimib.it> <871vaee7ru.fsf@59A2.org> <4C5ADEE1.1030901@disco.unimib.it> Message-ID: <87mxt1ca51.fsf@59A2.org> On Thu, 05 Aug 2010 11:55:13 -0400, Filippo Spiga wrote: > - umpfpack: sometimes a values like '-1.3363470411775628e-16' or > '1.1111231822598224e-15' appears instead of '0.0000000000000000e+00' This is the nature of floating point arithmetic. > - mumps: for large system (~30k x 30k matrix) it seems to be stuck after > a while. I used 8 processors. I cannot understand why this happens but > I'm investigating... Interesting, other people solving Stokes-like problems with MUMPS occasionally experience this. Let us (or the MUMPS developers) know if you make progress. It would also be good to have a modest size test case that produces the hang on different machines. > SuperLU_DIST seems to work perfectly even if is slower that the other > two. But I didn't do a exaustive performance comparison. Now my idea is > do a lot of tests to measure the accuracy and the timing varying the > dimension of the problem (I have different cubes to test), ksp_atol and > ksp_rtol. I'm able for all simple cube cases to costruct by myself the > analitical solution so I will compare the computed one with the > "analitical" one. That's perfect to tune the solver, isn't it? That measure of accuracy includes discretization error which is likely to be much larger than solve error (unless the solver fails, producing an erroneous result). You can check that the residual (e.g. computed by SNES) actually gets very small relative to the applied forcing. Your goal should be a accuracy approaching epsilon * condition_number (with the direct solver, or an iterative solver with very tight tolerances), which I think is somewhere around 1e-12 for your problem and double precision. Jed From filippo.spiga at disco.unimib.it Thu Aug 5 14:47:20 2010 From: filippo.spiga at disco.unimib.it (Filippo Spiga) Date: Thu, 05 Aug 2010 15:47:20 -0400 Subject: [petsc-users] Compile and link correctly using conf/petscvariables and conf/variables In-Reply-To: References: <4C5ADB31.1090209@disco.unimib.it> Message-ID: <4C5B1548.60600@disco.unimib.it> Dear Matthew, Matthew Knepley wrote: > include ${PETSC_DIR}/conf/variables > include ${PETSC_DIR}/conf/rules > > foo: foo.o > ${CLINKER} -o foo foo.o ${PETSC_TS_LIB} I already have a Makefile. But most important I have a autoconf script that generates my configure that generates my Makefile. So I have two possibilities: - modify every single Make template to use "conf/variables" and "conf/rules" as you suggested (long, boring and useless strategy because all my current Makefiles work. I only want to generalize the configure as much as possible replacing one single line); - or starting from "conf/petscvariables" I can try to compose by myself the only information I need to generalize my scripts. I only need the name of the library. That's all. Or, if it was compiled splitting it in different indipendent libraries, I need the right order to link {PETSC_CONTRIB_BASIC, PETSC_SNES_LIB_BASIC, PETSC_KSP_LIB_BASIC, PETSC_MAT_LIB_BASIC, PETSC_LIB_BASIC, PETSC_VEC_LIB_BASIC, PETSC_DM_LIB_BASIC, PETSC_TS_LIB_BASIC, PETSC_SYS_LIB_BASIC}. I don't understand why "conf/petscvariables" doesn't provide that information. I guess it's easy to store it in one single explicit line. I'm looking for a easy way to ensure portability, I don't want to increase the complexity of the makefile/configure. If starting from the last stable release PETSc is compiled by default in one single library (and it is), I can ignore all these stuffs until that kind of "portability" problem will arise. I will probably do that at this point... Thank you very much for your explanations, Regards -- Filippo SPIGA ?Nobody will drive us out of Cantor's paradise.? -- David Hilbert From balay at mcs.anl.gov Thu Aug 5 14:52:07 2010 From: balay at mcs.anl.gov (Satish Balay) Date: Thu, 5 Aug 2010 14:52:07 -0500 (CDT) Subject: [petsc-users] Compile and link correctly using conf/petscvariables and conf/variables In-Reply-To: <4C5B1548.60600@disco.unimib.it> References: <4C5ADB31.1090209@disco.unimib.it> <4C5B1548.60600@disco.unimib.it> Message-ID: You configure script would have to create this makefile and "echo ${PETSC_LIB}" - and other stuff you need form a given install of PETSc - to detect what you want. Anythings else is not portable. [And won't work across different PETSc installations - of the same version] If you want a simple solution - then you should just use PETSc from makefile directly - and not introduce an extra configure step in the middle. satish On Thu, 5 Aug 2010, Filippo Spiga wrote: > Dear Matthew, > > Matthew Knepley wrote: > > include ${PETSC_DIR}/conf/variables > > include ${PETSC_DIR}/conf/rules > > > > foo: foo.o > > ${CLINKER} -o foo foo.o ${PETSC_TS_LIB} > > I already have a Makefile. But most important I have a autoconf script that > generates my configure that generates my Makefile. So I have two > possibilities: > - modify every single Make template to use "conf/variables" and "conf/rules" > as you suggested (long, boring and useless strategy because all my current > Makefiles work. I only want to generalize the configure as much as possible > replacing one single line); > - or starting from "conf/petscvariables" I can try to compose by myself the > only information I need to generalize my scripts. > > I only need the name of the library. That's all. Or, if it was compiled > splitting it in different indipendent libraries, I need the right order to > link {PETSC_CONTRIB_BASIC, PETSC_SNES_LIB_BASIC, PETSC_KSP_LIB_BASIC, > PETSC_MAT_LIB_BASIC, PETSC_LIB_BASIC, PETSC_VEC_LIB_BASIC, PETSC_DM_LIB_BASIC, > PETSC_TS_LIB_BASIC, PETSC_SYS_LIB_BASIC}. I don't understand why > "conf/petscvariables" doesn't provide that information. I guess it's easy to > store it in one single explicit line. I'm looking for a easy way to ensure > portability, I don't want to increase the complexity of the > makefile/configure. > > If starting from the last stable release PETSc is compiled by default in one > single library (and it is), I can ignore all these stuffs until that kind of > "portability" problem will arise. I will probably do that at this point... > > Thank you very much for your explanations, > Regards > > From recrusader at gmail.com Fri Aug 6 08:57:39 2010 From: recrusader at gmail.com (Yujie) Date: Fri, 6 Aug 2010 08:57:39 -0500 Subject: [petsc-users] one question about GPU Message-ID: Dear PETSc Developers, I just took a look at new faq and got the following information, "Can PETSc use GPUs to speedup computations? PETSc-dev has some support for running portions of the computation on Nvidia GPUs. See installation.html for how to install PETSc to use GPUs. PETSc has a Vec class VECCUDA that performs almost all the vector operations on the GPU. The Mat class MATCUDA performs matrix-vector products on the GPU but does not have matrix assembly on the GPU yet. Both of these classes run in parallel with MPI. All KPS methods, except KSPIBCGS, run all their vector operations on the GPU thus, for example Jacobi preconditioned Krylov methods run completely on the GPU. Preconditioners are a problem, we could do with some help for these. The example src/snes/examples/tutorials/ex47cu.cu demonstates how the nonlinear function evaluation can be done on the GPU." I have also checked the codes of PETSc. I found the codes relevant to GPU are added in "SEQ" not "MPI". Also, only few functions are realized currently for Vec and Mat. However, from FAQ, "Both of these classes run in parallel with MPI". How to realized it regarding current version? Thanks a lot. Regards, Yujie From nemanja.ilic.81 at gmail.com Fri Aug 6 09:00:05 2010 From: nemanja.ilic.81 at gmail.com (=?utf-8?b?0J3QtdC80LDRmtCwINCY0LvQuNGb?= (Nemanja Ilic)) Date: Fri, 6 Aug 2010 16:00:05 +0200 Subject: [petsc-users] Finding determinant and inverse matrix In-Reply-To: <201008061255.19813.nemanja.ilic.81@gmail.com> References: <201008041918.31186.nemanja.ilic.81@gmail.com> <201008061255.19813.nemanja.ilic.81@gmail.com> Message-ID: <201008061600.05220.nemanja.ilic.81@gmail.com> On Friday 06 August 2010 12:55:19 ?????? ???? (Nemanja Ilic) wrote: > Hello, > > For the matrix: 2 -2 0 > -1 5 1 > 3 4 5 > I get determinant = 0.0384615. The correct answer is 26. > Maybe I am doing LU Factorization wrong? > This is how I do LU Factoring: > ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm); CHKERRQ(ierr); > ierr = MatFactorInfoInitialize(&info); CHKERRQ(ierr); > ierr = MatLUFactor(Ap, perm, iperm, &info); CHKERRQ(ierr); > > This is the correct LU upper factotrization: 3.000 4.000 5.000 > 0.000 6.333 2.667 > 0.000 0.000 -1.368 > This is what I get: row 0: (0, 0.5) (1, -2) (2, 0) > row 1: (0, -0.5) (1, 0.25) (2, 1) > row 2: (0, 1.5) (1, 1.75) (2, 0.307692) > > Thank you, > regards, > Nemanja > > > On Wednesday 04 August 2010 23:19:37 you wrote: > > On Wed, Aug 4, 2010 at 12:18 PM, ?????? ???? (Nemanja Ilic) < > > nemanja.ilic.81 at gmail.com> wrote: > > > > > Hello, > > > > > > Thank you for you previous help. I wrote the code for calculating matrix > > > determinant and inverse matrix and they don't break anymore. Still I have > > > problems. I try to find determinant in the following way: First get LU > > > factor of a matrix and then multiply it's diagonal elements. I don't get > > > correct results. Could you tell me wheather the problem > > > > > > That description does not help. What do you get? What is the correct answer? > > Did you try it on a small > > problem that you can factor by hand? > > > > > > > is maybe in info structure? What information do you need to be able to help > > > me? I find the inverse matrix in the following way: I create linear problem > > > A * X = B where A is the input matrix, X is the inverse matrix, and B is > > > identity matrix. I solve it using MatMatSolve. Could you possibly help me > > > and what info do you need? > > > > > > > That should work. > > > > Matt > > > > > > > Thank you in advance, > > > Best regards, > > > Nemanja > > > > > > > > > > > > From balay at mcs.anl.gov Fri Aug 6 10:03:51 2010 From: balay at mcs.anl.gov (Satish Balay) Date: Fri, 6 Aug 2010 10:03:51 -0500 (CDT) Subject: [petsc-users] one question about GPU In-Reply-To: References: Message-ID: On Fri, 6 Aug 2010, Yujie wrote: > Dear PETSc Developers, > > I just took a look at new faq and got the following information, > > "Can PETSc use GPUs to speedup computations? > > PETSc-dev has some support for running portions of the computation on > Nvidia GPUs. See installation.html for how to install PETSc to use > GPUs. PETSc has a Vec class VECCUDA that performs almost all the > vector operations on the GPU. The Mat class MATCUDA performs > matrix-vector products on the GPU but does not have matrix assembly on > the GPU yet. Both of these classes run in parallel with MPI. All KPS > methods, except KSPIBCGS, run all their vector operations on the GPU > thus, for example Jacobi preconditioned Krylov methods run completely > on the GPU. Preconditioners are a problem, we could do with some help > for these. The example src/snes/examples/tutorials/ex47cu.cu > demonstates how the nonlinear function evaluation can be done on the > GPU." > > I have also checked the codes of PETSc. I found the codes relevant to > GPU are added in "SEQ" not "MPI". This is incorrect. I see: src/vec/vec/impls/seq/seqcuda src/vec/vec/impls/mpi/mpicuda src/mat/impls/aij/seq/seqcuda src/mat/impls/aij/mpi/mpicuda > Also, only few functions are realized currently for Vec and > Mat. However, from FAQ, "Both of these classes run in parallel with > MPI". How to realized it regarding current version? Thanks a lot. If you manage to get cuda & infiniband going [with mvapich] - you can try: mpiexec -n 4 ./ex19 -da_vec_type mpicuda -da_mat_type mpiaijcuda \ -pc_type none -dmmg_nlevels 1 -da_grid_x 100 -da_grid_y 100 \ -log_summary -mat_no_inode -preload off -cuda_synchronize Note: you need current petsc-dev for this. Also check: [at the very end] http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/installation.html Satish From chetan.jhurani at gmail.com Fri Aug 6 11:40:05 2010 From: chetan.jhurani at gmail.com (Chetan Jhurani) Date: Fri, 6 Aug 2010 10:40:05 -0600 Subject: [petsc-users] KSPLSQR convergence criterion Message-ID: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> Hello! Could someone help me figure out the correct way to to use KSPLSQR? Maybe I'm missing something simple. I'm trying to use it to solve an over-determined set of equations. It seems like the KSP iterations keep on going because the residual is not small enough. But since the system is over-determined, in general, the exact residual Ax - b will not be zero. For example, to solve the system min_x ||Ax - b||, with A = [1;2], b = [3;4], x must be inv(A'A)A'b = 2.2. Relative residual is 0.17888. See the Matlab code below too, which gives the correct value in 1 iteration. KSPLSQR, however, stagnates after 1 iteration. At that point, the relative residual and true residual norm match the correct values exactly. Is there an assumption in KSPLSQR that the system is always invertible or under-determined? This is petsc-3.1p2 if it matters. Thanks, Chetan ---------------------------------------------------- KSPLSQR: 0 KSP preconditioned resid norm 5.000000000000e+000 true resid norm 5.000000000000e+000 ||Ae||/||Ax|| 1.000000000000e+000 1 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 2 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 3 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 4 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 5 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 Matlab: >> a = [1;2]; >> b = [3;4]; >> [x,FLAG,RELRES,ITER] = lsqr(a,b, 1e-10, 10) x = 2.200000000000000 FLAG = 1 RELRES = 0.178885438199983 ITER = 1 >> norm(a*x-b) ans = 0.894427190999916 ---------------------------------------------------- From bsmith at mcs.anl.gov Fri Aug 6 12:46:38 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Fri, 6 Aug 2010 12:46:38 -0500 Subject: [petsc-users] Finding determinant and inverse matrix In-Reply-To: <201008061600.05220.nemanja.ilic.81@gmail.com> References: <201008041918.31186.nemanja.ilic.81@gmail.com> <201008061255.19813.nemanja.ilic.81@gmail.com> <201008061600.05220.nemanja.ilic.81@gmail.com> Message-ID: Sorry for the confusion. PETSc stores the inverse of the diagonal entries (so in the triangular solves it does not need to do divides). Note that 1/26 = .0384615 so all you need to do is invert your result and you'll get the determinant. Barry On Aug 6, 2010, at 9:00 AM, ?????? ???? (Nemanja Ilic) wrote: > On Friday 06 August 2010 12:55:19 ?????? ???? (Nemanja Ilic) wrote: >> Hello, >> >> For the matrix: 2 -2 0 >> -1 5 1 >> 3 4 5 >> I get determinant = 0.0384615. The correct answer is 26. >> Maybe I am doing LU Factorization wrong? >> This is how I do LU Factoring: >> ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm); CHKERRQ(ierr); >> ierr = MatFactorInfoInitialize(&info); CHKERRQ(ierr); >> ierr = MatLUFactor(Ap, perm, iperm, &info); CHKERRQ(ierr); >> >> This is the correct LU upper factotrization: 3.000 4.000 5.000 >> 0.000 6.333 2.667 >> 0.000 0.000 -1.368 >> This is what I get: row 0: (0, 0.5) (1, -2) (2, 0) >> row 1: (0, -0.5) (1, 0.25) (2, 1) >> row 2: (0, 1.5) (1, 1.75) (2, 0.307692) >> >> Thank you, >> regards, >> Nemanja >> >> >> On Wednesday 04 August 2010 23:19:37 you wrote: >>> On Wed, Aug 4, 2010 at 12:18 PM, ?????? ???? (Nemanja Ilic) < >>> nemanja.ilic.81 at gmail.com> wrote: >>> >>>> Hello, >>>> >>>> Thank you for you previous help. I wrote the code for calculating matrix >>>> determinant and inverse matrix and they don't break anymore. Still I have >>>> problems. I try to find determinant in the following way: First get LU >>>> factor of a matrix and then multiply it's diagonal elements. I don't get >>>> correct results. Could you tell me wheather the problem >>> >>> >>> That description does not help. What do you get? What is the correct answer? >>> Did you try it on a small >>> problem that you can factor by hand? >>> >>> >>>> is maybe in info structure? What information do you need to be able to help >>>> me? I find the inverse matrix in the following way: I create linear problem >>>> A * X = B where A is the input matrix, X is the inverse matrix, and B is >>>> identity matrix. I solve it using MatMatSolve. Could you possibly help me >>>> and what info do you need? >>>> >>> >>> That should work. >>> >>> Matt >>> >>> >>>> Thank you in advance, >>>> Best regards, >>>> Nemanja >>>> >>> >>> >>> >> >> >> > > From chetan.jhurani at gmail.com Fri Aug 6 13:21:53 2010 From: chetan.jhurani at gmail.com (Chetan Jhurani) Date: Fri, 6 Aug 2010 12:21:53 -0600 Subject: [petsc-users] KSPLSQR convergence criterion In-Reply-To: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> References: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> Message-ID: <4c5c52eb.922ddc0a.0afd.34a8@mx.google.com> Replying to my previous mail, this time with self-contained Petsc code if it helps. As before this is to use KSPLSQR to solve min_x ||Ax - b||, with A = [1;2], b = [3;4], Results: KSPGetIterationNumber 10000 KSPGetResidualNorm 0.894427 KSPConvergedReason -3 ------------------------------------------------------------- #include #include #include #include #include int main(int argc, char* argv[]) { PetscErrorCode ierr; ierr = PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); CHKERRQ(ierr); PetscScalar A_array[2] = {1, 2}; PetscScalar rhs_array[2] = {3, 4}; PetscInt pos[2] = {0, 1}; Mat A; Vec soln, rhs; KSP ksp; ierr = MatCreateSeqDense(PETSC_COMM_SELF, 2, 1, A_array, &A); CHKERRQ(ierr); ierr = VecCreateSeq(PETSC_COMM_SELF, 2, &rhs); CHKERRQ(ierr); ierr = VecSetValues(rhs, 2, pos, rhs_array, INSERT_VALUES); CHKERRQ(ierr); ierr = VecAssemblyBegin(rhs); CHKERRQ(ierr); ierr = VecAssemblyEnd(rhs); CHKERRQ(ierr); ierr = VecCreateSeq(PETSC_COMM_SELF, 1, &soln); CHKERRQ(ierr); ierr = KSPCreate(PETSC_COMM_SELF, &ksp); CHKERRQ(ierr); ierr = KSPSetType(ksp, KSPLSQR); CHKERRQ(ierr); ierr = KSPSetOperators(ksp, A, A, SAME_PRECONDITIONER); CHKERRQ(ierr); ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr); ierr = KSPSolve(ksp, rhs, soln); CHKERRQ(ierr); PetscInt num_iters; ierr = KSPGetIterationNumber(ksp, &num_iters); CHKERRQ(ierr); PetscReal rnorm; ierr = KSPGetResidualNorm(ksp, &rnorm); CHKERRQ(ierr); KSPConvergedReason reason; ierr = KSPGetConvergedReason(ksp, &reason); CHKERRQ(ierr); std::cout << "KSPGetIterationNumber " << num_iters << '\n'; std::cout << "KSPGetResidualNorm " << rnorm << '\n'; std::cout << "KSPConvergedReason " << reason << '\n'; ierr = KSPDestroy(ksp); CHKERRQ(ierr); ierr = VecDestroy(soln); CHKERRQ(ierr); ierr = VecDestroy(rhs); CHKERRQ(ierr); ierr = MatDestroy(A); CHKERRQ(ierr); ierr = PetscFinalize(); CHKERRQ(ierr); } ------------------------------------------------------------- Chetan > -----Original Message----- > From: Chetan Jhurani [mailto:chetan.jhurani at gmail.com] > Sent: Friday, August 06, 2010 10:40 AM > To: 'PETSc users list' > Subject: KSPLSQR convergence criterion > > Hello! > > Could someone help me figure out the correct way to > to use KSPLSQR? Maybe I'm missing something simple. > > I'm trying to use it to solve an over-determined set > of equations. It seems like the KSP iterations keep on > going because the residual is not small enough. But > since the system is over-determined, in general, the > exact residual Ax - b will not be zero. > > For example, to solve the system > > min_x ||Ax - b||, with A = [1;2], b = [3;4], > > x must be inv(A'A)A'b = 2.2. Relative residual is 0.17888. > See the Matlab code below too, which gives the correct > value in 1 iteration. > > KSPLSQR, however, stagnates after 1 iteration. At that > point, the relative residual and true residual norm > match the correct values exactly. > > Is there an assumption in KSPLSQR that the system is always > invertible or under-determined? This is petsc-3.1p2 if > it matters. > > Thanks, > > Chetan > > ---------------------------------------------------- > KSPLSQR: > > 0 KSP preconditioned resid norm 5.000000000000e+000 true resid norm 5.000000000000e+000 > ||Ae||/||Ax|| 1.000000000000e+000 > 1 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > 2 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > 3 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > 4 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > 5 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > > Matlab: > > >> a = [1;2]; > >> b = [3;4]; > >> [x,FLAG,RELRES,ITER] = lsqr(a,b, 1e-10, 10) > x = > 2.200000000000000 > FLAG = > 1 > RELRES = > 0.178885438199983 > ITER = > 1 > >> norm(a*x-b) > ans = > 0.894427190999916 > > ---------------------------------------------------- > From bsmith at mcs.anl.gov Fri Aug 6 22:25:02 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Fri, 6 Aug 2010 22:25:02 -0500 Subject: [petsc-users] KSPLSQR convergence criterion In-Reply-To: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> References: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> Message-ID: > Chetan, We don't currently have a convergence test for this case (hence it keeps iterating). I am working on it now and will add the convergence test in this case. Barry On Aug 6, 2010, at 11:40 AM, Chetan Jhurani wrote: > Hello! > > Could someone help me figure out the correct way to > to use KSPLSQR? Maybe I'm missing something simple. > > I'm trying to use it to solve an over-determined set > of equations. It seems like the KSP iterations keep on > going because the residual is not small enough. But > since the system is over-determined, in general, the > exact residual Ax - b will not be zero. > > For example, to solve the system > > min_x ||Ax - b||, with A = [1;2], b = [3;4], > > x must be inv(A'A)A'b = 2.2. Relative residual is 0.17888. > See the Matlab code below too, which gives the correct > value in 1 iteration. > > KSPLSQR, however, stagnates after 1 iteration. At that > point, the relative residual and true residual norm > match the correct values exactly. > > Is there an assumption in KSPLSQR that the system is always > invertible or under-determined? This is petsc-3.1p2 if > it matters. > > Thanks, > > Chetan > > ---------------------------------------------------- > KSPLSQR: > > 0 KSP preconditioned resid norm 5.000000000000e+000 true resid norm 5.000000000000e+000 ||Ae||/||Ax|| 1.000000000000e+000 > 1 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 2 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 3 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 4 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 5 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > > Matlab: > >>> a = [1;2]; >>> b = [3;4]; >>> [x,FLAG,RELRES,ITER] = lsqr(a,b, 1e-10, 10) > x = > 2.200000000000000 > FLAG = > 1 > RELRES = > 0.178885438199983 > ITER = > 1 >>> norm(a*x-b) > ans = > 0.894427190999916 > > ---------------------------------------------------- > > From bsmith at mcs.anl.gov Fri Aug 6 23:29:04 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Fri, 6 Aug 2010 23:29:04 -0500 Subject: [petsc-users] KSPLSQR convergence criterion In-Reply-To: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> References: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> Message-ID: <9EE60D8B-E2FC-4125-9951-F32E7C7411FB@mcs.anl.gov> Ok, here is my understanding of the situation: LSQR actually solves the normal equations A'*Ax = A'x. When Ax = b has a solution then Matlab and PETSc use || b - Ax|| < tol to determine convergence. Matlab also checks || A'*b - A'*Ax || < tol for convergence. In petsc-dev http://www.mcs.anl.gov/petsc/petsc-as/developers/index.html I have added an additional test based on the residual norm of the normal equations || A'*b - A'*Ax || < tol I also added -ksp_monitor_lsqr that prints the residual norm and the residual norm of the normal equations. For example [barry-smiths-macbook-pro:~/Downloads] barrysmith% ./ex1 -ksp_max_it 10 -ksp_converged_reason -ksp_monitor_lsqr 0 KSP Residual norm 5.000000000000e+00 1 KSP Residual norm 8.944271909999e-01 Residual norm normal equations 1.807443084090e-15 Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1 Please let me know if you have any troubles. Barry Note that I use a different scaling of tol for convergence test than Matlab (they try to approximate the norm of the preconditioned matrix and include that inside the bound, in PETSc we never do this). On Aug 6, 2010, at 11:40 AM, Chetan Jhurani wrote: > Hello! > > Could someone help me figure out the correct way to > to use KSPLSQR? Maybe I'm missing something simple. > > I'm trying to use it to solve an over-determined set > of equations. It seems like the KSP iterations keep on > going because the residual is not small enough. But > since the system is over-determined, in general, the > exact residual Ax - b will not be zero. > > For example, to solve the system > > min_x ||Ax - b||, with A = [1;2], b = [3;4], > > x must be inv(A'A)A'b = 2.2. Relative residual is 0.17888. > See the Matlab code below too, which gives the correct > value in 1 iteration. > > KSPLSQR, however, stagnates after 1 iteration. At that > point, the relative residual and true residual norm > match the correct values exactly. > > Is there an assumption in KSPLSQR that the system is always > invertible or under-determined? This is petsc-3.1p2 if > it matters. > > Thanks, > > Chetan > > ---------------------------------------------------- > KSPLSQR: > > 0 KSP preconditioned resid norm 5.000000000000e+000 true resid norm 5.000000000000e+000 ||Ae||/||Ax|| 1.000000000000e+000 > 1 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 2 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 3 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 4 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > 5 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 ||Ae||/||Ax|| 1.788854382000e-001 > > Matlab: > >>> a = [1;2]; >>> b = [3;4]; >>> [x,FLAG,RELRES,ITER] = lsqr(a,b, 1e-10, 10) > x = > 2.200000000000000 > FLAG = > 1 > RELRES = > 0.178885438199983 > ITER = > 1 >>> norm(a*x-b) > ans = > 0.894427190999916 > > ---------------------------------------------------- > > From chetan.jhurani at gmail.com Sat Aug 7 01:40:10 2010 From: chetan.jhurani at gmail.com (Chetan Jhurani) Date: Sat, 7 Aug 2010 00:40:10 -0600 Subject: [petsc-users] KSPLSQR convergence criterion In-Reply-To: <9EE60D8B-E2FC-4125-9951-F32E7C7411FB@mcs.anl.gov> References: <4c5c3ae7.de7ae60a.6e72.0fdf@mx.google.com> <9EE60D8B-E2FC-4125-9951-F32E7C7411FB@mcs.anl.gov> Message-ID: <4c5cffcd.0e14640a.7158.76b0@mx.google.com> Thanks for the quick fix. I'll check it out and let you know if there is any trouble. Chetan > -----Original Message----- > From: petsc-users-bounces at mcs.anl.gov [mailto:petsc-users-bounces at mcs.anl.gov] On Behalf Of Barry > Smith > Sent: Friday, August 06, 2010 10:29 PM > To: PETSc users list > Subject: Re: [petsc-users] KSPLSQR convergence criterion > > > Ok, here is my understanding of the situation: LSQR actually solves the normal equations A'*Ax = > A'x. When Ax = b has a solution then Matlab and PETSc use || b - Ax|| < tol to determine convergence. > Matlab also checks || A'*b - A'*Ax || < tol for convergence. > > In petsc-dev http://www.mcs.anl.gov/petsc/petsc-as/developers/index.html I have added an additional > test based on the residual norm of the normal equations || A'*b - A'*Ax || < tol I also added - > ksp_monitor_lsqr that prints the residual norm and the residual norm of the normal equations. For > example > > [barry-smiths-macbook-pro:~/Downloads] barrysmith% ./ex1 -ksp_max_it 10 -ksp_converged_reason - > ksp_monitor_lsqr > 0 KSP Residual norm 5.000000000000e+00 > 1 KSP Residual norm 8.944271909999e-01 Residual norm normal equations 1.807443084090e-15 > Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1 > > Please let me know if you have any troubles. > > Barry > > Note that I use a different scaling of tol for convergence test than Matlab (they try to approximate > the norm of the preconditioned matrix and include that inside the bound, in PETSc we never do this). > > > > On Aug 6, 2010, at 11:40 AM, Chetan Jhurani wrote: > > > Hello! > > > > Could someone help me figure out the correct way to > > to use KSPLSQR? Maybe I'm missing something simple. > > > > I'm trying to use it to solve an over-determined set > > of equations. It seems like the KSP iterations keep on > > going because the residual is not small enough. But > > since the system is over-determined, in general, the > > exact residual Ax - b will not be zero. > > > > For example, to solve the system > > > > min_x ||Ax - b||, with A = [1;2], b = [3;4], > > > > x must be inv(A'A)A'b = 2.2. Relative residual is 0.17888. > > See the Matlab code below too, which gives the correct > > value in 1 iteration. > > > > KSPLSQR, however, stagnates after 1 iteration. At that > > point, the relative residual and true residual norm > > match the correct values exactly. > > > > Is there an assumption in KSPLSQR that the system is always > > invertible or under-determined? This is petsc-3.1p2 if > > it matters. > > > > Thanks, > > > > Chetan > > > > ---------------------------------------------------- > > KSPLSQR: > > > > 0 KSP preconditioned resid norm 5.000000000000e+000 true resid norm 5.000000000000e+000 > ||Ae||/||Ax|| 1.000000000000e+000 > > 1 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > > 2 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > > 3 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > > 4 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > > 5 KSP preconditioned resid norm 8.944271909999e-001 true resid norm 8.944271909999e-001 > ||Ae||/||Ax|| 1.788854382000e-001 > > > > Matlab: > > > >>> a = [1;2]; > >>> b = [3;4]; > >>> [x,FLAG,RELRES,ITER] = lsqr(a,b, 1e-10, 10) > > x = > > 2.200000000000000 > > FLAG = > > 1 > > RELRES = > > 0.178885438199983 > > ITER = > > 1 > >>> norm(a*x-b) > > ans = > > 0.894427190999916 > > > > ---------------------------------------------------- > > > > From nemanja.ilic.81 at gmail.com Sun Aug 8 12:12:31 2010 From: nemanja.ilic.81 at gmail.com (=?utf-8?b?0J3QtdC80LDRmtCwINCY0LvQuNGb?= (Nemanja Ilic)) Date: Sun, 8 Aug 2010 19:12:31 +0200 Subject: [petsc-users] Finding determinant and inverse matrix In-Reply-To: References: <201008041918.31186.nemanja.ilic.81@gmail.com> <201008061600.05220.nemanja.ilic.81@gmail.com> Message-ID: <201008081912.31847.nemanja.ilic.81@gmail.com> Hello, Thank you for your reply, it was of great help. I managed to get determinant correctly. Could you direct me to the algorithm for producing upper/lower triangular matrices from petsc's LUFactor result? Are values in all columns inverted or just on the diagonal? What exactly is the result of LUFactor? Thank you, Regards, Nemanja On Friday 06 August 2010 19:46:38 Barry Smith wrote: > > Sorry for the confusion. PETSc stores the inverse of the diagonal entries (so in the triangular solves it does not need to do divides). Note that 1/26 = .0384615 so all you need to do is invert your result and you'll get the determinant. > > Barry > > On Aug 6, 2010, at 9:00 AM, ?????? ???? (Nemanja Ilic) wrote: > > > On Friday 06 August 2010 12:55:19 ?????? ???? (Nemanja Ilic) wrote: > >> Hello, > >> > >> For the matrix: 2 -2 0 > >> -1 5 1 > >> 3 4 5 > >> I get determinant = 0.0384615. The correct answer is 26. > >> Maybe I am doing LU Factorization wrong? > >> This is how I do LU Factoring: > >> ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm); CHKERRQ(ierr); > >> ierr = MatFactorInfoInitialize(&info); CHKERRQ(ierr); > >> ierr = MatLUFactor(Ap, perm, iperm, &info); CHKERRQ(ierr); > >> > >> This is the correct LU upper factotrization: 3.000 4.000 5.000 > >> 0.000 6.333 2.667 > >> 0.000 0.000 -1.368 > >> This is what I get: row 0: (0, 0.5) (1, -2) (2, 0) > >> row 1: (0, -0.5) (1, 0.25) (2, 1) > >> row 2: (0, 1.5) (1, 1.75) (2, 0.307692) > >> > >> Thank you, > >> regards, > >> Nemanja > >> > >> > >> On Wednesday 04 August 2010 23:19:37 you wrote: > >>> On Wed, Aug 4, 2010 at 12:18 PM, ?????? ???? (Nemanja Ilic) < > >>> nemanja.ilic.81 at gmail.com> wrote: > >>> > >>>> Hello, > >>>> > >>>> Thank you for you previous help. I wrote the code for calculating matrix > >>>> determinant and inverse matrix and they don't break anymore. Still I have > >>>> problems. I try to find determinant in the following way: First get LU > >>>> factor of a matrix and then multiply it's diagonal elements. I don't get > >>>> correct results. Could you tell me wheather the problem > >>> > >>> > >>> That description does not help. What do you get? What is the correct answer? > >>> Did you try it on a small > >>> problem that you can factor by hand? > >>> > >>> > >>>> is maybe in info structure? What information do you need to be able to help > >>>> me? I find the inverse matrix in the following way: I create linear problem > >>>> A * X = B where A is the input matrix, X is the inverse matrix, and B is > >>>> identity matrix. I solve it using MatMatSolve. Could you possibly help me > >>>> and what info do you need? > >>>> > >>> > >>> That should work. > >>> > >>> Matt > >>> > >>> > >>>> Thank you in advance, > >>>> Best regards, > >>>> Nemanja > >>>> > >>> > >>> > >>> > >> > >> > >> > > > > > > From bsmith at mcs.anl.gov Sun Aug 8 13:08:34 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Sun, 8 Aug 2010 13:08:34 -0500 Subject: [petsc-users] Finding determinant and inverse matrix In-Reply-To: <201008081912.31847.nemanja.ilic.81@gmail.com> References: <201008041918.31186.nemanja.ilic.81@gmail.com> <201008061600.05220.nemanja.ilic.81@gmail.com> <201008081912.31847.nemanja.ilic.81@gmail.com> Message-ID: <8BFFF06D-8300-4B48-9762-5707576F570B@mcs.anl.gov> The source code for forming the factorization and doing triangular solves is in src/mat/impls/aij/seq There are a couple of different data structures and hence algorithms depending on the use. You need to dig around in the code for details. Only the diagonal is inverted because that is the only one that needs to be inverted. Barry On Aug 8, 2010, at 12:12 PM, ?????? ???? (Nemanja Ilic) wrote: > Hello, > > Thank you for your reply, it was of great help. I managed to get determinant correctly. Could you direct me to the algorithm for producing upper/lower triangular matrices from petsc's LUFactor result? Are values in all columns inverted or just on the diagonal? What exactly is the result of LUFactor? > > Thank you, > Regards, > Nemanja > > > On Friday 06 August 2010 19:46:38 Barry Smith wrote: >> >> Sorry for the confusion. PETSc stores the inverse of the diagonal entries (so in the triangular solves it does not need to do divides). Note that 1/26 = .0384615 so all you need to do is invert your result and you'll get the determinant. >> >> Barry >> >> On Aug 6, 2010, at 9:00 AM, ?????? ???? (Nemanja Ilic) wrote: >> >>> On Friday 06 August 2010 12:55:19 ?????? ???? (Nemanja Ilic) wrote: >>>> Hello, >>>> >>>> For the matrix: 2 -2 0 >>>> -1 5 1 >>>> 3 4 5 >>>> I get determinant = 0.0384615. The correct answer is 26. >>>> Maybe I am doing LU Factorization wrong? >>>> This is how I do LU Factoring: >>>> ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm); CHKERRQ(ierr); >>>> ierr = MatFactorInfoInitialize(&info); CHKERRQ(ierr); >>>> ierr = MatLUFactor(Ap, perm, iperm, &info); CHKERRQ(ierr); >>>> >>>> This is the correct LU upper factotrization: 3.000 4.000 5.000 >>>> 0.000 6.333 2.667 >>>> 0.000 0.000 -1.368 >>>> This is what I get: row 0: (0, 0.5) (1, -2) (2, 0) >>>> row 1: (0, -0.5) (1, 0.25) (2, 1) >>>> row 2: (0, 1.5) (1, 1.75) (2, 0.307692) >>>> >>>> Thank you, >>>> regards, >>>> Nemanja >>>> >>>> >>>> On Wednesday 04 August 2010 23:19:37 you wrote: >>>>> On Wed, Aug 4, 2010 at 12:18 PM, ?????? ???? (Nemanja Ilic) < >>>>> nemanja.ilic.81 at gmail.com> wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>> Thank you for you previous help. I wrote the code for calculating matrix >>>>>> determinant and inverse matrix and they don't break anymore. Still I have >>>>>> problems. I try to find determinant in the following way: First get LU >>>>>> factor of a matrix and then multiply it's diagonal elements. I don't get >>>>>> correct results. Could you tell me wheather the problem >>>>> >>>>> >>>>> That description does not help. What do you get? What is the correct answer? >>>>> Did you try it on a small >>>>> problem that you can factor by hand? >>>>> >>>>> >>>>>> is maybe in info structure? What information do you need to be able to help >>>>>> me? I find the inverse matrix in the following way: I create linear problem >>>>>> A * X = B where A is the input matrix, X is the inverse matrix, and B is >>>>>> identity matrix. I solve it using MatMatSolve. Could you possibly help me >>>>>> and what info do you need? >>>>>> >>>>> >>>>> That should work. >>>>> >>>>> Matt >>>>> >>>>> >>>>>> Thank you in advance, >>>>>> Best regards, >>>>>> Nemanja >>>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>> >>> >> >> > > From nemanja.ilic.81 at gmail.com Mon Aug 9 13:00:15 2010 From: nemanja.ilic.81 at gmail.com (=?utf-8?b?0J3QtdC80LDRmtCwINCY0LvQuNGb?= (Nemanja Ilic)) Date: Mon, 9 Aug 2010 20:00:15 +0200 Subject: [petsc-users] Inverse matrix empty Message-ID: <201008092000.15494.nemanja.ilic.81@gmail.com> Hello, I want to get the inverse of a matrix. I use the following algorithm: I have input matrix (A), identity matrix (B) and I try to solve A * X = B, where X is the inverse matrix. I use MatMatSolve function. I included blas, fblas, and superlu libraries in my project but still I get empty inverse matrix. I factored A with LUFactor before calling MatMatSolve. What am I doing wrong? Thank you in advance, Regards, Nemanja From nemanja.ilic.81 at gmail.com Mon Aug 9 14:14:33 2010 From: nemanja.ilic.81 at gmail.com (=?utf-8?b?0J3QtdC80LDRmtCwINCY0LvQuNGb?= (Nemanja Ilic)) Date: Mon, 9 Aug 2010 21:14:33 +0200 Subject: [petsc-users] Inverse matrix empty In-Reply-To: References: <201008092000.15494.nemanja.ilic.81@gmail.com> Message-ID: <201008092114.33915.nemanja.ilic.81@gmail.com> Here is my code, Thank you, regards, Nemanja #include "math_petsc.h" #include #include #include #include double** getInverseMatrix( int num_rows_in, int num_columns_in, const char *file_name, const char *output_file_name) { double **X = NULL; Mat Ap; // input matrix Mat Bp, // identity matrix Xp; // result matrix PetscErrorCode ierr; // error code PetscInt i, j, // iterator variable *col, // column indices *row, // row indices ap_num_rows, // number of rows ap_num_columns; // number of columns FILE *file; // input file IS perm_rows, perm_cols; MatFactorInfo lu_info, fact_info; KSP ksp; PC pc; IS perm, iperm; MatFactorInfo info; PetscInt rank, size; ap_num_rows = num_rows_in; ap_num_columns = num_columns_in; ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size); CHKERRQ(ierr); printf("MPI_Comm_rank = %d\nMPI_Comm_size = %d\n", rank, size); // open file and read number of rows and columns ierr = PetscFOpen(PETSC_COMM_SELF, file_name, "r", &file); CHKERRQ(ierr); // alocate column and row indices col = (PetscInt*) malloc(ap_num_columns * sizeof(PetscInt)); row = (PetscInt*) malloc(ap_num_rows * sizeof(PetscInt)); // create matrices ierr = MatCreate(PETSC_COMM_WORLD, &Ap); CHKERRQ(ierr); ierr = MatSetSizes(Ap, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, ap_num_columns); CHKERRQ(ierr); ierr = MatSetFromOptions(Ap); CHKERRQ(ierr); ierr = MatCreate(PETSC_COMM_WORLD, &Bp); CHKERRQ(ierr); ierr = MatSetSizes(Bp, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, ap_num_columns); CHKERRQ(ierr); ierr = MatSetFromOptions(Bp); CHKERRQ(ierr); ierr = MatCreate(PETSC_COMM_WORLD, &Xp); CHKERRQ(ierr); ierr = MatSetSizes(Xp, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, ap_num_columns); CHKERRQ(ierr); ierr = MatSetFromOptions(Xp); CHKERRQ(ierr); /* ierr = MatCreate(PETSC_COMM_WORLD, &fact); CHKERRQ(ierr); ierr = MatSetSizes(fact, PETSC_DECIDE, PETSC_DECIDE, m, n); CHKERRQ(ierr); ierr = MatSetFromOptions(fact); CHKERRQ(ierr); */ // populate row index vector for (i = 0; i < ap_num_rows; ++i) row[i] = i; // populate column index variable for (i = 0; i < ap_num_columns; ++i) col[i] = i; // now populate matrix double *row_values = (double*) malloc(ap_num_columns * sizeof(double)); for (i = 0; i < ap_num_rows; ++i) { for (j = 0; j < ap_num_columns; ++j) { fscanf(file, "%lg", &row_values[j]); } printf("%f %f %f\n", row_values[j-3], row_values[j-2], row_values[j-1]); // add row to matrix ierr = MatSetValues(Ap, 1, &i, ap_num_columns, col, row_values, INSERT_VALUES); CHKERRQ(ierr); } ierr = MatAssemblyBegin(Ap, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); ierr = MatAssemblyEnd(Ap, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); ierr = MatView(Ap, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); // factor the matrix ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm);CHKERRQ(ierr); ierr = MatFactorInfoInitialize(&info);CHKERRQ(ierr); ierr = MatLUFactor(Ap, perm, iperm, &info);CHKERRQ(ierr); // the identity matrix double identity_values[ap_num_columns]; memset(identity_values, 0, ap_num_columns * sizeof(double)); for (i = 0; i < ap_num_rows; ++i) { identity_values[i] = 1; if (i != 0) identity_values[i-1] = 0; ierr = MatSetValues(Bp, 1, &i, ap_num_columns, col, identity_values, INSERT_VALUES); CHKERRQ(ierr); } ierr = MatAssemblyBegin(Bp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); ierr = MatAssemblyEnd(Bp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); // view identity matrix printf("This is the identity matrix:\n"); ierr = MatView(Bp, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); // create solver context ierr = KSPCreate(PETSC_COMM_WORLD, &ksp); CHKERRQ(ierr); ierr = KSPSetOperators(ksp, Ap, Ap, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr); // ierr = KSPSetOperators(ksp, Bp, Bp, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr); // ierr = KSPSetOperators(ksp, Xp, Xp, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr); ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr); ierr = PCSetType(pc,PCJACOBI);CHKERRQ(ierr); ierr = KSPSetTolerances(ksp,1.e-7,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);CHKERRQ(ierr); ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr); // !!!!! get inverse matrix !!!!! ierr = MatMatSolve(Ap, Bp, Xp); CHKERRQ(ierr); // assemble matrix ierr = MatAssemblyBegin(Xp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); ierr = MatAssemblyEnd(Xp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); // print result printf("This is the result:\n"); ierr = MatView(Xp, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); // write result to file PetscViewer viewer; ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, output_file_name, &viewer); CHKERRQ(ierr); ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_COMMON); CHKERRQ(ierr); ierr = MatView(Xp, viewer); CHKERRQ(ierr); // clean-up ierr = MatDestroy(Ap); CHKERRQ(ierr); ierr = MatDestroy(Bp); CHKERRQ(ierr); ierr = MatDestroy(Xp); CHKERRQ(ierr); free(col); free(row); free(row_values); return X; } On Monday 09 August 2010 20:14:01 you wrote: > Send me the segment of your code for computing inv(A). > I'll check it. > > Hong > > On Mon, Aug 9, 2010 at 1:00 PM, ?????? ???? (Nemanja Ilic) > wrote: > > Hello, > > > > I want to get the inverse of a matrix. I use the following algorithm: I have input matrix (A), identity matrix (B) and I try to solve A * X = B, where X is the inverse matrix. I use MatMatSolve function. I included blas, fblas, and superlu libraries in my project but still I get empty inverse matrix. I factored A with LUFactor before calling MatMatSolve. What am I doing wrong? > > > > Thank you in advance, > > Regards, > > Nemanja > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bsmith at mcs.anl.gov Mon Aug 9 14:54:32 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Mon, 9 Aug 2010 14:54:32 -0500 Subject: [petsc-users] Inverse matrix empty In-Reply-To: <201008092114.33915.nemanja.ilic.81@gmail.com> References: <201008092000.15494.nemanja.ilic.81@gmail.com> <201008092114.33915.nemanja.ilic.81@gmail.com> Message-ID: <73B8FFBD-6446-4262-B551-019ACBD907F7@mcs.anl.gov> call MatView() on your Xp before doing the solve, likely that is set wrong. Barry On Aug 9, 2010, at 2:14 PM, ?????? ???? (Nemanja Ilic) wrote: > Here is my code, > > > Thank you, > > regards, > > Nemanja > > > > #include "math_petsc.h" > > > #include > > > #include > > #include > > #include > > > double** getInverseMatrix( > > int num_rows_in, > > int num_columns_in, > > const char *file_name, > > const char *output_file_name) > > { > > double **X = NULL; > > Mat Ap; // input matrix > > Mat Bp, // identity matrix > > Xp; // result matrix > > PetscErrorCode ierr; // error code > > PetscInt i, j, // iterator variable > > *col, // column indices > > *row, // row indices > > ap_num_rows, // number of rows > > ap_num_columns; // number of columns > > FILE *file; // input file > > IS perm_rows, perm_cols; > > MatFactorInfo lu_info, fact_info; > > KSP ksp; > > PC pc; > > IS perm, iperm; > > MatFactorInfo info; > > > PetscInt rank, size; > > ap_num_rows = num_rows_in; > > ap_num_columns = num_columns_in; > > > ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr); > > ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size); CHKERRQ(ierr); > > > printf("MPI_Comm_rank = %d\nMPI_Comm_size = %d\n", rank, size); > > > // open file and read number of rows and columns > > ierr = PetscFOpen(PETSC_COMM_SELF, file_name, "r", &file); CHKERRQ(ierr); > > > > // alocate column and row indices > > col = (PetscInt*) malloc(ap_num_columns * sizeof(PetscInt)); > > row = (PetscInt*) malloc(ap_num_rows * sizeof(PetscInt)); > > > > // create matrices > > ierr = MatCreate(PETSC_COMM_WORLD, &Ap); CHKERRQ(ierr); > > ierr = MatSetSizes(Ap, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, ap_num_columns); CHKERRQ(ierr); > > ierr = MatSetFromOptions(Ap); CHKERRQ(ierr); > > > ierr = MatCreate(PETSC_COMM_WORLD, &Bp); CHKERRQ(ierr); > > ierr = MatSetSizes(Bp, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, ap_num_columns); CHKERRQ(ierr); > > ierr = MatSetFromOptions(Bp); CHKERRQ(ierr); > > > ierr = MatCreate(PETSC_COMM_WORLD, &Xp); CHKERRQ(ierr); > > ierr = MatSetSizes(Xp, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, ap_num_columns); CHKERRQ(ierr); > > ierr = MatSetFromOptions(Xp); CHKERRQ(ierr); > > > /* ierr = MatCreate(PETSC_COMM_WORLD, &fact); CHKERRQ(ierr); > > ierr = MatSetSizes(fact, PETSC_DECIDE, PETSC_DECIDE, m, n); CHKERRQ(ierr); > > ierr = MatSetFromOptions(fact); CHKERRQ(ierr); > > */ > > > // populate row index vector > > for (i = 0; i < ap_num_rows; ++i) > > row[i] = i; > > // populate column index variable > > for (i = 0; i < ap_num_columns; ++i) > > col[i] = i; > > > // now populate matrix > > double *row_values = (double*) malloc(ap_num_columns * sizeof(double)); > > for (i = 0; i < ap_num_rows; ++i) > > { > > for (j = 0; j < ap_num_columns; ++j) > > { > > fscanf(file, "%lg", &row_values[j]); > > } > > printf("%f %f %f\n", row_values[j-3], row_values[j-2], row_values[j-1]); > > // add row to matrix > > ierr = MatSetValues(Ap, 1, &i, ap_num_columns, col, row_values, INSERT_VALUES); CHKERRQ(ierr); > > } > > ierr = MatAssemblyBegin(Ap, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > ierr = MatAssemblyEnd(Ap, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > > ierr = MatView(Ap, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); > > > > > // factor the matrix > > ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm);CHKERRQ(ierr); > > ierr = MatFactorInfoInitialize(&info);CHKERRQ(ierr); > > ierr = MatLUFactor(Ap, perm, iperm, &info);CHKERRQ(ierr); > > > > // the identity matrix > > double identity_values[ap_num_columns]; > > memset(identity_values, 0, ap_num_columns * sizeof(double)); > > for (i = 0; i < ap_num_rows; ++i) > > { > > identity_values[i] = 1; > > if (i != 0) > > identity_values[i-1] = 0; > > ierr = MatSetValues(Bp, 1, &i, ap_num_columns, col, identity_values, INSERT_VALUES); CHKERRQ(ierr); > > } > > ierr = MatAssemblyBegin(Bp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > ierr = MatAssemblyEnd(Bp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > > // view identity matrix > > printf("This is the identity matrix:\n"); > > ierr = MatView(Bp, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); > > > // create solver context > > ierr = KSPCreate(PETSC_COMM_WORLD, &ksp); CHKERRQ(ierr); > > ierr = KSPSetOperators(ksp, Ap, Ap, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr); > > // ierr = KSPSetOperators(ksp, Bp, Bp, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr); > > // ierr = KSPSetOperators(ksp, Xp, Xp, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr); > > ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr); > > ierr = PCSetType(pc,PCJACOBI);CHKERRQ(ierr); > > ierr = KSPSetTolerances(ksp,1.e-7,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);CHKERRQ(ierr); > > ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr); > > > > // !!!!! get inverse matrix !!!!! > > ierr = MatMatSolve(Ap, Bp, Xp); CHKERRQ(ierr); > > > > // assemble matrix > > ierr = MatAssemblyBegin(Xp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > ierr = MatAssemblyEnd(Xp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > > // print result > > printf("This is the result:\n"); > > ierr = MatView(Xp, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); > > > // write result to file > > > PetscViewer viewer; > > ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, output_file_name, &viewer); CHKERRQ(ierr); > > ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_COMMON); CHKERRQ(ierr); > > ierr = MatView(Xp, viewer); CHKERRQ(ierr); > > > // clean-up > > ierr = MatDestroy(Ap); CHKERRQ(ierr); > > ierr = MatDestroy(Bp); CHKERRQ(ierr); > > ierr = MatDestroy(Xp); CHKERRQ(ierr); > > > > free(col); > > free(row); > > free(row_values); > > > return X; > > } > > > > On Monday 09 August 2010 20:14:01 you wrote: > > > Send me the segment of your code for computing inv(A). > > > I'll check it. > > > > > > Hong > > > > > > On Mon, Aug 9, 2010 at 1:00 PM, ?????? ???? (Nemanja Ilic) > > > wrote: > > > > Hello, > > > > > > > > I want to get the inverse of a matrix. I use the following algorithm: I have input matrix (A), identity matrix (B) and I try to solve A * X = B, where X is the inverse matrix. I use MatMatSolve function. I included blas, fblas, and superlu libraries in my project but still I get empty inverse matrix. I factored A with LUFactor before calling MatMatSolve. What am I doing wrong? > > > > > > > > Thank you in advance, > > > > Regards, > > > > Nemanja > > > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hzhang at mcs.anl.gov Mon Aug 9 15:03:36 2010 From: hzhang at mcs.anl.gov (Hong Zhang) Date: Mon, 9 Aug 2010 15:03:36 -0500 Subject: [petsc-users] Inverse matrix empty In-Reply-To: <201008092114.33915.nemanja.ilic.81@gmail.com> References: <201008092000.15494.nemanja.ilic.81@gmail.com> <201008092114.33915.nemanja.ilic.81@gmail.com> Message-ID: Your calling procedure is incorrect. See ~petsc/src/mat/examples/tests/ex129.c on how to use MatMatMult(). You do not need KSP object. Here are suggested calls: Mat F; // store matrix factors ierr = MatGetOrdering(Ap,MATORDERINGND,&perm,&iperm);CHKERRQ(ierr); ierr = MatGetFactor(Ap,MATSOLVERPETSC,MAT_FACTOR_LU,&F);CHKERRQ(ierr); ierr = MatFactorInfoInitialize(&info);CHKERRQ(ierr); info.fill = 5.0; ierr = MatLUFactorSymbolic(F,Ap,perm,iperm,&info);CHKERRQ(ierr); ierr = MatLUFactorNumeric(F,Ap,&info);CHKERRQ(ierr); ierr = MatMatSolve(F,Bp,Xp);CHKERRQ(ierr); Hong On Mon, Aug 9, 2010 at 2:14 PM, ?????? ???? (Nemanja Ilic) wrote: > Here is my code, > > Thank you, > > regards, > > Nemanja > > #include "math_petsc.h" > > #include > > #include > > #include > > #include > > double** getInverseMatrix( > > int num_rows_in, > > int num_columns_in, > > const char *file_name, > > const char *output_file_name) > > { > > double **X = NULL; > > Mat Ap; // input matrix > > Mat Bp, // identity matrix > > Xp; // result matrix > > PetscErrorCode ierr; // error code > > PetscInt i, j, // iterator variable > > *col, // column indices > > *row, // row indices > > ap_num_rows, // number of rows > > ap_num_columns; // number of columns > > FILE *file; // input file > > IS perm_rows, perm_cols; > > MatFactorInfo lu_info, fact_info; > > KSP ksp; > > PC pc; > > IS perm, iperm; > > MatFactorInfo info; > > PetscInt rank, size; > > ap_num_rows = num_rows_in; > > ap_num_columns = num_columns_in; > > ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr); > > ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size); CHKERRQ(ierr); > > printf("MPI_Comm_rank = %d\nMPI_Comm_size = %d\n", rank, size); > > // open file and read number of rows and columns > > ierr = PetscFOpen(PETSC_COMM_SELF, file_name, "r", &file); CHKERRQ(ierr); > > // alocate column and row indices > > col = (PetscInt*) malloc(ap_num_columns * sizeof(PetscInt)); > > row = (PetscInt*) malloc(ap_num_rows * sizeof(PetscInt)); > > // create matrices > > ierr = MatCreate(PETSC_COMM_WORLD, &Ap); CHKERRQ(ierr); > > ierr = MatSetSizes(Ap, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, > ap_num_columns); CHKERRQ(ierr); > > ierr = MatSetFromOptions(Ap); CHKERRQ(ierr); > > ierr = MatCreate(PETSC_COMM_WORLD, &Bp); CHKERRQ(ierr); > > ierr = MatSetSizes(Bp, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, > ap_num_columns); CHKERRQ(ierr); > > ierr = MatSetFromOptions(Bp); CHKERRQ(ierr); > > ierr = MatCreate(PETSC_COMM_WORLD, &Xp); CHKERRQ(ierr); > > ierr = MatSetSizes(Xp, PETSC_DECIDE, PETSC_DECIDE, ap_num_rows, > ap_num_columns); CHKERRQ(ierr); > > ierr = MatSetFromOptions(Xp); CHKERRQ(ierr); > > /* ierr = MatCreate(PETSC_COMM_WORLD, &fact); CHKERRQ(ierr); > > ierr = MatSetSizes(fact, PETSC_DECIDE, PETSC_DECIDE, m, n); CHKERRQ(ierr); > > ierr = MatSetFromOptions(fact); CHKERRQ(ierr); > > */ > > // populate row index vector > > for (i = 0; i < ap_num_rows; ++i) > > row[i] = i; > > // populate column index variable > > for (i = 0; i < ap_num_columns; ++i) > > col[i] = i; > > // now populate matrix > > double *row_values = (double*) malloc(ap_num_columns * sizeof(double)); > > for (i = 0; i < ap_num_rows; ++i) > > { > > for (j = 0; j < ap_num_columns; ++j) > > { > > fscanf(file, "%lg", &row_values[j]); > > } > > printf("%f %f %f\n", row_values[j-3], row_values[j-2], row_values[j-1]); > > // add row to matrix > > ierr = MatSetValues(Ap, 1, &i, ap_num_columns, col, row_values, > INSERT_VALUES); CHKERRQ(ierr); > > } > > ierr = MatAssemblyBegin(Ap, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > ierr = MatAssemblyEnd(Ap, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > ierr = MatView(Ap, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); > > // factor the matrix > > ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm);CHKERRQ(ierr); > > ierr = MatFactorInfoInitialize(&info);CHKERRQ(ierr); > > ierr = MatLUFactor(Ap, perm, iperm, &info);CHKERRQ(ierr); > > // the identity matrix > > double identity_values[ap_num_columns]; > > memset(identity_values, 0, ap_num_columns * sizeof(double)); > > for (i = 0; i < ap_num_rows; ++i) > > { > > identity_values[i] = 1; > > if (i != 0) > > identity_values[i-1] = 0; > > ierr = MatSetValues(Bp, 1, &i, ap_num_columns, col, identity_values, > INSERT_VALUES); CHKERRQ(ierr); > > } > > ierr = MatAssemblyBegin(Bp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > ierr = MatAssemblyEnd(Bp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > // view identity matrix > > printf("This is the identity matrix:\n"); > > ierr = MatView(Bp, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); > > // create solver context > > ierr = KSPCreate(PETSC_COMM_WORLD, &ksp); CHKERRQ(ierr); > > ierr = KSPSetOperators(ksp, Ap, Ap, DIFFERENT_NONZERO_PATTERN); > CHKERRQ(ierr); > > // ierr = KSPSetOperators(ksp, Bp, Bp, DIFFERENT_NONZERO_PATTERN); > CHKERRQ(ierr); > > // ierr = KSPSetOperators(ksp, Xp, Xp, DIFFERENT_NONZERO_PATTERN); > CHKERRQ(ierr); > > ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr); > > ierr = PCSetType(pc,PCJACOBI);CHKERRQ(ierr); > > ierr = > KSPSetTolerances(ksp,1.e-7,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);CHKERRQ(ierr); > > ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr); > > // !!!!! get inverse matrix !!!!! > > ierr = MatMatSolve(Ap, Bp, Xp); CHKERRQ(ierr); > > // assemble matrix > > ierr = MatAssemblyBegin(Xp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > ierr = MatAssemblyEnd(Xp, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); > > // print result > > printf("This is the result:\n"); > > ierr = MatView(Xp, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); > > // write result to file > > PetscViewer viewer; > > ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, output_file_name, &viewer); > CHKERRQ(ierr); > > ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_COMMON); > CHKERRQ(ierr); > > ierr = MatView(Xp, viewer); CHKERRQ(ierr); > > // clean-up > > ierr = MatDestroy(Ap); CHKERRQ(ierr); > > ierr = MatDestroy(Bp); CHKERRQ(ierr); > > ierr = MatDestroy(Xp); CHKERRQ(ierr); > > free(col); > > free(row); > > free(row_values); > > return X; > > } > > On Monday 09 August 2010 20:14:01 you wrote: > >> Send me the segment of your code for computing inv(A). > >> I'll check it. > >> > >> Hong > >> > >> On Mon, Aug 9, 2010 at 1:00 PM, ?????? ???? (Nemanja Ilic) > >> wrote: > >> > Hello, > >> > > >> > I want to get the inverse of a matrix. I use the following algorithm: I >> > have input matrix (A), identity matrix (B) and I try to solve A * X = B, >> > where X is the inverse matrix. I use MatMatSolve function. I included blas, >> > fblas, and superlu libraries in my project but still I get empty inverse >> > matrix. I factored A with LUFactor before calling MatMatSolve. What am I >> > doing wrong? > >> > > >> > Thank you in advance, > >> > Regards, > >> > Nemanja > >> > > >> From lizs at mail.uc.edu Tue Aug 10 12:42:26 2010 From: lizs at mail.uc.edu (Li, Zhisong (lizs)) Date: Tue, 10 Aug 2010 17:42:26 +0000 Subject: [petsc-users] Does Petsc have any feature to handle the mirror points? Message-ID: <88D7E3BB7E1960428303E760100374510FA46969@BL2PRD0103MB055.prod.exchangelabs.com> Hi, Petsc Team, In finite difference computations, we often utilize schemes of five or more points stencil in one direction. To calculate the interior point next to the boundary, we need to assume one point out of the domain by extrapolation (such as a mirror point). As we are required to include all interior points and boundary points in the system matrix, does Petsc have any feature to handle these mirror points ? In assembling the matrix for a 3D system of multiple variables and equations, besides setting up the boundary conditions, I think this will cost lots of extra effort to specially manage the points next to the boundary, if Petsc doesn't have any easy way to do this. Thank you. Zhisong Li -------------- next part -------------- An HTML attachment was scrubbed... URL: From jed at 59A2.org Tue Aug 10 13:23:36 2010 From: jed at 59A2.org (Jed Brown) Date: Tue, 10 Aug 2010 10:23:36 -0800 Subject: [petsc-users] Does Petsc have any feature to handle the mirror points? In-Reply-To: <88D7E3BB7E1960428303E760100374510FA46969@BL2PRD0103MB055.prod.exchangelabs.com> References: <88D7E3BB7E1960428303E760100374510FA46969@BL2PRD0103MB055.prod.exchangelabs.com> Message-ID: I assume you are using DA. One way is to use a periodic stencil so that the local vector has room for those points. Another is to never put them into an array (you don't really want them in the global system anyway, and the Jacobian still needs to differentiate through the process by which you decide what to put in those slots). For something more complicated like immersed boundary methods, you will leave those points in and it might be impractical to differentiate through the computation of values at mirror points. The approximation you use will then affect convergence rate. Jed On Aug 10, 2010 9:42 AM, "Li, Zhisong (lizs)" wrote: Hi, Petsc Team, In finite difference computations, we often utilize schemes of five or more points stencil in one direction. To calculate the interior point next to the boundary, we need to assume one point out of the domain by extrapolation (such as a mirror point). As we are required to include all interior points and boundary points in the system matrix, does Petsc have any feature to handle these mirror points ? In assembling the matrix for a 3D system of multiple variables and equations, besides setting up the boundary conditions, I think this will cost lots of extra effort to specially manage the points next to the boundary, if Petsc doesn't have any easy way to do this. Thank you. Zhisong Li -------------- next part -------------- An HTML attachment was scrubbed... URL: From Joey.Hegarty at al.com.au Tue Aug 10 20:46:40 2010 From: Joey.Hegarty at al.com.au (Joey Hegarty) Date: Wed, 11 Aug 2010 11:46:40 +1000 Subject: [petsc-users] Dynamically changing coarse and levels DMMG preconditioners Message-ID: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> Hi folks, I'm looking for a way to update the coarse and levels preconditioners used during the DMMG solve after PETSc has been initialized. I can update some options dynamically like so: KSP ksp = DMMGGetKSP(dmmg); KSPSetTolerances(ksp, ...); KSPGMRESSetRestart(ksp, ...); But I do not see a clear way of updating the coarse and levels preconditioner types in a similar way. Am I missing something obvious? Apologise if this has been asked before. Cheers, Joey From jed at 59A2.org Tue Aug 10 20:59:01 2010 From: jed at 59A2.org (Jed Brown) Date: Tue, 10 Aug 2010 17:59:01 -0800 Subject: [petsc-users] Dynamically changing coarse and levels DMMG preconditioners In-Reply-To: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> References: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> Message-ID: <87d3tp52qi.fsf@59A2.org> On Wed, 11 Aug 2010 11:46:40 +1000, Joey Hegarty wrote: > Hi folks, > > I'm looking for a way to update the coarse and levels preconditioners used during the DMMG solve after PETSc has been initialized. > > I can update some options dynamically like so: > > KSP ksp = DMMGGetKSP(dmmg); > KSPSetTolerances(ksp, ...); > KSPGMRESSetRestart(ksp, ...); > > But I do not see a clear way of updating the coarse and levels preconditioner types in a similar way. Am I missing something obvious? Apologise if this has been asked before. See PCMGGetSmoother() and PCMGGetCoarseSolve(). Jed From knepley at gmail.com Tue Aug 10 20:57:01 2010 From: knepley at gmail.com (Matthew Knepley) Date: Tue, 10 Aug 2010 20:57:01 -0500 Subject: [petsc-users] Dynamically changing coarse and levels DMMG preconditioners In-Reply-To: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> References: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> Message-ID: On Tue, Aug 10, 2010 at 8:46 PM, Joey Hegarty wrote: > Hi folks, > > I'm looking for a way to update the coarse and levels preconditioners used > during the DMMG solve after PETSc has been initialized. > > I can update some options dynamically like so: > > KSP ksp = DMMGGetKSP(dmmg); > KSPSetTolerances(ksp, ...); > KSPGMRESSetRestart(ksp, ...); > > But I do not see a clear way of updating the coarse and levels > preconditioner types in a similar way. Am I missing something obvious? > Apologise if this has been asked before. > dmmg is just an array. DMMGGetKSP() is a macro that does dmmg[L-1].ksp for a DMMG of L levels. For the coarse level, you can use dmmg[0]. We should have something better, but this will work for now. Matt > Cheers, > Joey > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From nemanja.ilic.81 at gmail.com Wed Aug 11 12:05:38 2010 From: nemanja.ilic.81 at gmail.com (=?utf-8?b?0J3QtdC80LDRmtCwINCY0LvQuNGb?= (Nemanja Ilic)) Date: Wed, 11 Aug 2010 19:05:38 +0200 Subject: [petsc-users] LU Decomposition In-Reply-To: <201008101752.53933.nemanja.ilic.81@gmail.com> References: <201008092000.15494.nemanja.ilic.81@gmail.com> <201008101752.53933.nemanja.ilic.81@gmail.com> Message-ID: <201008111905.38921.nemanja.ilic.81@gmail.com> Hello, I figured this one myself :) As I was told in a previous email (thanks Barry), it depends on used Petsc's algorithm what will be the result of LU factoring. If matrix is created with MatCreateSeqDense and MatLUFactorSymbolic and MatLUFactorNumeric are used then the result matrix is simply "concatenated" L and U triangular matrices and elements on the diagonal are not inverted. regards, Nemanja On Tuesday 10 August 2010 17:52:53 ?????? ???? (Nemanja Ilic) wrote: > Hello, > > Thank you very much, Hong and Barry. I managet to get inverse matrix following your advice! Could you tell me what are the elements of the result of LUFactor in respect to upper and lower triangular decomposition matrices? I know that elements on the diagonal are inverted. > > Thank you, > regards, > Nemanja > From hong at aspiritech.org Wed Aug 11 16:14:10 2010 From: hong at aspiritech.org (Hong Zhang) Date: Wed, 11 Aug 2010 16:14:10 -0500 Subject: [petsc-users] LU Decomposition In-Reply-To: <201008111905.38921.nemanja.ilic.81@gmail.com> References: <201008092000.15494.nemanja.ilic.81@gmail.com> <201008101752.53933.nemanja.ilic.81@gmail.com> <201008111905.38921.nemanja.ilic.81@gmail.com> Message-ID: Nemanja, Petsc LU solver for seqdense is a wrapper of LAPACK's routines (see src/mat/impls/dense/seq/dense.c). For Petsc's sparse LU, the diagonals are inverted. Hong On Wed, Aug 11, 2010 at 12:05 PM, ?????? ???? (Nemanja Ilic) wrote: > Hello, > > I figured this one myself :) As I was told in a previous email (thanks Barry), it depends on used Petsc's algorithm what will be the result of LU factoring. If matrix is created with MatCreateSeqDense and MatLUFactorSymbolic and MatLUFactorNumeric are used then the result matrix is simply "concatenated" L and U triangular matrices and elements on the diagonal are not inverted. > > regards, > Nemanja > > > On Tuesday 10 August 2010 17:52:53 ?????? ???? (Nemanja Ilic) wrote: >> Hello, >> >> Thank you very much, Hong and Barry. I managet to get inverse matrix following your advice! Could you tell me what are the elements of the result of LUFactor in respect to upper and lower triangular decomposition matrices? I know that elements on the diagonal are inverted. >> >> Thank you, >> regards, >> Nemanja >> > From Joey.Hegarty at al.com.au Wed Aug 11 18:19:41 2010 From: Joey.Hegarty at al.com.au (Joey Hegarty) Date: Thu, 12 Aug 2010 09:19:41 +1000 Subject: [petsc-users] Dynamically changing coarse and levels DMMG preconditioners In-Reply-To: References: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> Message-ID: <54D21FF830611A45A208A4DC0F98B87C07982E8F69@exchdb01> Thanks Matt / Jed for the rapid reply, that's what I was looking for. Cheers, Joey From: petsc-users-bounces at mcs.anl.gov [mailto:petsc-users-bounces at mcs.anl.gov] On Behalf Of Matthew Knepley Sent: Wednesday, 11 August 2010 11:57 AM To: PETSc users list Subject: Re: [petsc-users] Dynamically changing coarse and levels DMMG preconditioners On Tue, Aug 10, 2010 at 8:46 PM, Joey Hegarty > wrote: Hi folks, I'm looking for a way to update the coarse and levels preconditioners used during the DMMG solve after PETSc has been initialized. I can update some options dynamically like so: KSP ksp = DMMGGetKSP(dmmg); KSPSetTolerances(ksp, ...); KSPGMRESSetRestart(ksp, ...); But I do not see a clear way of updating the coarse and levels preconditioner types in a similar way. Am I missing something obvious? Apologise if this has been asked before. dmmg is just an array. DMMGGetKSP() is a macro that does dmmg[L-1].ksp for a DMMG of L levels. For the coarse level, you can use dmmg[0]. We should have something better, but this will work for now. Matt Cheers, Joey -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From Chun.SUN at 3ds.com Mon Aug 16 09:54:27 2010 From: Chun.SUN at 3ds.com (SUN Chun) Date: Mon, 16 Aug 2010 10:54:27 -0400 Subject: [petsc-users] zero out a sub matrix In-Reply-To: <54D21FF830611A45A208A4DC0F98B87C07982E8F69@exchdb01> References: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> <54D21FF830611A45A208A4DC0F98B87C07982E8F69@exchdb01> Message-ID: <2545DC7A42DF804AAAB2ADA5043D57DA9EC4E8@CORP-CLT-EXB01.ds> Hi Petsc Dev, Is there an efficient way to zero out a sub-matrix in the whole matrix? I can get it from MatGetSubMatrix easily. Is there a way to put it back without looping over the non-zeros? Thanks, Chun This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email.For other languages, go to http://www.3ds.com/terms/email-disclaimer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Mon Aug 16 09:59:01 2010 From: knepley at gmail.com (Matthew Knepley) Date: Mon, 16 Aug 2010 14:59:01 +0000 Subject: [petsc-users] zero out a sub matrix In-Reply-To: <2545DC7A42DF804AAAB2ADA5043D57DA9EC4E8@CORP-CLT-EXB01.ds> References: <54D21FF830611A45A208A4DC0F98B87C07982E8B3C@exchdb01> <54D21FF830611A45A208A4DC0F98B87C07982E8F69@exchdb01> <2545DC7A42DF804AAAB2ADA5043D57DA9EC4E8@CORP-CLT-EXB01.ds> Message-ID: On Mon, Aug 16, 2010 at 2:54 PM, SUN Chun wrote: > Hi Petsc Dev, > > > > Is there an efficient way to zero out a sub-matrix in the whole matrix? I > can get it from MatGetSubMatrix easily. Is there a way to put it back > without looping over the non-zeros? > There is no easier way than MatSetValues currently. Matt > > > Thanks, > > Chun > > This email and any attachments are intended solely for the use of the > individual or entity to whom it is addressed and may be confidential and/or > privileged. > > If you are not one of the named recipients or have received this email in > error, > > (i) you should not read, disclose, or copy it, > > (ii) please notify sender of your receipt by reply email and delete this > email and all attachments, > > (iii) Dassault Systemes does not accept or assume any liability or > responsibility for any use of or reliance on this email. > > For other languages, Click Here > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From lizs at mail.uc.edu Wed Aug 18 00:28:37 2010 From: lizs at mail.uc.edu (Li, Zhisong (lizs)) Date: Wed, 18 Aug 2010 05:28:37 +0000 Subject: [petsc-users] Whether multiple DA objects of equal dimensions generate the same domain decomposition ? Message-ID: <88D7E3BB7E1960428303E760100374510FA46B07@BL2PRD0103MB055.prod.exchangelabs.com> Hi, Petsc team, For quite a while, I have a wonder that whether two DA objects of equal dimensions (x, y, z) will generate the same domain decomposition in a parallel computation? In my understanding of PETSc, sometimes we have to use different DA objects because of the restrictions of the generated matrix and DOF associated with a DA. For example, for a given structured domain, we may use da1 to store the velocities (u, v, w, DOF = 3), and da2 to store the pressure (p, DOF = 1), as we want to compute them separately. Matrice from DAGetMatrix() must be of different sizes for da1 and da2 because of different DOF. On the other hand, we also want to project pressure to velocities point to point. So whether da1 and da2 will distribute exactly the same portion of the overall domain on each computer node when we're running parallelly? If not, how can we achieve it? Thank you very much! Regards, Zhisong Li -------------- next part -------------- An HTML attachment was scrubbed... URL: From bsmith at mcs.anl.gov Wed Aug 18 00:40:41 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Wed, 18 Aug 2010 00:40:41 -0500 Subject: [petsc-users] Whether multiple DA objects of equal dimensions generate the same domain decomposition ? In-Reply-To: <88D7E3BB7E1960428303E760100374510FA46B07@BL2PRD0103MB055.prod.exchangelabs.com> References: <88D7E3BB7E1960428303E760100374510FA46B07@BL2PRD0103MB055.prod.exchangelabs.com> Message-ID: <4D7BE599-F85A-4D50-AE98-FCEB0B8C0015@mcs.anl.gov> On Aug 18, 2010, at 12:28 AM, "Li, Zhisong (lizs)" wrote: > Hi, Petsc team, > > For quite a while, I have a wonder that whether two DA objects of equal dimensions (x, y, z) will generate the same domain decomposition in a parallel computation? Yes, the logic on default decompositions only depends on M N and P not on dof. > > In my understanding of PETSc, sometimes we have to use different DA objects because of the restrictions of the generated matrix and DOF associated with a DA. For example, for a given structured domain, we may use da1 to store the velocities (u, v, w, DOF = 3), and da2 to store the pressure (p, DOF = 1), as we want to compute them separately. Matrice from DAGetMatrix() must be of different sizes for da1 and da2 because of different DOF. On the other hand, we also want to project pressure to velocities point to point. So whether da1 and da2 will distribute exactly the same portion of the overall domain on each computer node when we're running parallelly? If not, how can we achieve it? > The final arguments to dacreate2d and dacreate3d allow you dictate the exact decomposition along with the m n and p arguments. But in you situation you need not worry about them. Barry > > Thank you very much! > > Regards, > > > Zhisong Li -------------- next part -------------- An HTML attachment was scrubbed... URL: From suguleasa at gmail.com Fri Aug 20 14:57:30 2010 From: suguleasa at gmail.com (Elena Smith) Date: Fri, 20 Aug 2010 14:57:30 -0500 Subject: [petsc-users] linking and compiling cg.c with examples from tutorials Message-ID: Hello All, I am a new PETSc user and I need some help. This is what I am trying to do: - use one of the examples provided under "tutorials" (src/ksp/ksp/examples/tutorials) and make it used one of the iterative methods already in src/ksp/ksp/impls. For example, instead of using KSPSetType(ksp,KSPCG) and then KSPSolve, I want to just do: KSPSolve_CG, where KSPSolve_CG comes from cg.c which would have some changes I would make. >From a previous post (https://lists.mcs.anl.gov/mailman/htdig/petsc-dev/2008-November/001049.html ) I understood that KSPSolve (with the KSPCG type set as above) calls actually KSPSolve_CG that is implemented in cg.c from src/ksp/ksp/impls/cg/cg.c. Does this mean I can change cg.c and somehow (magically) when I compile the example, it will know to compile the modified cg.c as well, perhaps through something like PETSC_KSP_LIB? I have tried this and it doesn't work, but it could be because not knowing how to set up the makefile... or my simplistic approach. Or would I have to recompile the entire source code to reflect the changes? I believe the answer is much simpler than this question suggests. Your help would be greatly appreciated. Thank you in advance, Elena From bsmith at mcs.anl.gov Fri Aug 20 15:08:09 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Fri, 20 Aug 2010 15:08:09 -0500 Subject: [petsc-users] linking and compiling cg.c with examples from tutorials In-Reply-To: References: Message-ID: If you are just "experimenting" with changes to cg.c there are two easy ways to do this 1) change cg.c directly in the PETSc directory tree and then run make in that directory, this updates the PETSc library, then relink your program and it will get your changes or 2) copy cg.c into your directory put it in your makefile as one of your source files and change it and compile there If you actually want to make a whole new PETSc Krylov method, distinct from the current CG then read the comments in cg.c on how to do it. Barry On Aug 20, 2010, at 2:57 PM, Elena Smith wrote: > Hello All, > > I am a new PETSc user and I need some help. > This is what I am trying to do: > - use one of the examples provided under "tutorials" > (src/ksp/ksp/examples/tutorials) and make it used one of the iterative > methods already in src/ksp/ksp/impls. > For example, instead of using KSPSetType(ksp,KSPCG) and then KSPSolve, > I want to just do: KSPSolve_CG, where KSPSolve_CG comes from cg.c > which would have some changes I would make. > >> From a previous post > (https://lists.mcs.anl.gov/mailman/htdig/petsc-dev/2008-November/001049.html > ) I understood that KSPSolve (with the KSPCG type set as above) calls > actually KSPSolve_CG that is implemented in cg.c from > src/ksp/ksp/impls/cg/cg.c. > Does this mean I can change cg.c and somehow (magically) when I > compile the example, it will know to compile the modified cg.c as > well, perhaps through something like PETSC_KSP_LIB? I have tried this > and it doesn't work, but it could be because not knowing how to set up > the makefile... or my simplistic approach. > > Or would I have to recompile the entire source code to reflect the > changes? I believe the answer is much simpler than this question > suggests. > > Your help would be greatly appreciated. > Thank you in advance, > Elena From xxy113 at psu.edu Sat Aug 21 09:00:20 2010 From: xxy113 at psu.edu (Xuan YU) Date: Sat, 21 Aug 2010 10:00:20 -0400 Subject: [petsc-users] Does preconditioner change results? Message-ID: Hi, I used several types of pc in TS solver. Only ilu and jacobi accelerates my codes. But both of the preconditioners changed a lot of the results comparing with result without pc. Could you please tell me what should I do? Xuan YU xxy113 at psu.edu From hong at aspiritech.org Sat Aug 21 09:15:59 2010 From: hong at aspiritech.org (Hong Zhang) Date: Sat, 21 Aug 2010 09:15:59 -0500 Subject: [petsc-users] Does preconditioner change results? In-Reply-To: References: Message-ID: Xuan, > I used several types of pc in TS solver. Only ilu and jacobi accelerates my > codes. But both of the preconditioners changed a lot of the results > comparing with result without pc. Could you please tell me what should I do? You need figure out which result gives better approximate solution from your application. The preconditioners are strongly application dependent. We do not know which pc is good for you without studying your application. You may use option '-ts_view -ksp_converged_reason' to check which algorithm is being used and if linear solver converges. Hong > > > Xuan YU > xxy113 at psu.edu > > > > > From sixthseason at gmail.com Mon Aug 23 09:23:34 2010 From: sixthseason at gmail.com (=?GB2312?B?TGl1IExpbiDB9cHW?=) Date: Mon, 23 Aug 2010 22:23:34 +0800 Subject: [petsc-users] what the default set of Hypre euclid Message-ID: Hypre euclid give a good convergence speed for my matrix, but I can't find the default set of Hypre eculid, Could anyone provide the default of Hypre eculid? -------------- next part -------------- An HTML attachment was scrubbed... URL: From knepley at gmail.com Mon Aug 23 09:45:49 2010 From: knepley at gmail.com (Matthew Knepley) Date: Mon, 23 Aug 2010 14:45:49 +0000 Subject: [petsc-users] what the default set of Hypre euclid In-Reply-To: References: Message-ID: You have to configure using Hypre (e.g. --download-hypre), and then use -pc_type hypre -pc_hypre_type euclid Matt On Mon, Aug 23, 2010 at 2:23 PM, Liu Lin ?? wrote: > Hypre euclid give a good convergence speed for my matrix, but I can't find > the default set of Hypre eculid, > > Could anyone provide the default of Hypre eculid? > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: From suguleasa at gmail.com Mon Aug 23 11:48:39 2010 From: suguleasa at gmail.com (Elena Smith) Date: Mon, 23 Aug 2010 11:48:39 -0500 Subject: [petsc-users] linking and compiling cg.c with examples from tutorials In-Reply-To: References: Message-ID: I went with option 1. It turned out that my problems were given by the machine and its default settings. Thank you very much! Elena On Fri, Aug 20, 2010 at 3:08 PM, Barry Smith wrote: > > ? If you are just "experimenting" with changes to cg.c there are two easy ways to do this > > 1) change cg.c directly in the PETSc directory tree and then run make in that directory, this updates the PETSc library, then relink your program and it will get your changes or > > 2) copy cg.c into your directory put it in your makefile as one of your source files and change it and compile there > > ? If you actually want to make a whole new PETSc Krylov method, distinct from the current CG then read the comments in cg.c on how to do it. > > ? Barry > > On Aug 20, 2010, at 2:57 PM, Elena Smith wrote: > >> Hello All, >> >> I am a new PETSc user and I need some help. >> This is what I am trying to do: >> - use one of the examples provided under "tutorials" >> (src/ksp/ksp/examples/tutorials) and make it used one of the iterative >> methods already in src/ksp/ksp/impls. >> For example, instead of using KSPSetType(ksp,KSPCG) and then KSPSolve, >> I want to just do: KSPSolve_CG, where KSPSolve_CG comes from cg.c >> which would have some changes I would make. >> >>> From a previous post >> (https://lists.mcs.anl.gov/mailman/htdig/petsc-dev/2008-November/001049.html >> ) I understood that KSPSolve (with the KSPCG type set as above) calls >> actually KSPSolve_CG that is implemented in cg.c from >> src/ksp/ksp/impls/cg/cg.c. >> Does this mean I can change cg.c and somehow (magically) when I >> compile the example, it will know to compile the modified cg.c as >> well, perhaps through something like PETSC_KSP_LIB? ?I have tried this >> and it doesn't work, but it could be because not knowing how to set up >> the makefile... or my simplistic approach. >> >> Or would I have to recompile the entire source code to reflect the >> changes? I believe the answer is much simpler than this question >> suggests. >> >> Your help would be greatly appreciated. >> Thank you in advance, >> ? ?Elena > > From austin at txcorp.com Mon Aug 23 12:18:14 2010 From: austin at txcorp.com (Travis Austin) Date: Mon, 23 Aug 2010 10:18:14 -0700 Subject: [petsc-users] Default set of HYPRE's Euclid Message-ID: <8D5FFD82-8609-49D3-AE7E-3CD492522ACB@txcorp.com> Liu Lin, Try to add -pc_hypre_euclid_print_statistics to your command line see if that tells you the default set that is being used. For HYPRE's boomeramg a similar command gives you all of the info that you need. Travis Austin ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Travis Austin, Ph.D. Tech-X Corporation 5621 Arapahoe Ave, Suite A Boulder, CO 80303 austin at txcorp.com ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -------------- next part -------------- An HTML attachment was scrubbed... URL: From hari at iastate.edu Mon Aug 23 22:28:56 2010 From: hari at iastate.edu (Hari Kodali) Date: Mon, 23 Aug 2010 22:28:56 -0500 Subject: [petsc-users] linker error, undefined reference to `petscstack' Message-ID: Hi all, I received a linker error while using petsc in $PETSC_DIR/$PETSC_ARCH/include/petscis.h:135: undefined reference to `petscstack' i tried nm $PETSC_DIR/$PETSC_ARCH/lib/*.* | grep petscstack but this command did not return any values. PS: petscstack is defined in 'petscerror.h' which is included in 'petsc.h' any help to debug this would be appreciated. -- Thanks, Hari Krishna Kodali -------------- next part -------------- An HTML attachment was scrubbed... URL: From balay at mcs.anl.gov Mon Aug 23 22:34:43 2010 From: balay at mcs.anl.gov (Satish Balay) Date: Mon, 23 Aug 2010 22:34:43 -0500 (CDT) Subject: [petsc-users] linker error, undefined reference to `petscstack' In-Reply-To: References: Message-ID: Did you build PETSc yourself? Do petsc examples work? Send make.log from the build, and the output of 'make test' to petsc-maint at mcs.anl.gov Satish On Mon, 23 Aug 2010, Hari Kodali wrote: > Hi all, > > I received a linker error while using petsc > > in $PETSC_DIR/$PETSC_ARCH/include/petscis.h:135: undefined reference to > `petscstack' > > i tried > nm $PETSC_DIR/$PETSC_ARCH/lib/*.* | grep petscstack > but this command did not return any values. > > PS: > petscstack is defined in 'petscerror.h' which is included in 'petsc.h' > > > any help to debug this would be appreciated. > > From B.Sanderse at cwi.nl Fri Aug 27 19:28:15 2010 From: B.Sanderse at cwi.nl (Benjamin Sanderse) Date: Fri, 27 Aug 2010 18:28:15 -0600 Subject: [petsc-users] petsc and matlab Message-ID: <549B2F8A-ACB0-4CFE-A7FB-A2AE336E4012@cwi.nl> Hello all, I am trying to let Matlab communicate to Petsc and vice versa. I have compiled petsc-3.1 successfully and have looked at example ex41.m in /src/ksp/ksp/examples/tutorials/ex41.m. After compiling ex41.c I tried to run ex41.m, e.g. by typing ex41(1) in Matlab. Then I get the following error: ??? Undefined function or variable 'sopen' Error in ==> PetscOpenSocket.PetscOpenSocket at 10 S = struct('fd',sopen()); Error in ==> ex41 at 10 p = PetscOpenSocket; It seems that sopen() is not recognized. I have googled a bit around and checked this mailing list, but I could not find out where sopen() should be located. Does anyone have suggestions? Or am I doing something completely wrong? Thanks, Benjamin From bsmith at mcs.anl.gov Fri Aug 27 22:02:37 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Fri, 27 Aug 2010 22:02:37 -0500 Subject: [petsc-users] petsc and matlab In-Reply-To: <549B2F8A-ACB0-4CFE-A7FB-A2AE336E4012@cwi.nl> References: <549B2F8A-ACB0-4CFE-A7FB-A2AE336E4012@cwi.nl> Message-ID: <5E3FFF9B-C196-44E7-ACA2-A848FBEC9591@mcs.anl.gov> sopen is compiled by the PETSc makefiles and then put into the directory bin/matlab/ Did you ./configure PETSc with the option --with-matlab? If not then you will need to run ./configure again and then make again. If you did run ./configure with --with-matlab then please send configure.log and make.log to petsc-maint at mcs.anl.gov and we'll determine the problem. Barry On Aug 27, 2010, at 7:28 PM, Benjamin Sanderse wrote: > Hello all, > > I am trying to let Matlab communicate to Petsc and vice versa. I have compiled petsc-3.1 successfully and have looked at example ex41.m in /src/ksp/ksp/examples/tutorials/ex41.m. After compiling ex41.c I tried to run ex41.m, e.g. by typing ex41(1) in Matlab. Then I get the following error: > > ??? Undefined function or variable 'sopen' > Error in ==> PetscOpenSocket.PetscOpenSocket at 10 > S = struct('fd',sopen()); > > Error in ==> ex41 at 10 > p = PetscOpenSocket; > > > It seems that sopen() is not recognized. I have googled a bit around and checked this mailing list, but I could not find out where sopen() should be located. Does anyone have suggestions? Or am I doing something completely wrong? > > Thanks, > > Benjamin From henrik.nordborg at cadfem.ch Mon Aug 30 07:11:34 2010 From: henrik.nordborg at cadfem.ch (Henrik Nordborg) Date: Mon, 30 Aug 2010 14:11:34 +0200 Subject: [petsc-users] UNSUBSCRIBE In-Reply-To: <549B2F8A-ACB0-4CFE-A7FB-A2AE336E4012@cwi.nl> References: <549B2F8A-ACB0-4CFE-A7FB-A2AE336E4012@cwi.nl> Message-ID: <2F57B039D39B6F499CA6C65330659BDDA393424C5A@muc-dc-03.cadfem-gmbh.cadfem.de> -----Urspr?ngliche Nachricht----- Von: petsc-users-bounces at mcs.anl.gov [mailto:petsc-users-bounces at mcs.anl.gov] Im Auftrag von Benjamin Sanderse Gesendet: Samstag, 28. August 2010 02:28 An: petsc-users at mcs.anl.gov Betreff: [petsc-users] petsc and matlab Hello all, I am trying to let Matlab communicate to Petsc and vice versa. I have compiled petsc-3.1 successfully and have looked at example ex41.m in /src/ksp/ksp/examples/tutorials/ex41.m. After compiling ex41.c I tried to run ex41.m, e.g. by typing ex41(1) in Matlab. Then I get the following error: ??? Undefined function or variable 'sopen' Error in ==> PetscOpenSocket.PetscOpenSocket at 10 S = struct('fd',sopen()); Error in ==> ex41 at 10 p = PetscOpenSocket; It seems that sopen() is not recognized. I have googled a bit around and checked this mailing list, but I could not find out where sopen() should be located. Does anyone have suggestions? Or am I doing something completely wrong? Thanks, Benjamin From j.alyn.roberts at gmail.com Tue Aug 31 10:12:46 2010 From: j.alyn.roberts at gmail.com (Jeremy Roberts) Date: Tue, 31 Aug 2010 11:12:46 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell Message-ID: Hi folks, I am trying to implement a sample problem for SNES using a shell matrix construct for the Jacobian (*not* finite differences). However, I haven't yet found a straightforward example for this. I've seen one for a shell-based PC but not for a shell-based Jacobian. I thought a sequence like this would work, but I'm not sure how to set the Jacobian. call MatCreateShell( PETSC_COMM_SELF, m, n, m, n, PETSC_NULL_OBJECT, Jshell, ierr ) call MatShellSetOperation( Jshell, MATOP_MULT, jac_shell, ierr ) call MatCreateSNESMF( snes, Jshell, ierr ) call SNESSetJacobian( snes, Jshell, Jshell, ???, PETSC_NULL_OBJECT, ierr ) I need no PC right now, jac_shell computes the result J*v, and Jshell is an empty Mat. How do I finish this calling sequence? Am I way off base here? Thanks, Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From bsmith at mcs.anl.gov Tue Aug 31 10:18:40 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 31 Aug 2010 11:18:40 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: References: Message-ID: On Aug 31, 2010, at 11:12 AM, Jeremy Roberts wrote: > Hi folks, > > I am trying to implement a sample problem for SNES using a shell matrix construct for the Jacobian (*not* finite differences). > > However, I haven't yet found a straightforward example for this. I've seen one for a shell-based PC but not for a shell-based Jacobian. > > I thought a sequence like this would work, but I'm not sure how to set the Jacobian. > > call MatCreateShell( PETSC_COMM_SELF, m, n, m, n, PETSC_NULL_OBJECT, Jshell, ierr ) > call MatShellSetOperation( Jshell, MATOP_MULT, jac_shell, ierr ) > call MatCreateSNESMF( snes, Jshell, ierr ) ^^^^ don't want this, don't need this, this line makes no sense > call SNESSetJacobian( snes, Jshell, Jshell, ???, PETSC_NULL_OBJECT, ierr ) ^^^^^^^^^^ You would write a function with the correct calling sequence. This function would keep a copy of the input vector (this is the place WHERE the Jacobian is evaulated in J(u)*x this is the u so you need to keep a copy of it here to use when you do your jac_shell multiply) Barry > > I need no PC right now, jac_shell computes the result J*v, and Jshell is an empty Mat. > > How do I finish this calling sequence? Am I way off base here? > > Thanks, > Jeremy From rabartl at sandia.gov Tue Aug 31 11:47:20 2010 From: rabartl at sandia.gov (Bartlett, Roscoe A) Date: Tue, 31 Aug 2010 10:47:20 -0600 Subject: [petsc-users] Participation Requested: Survey about Software Practices in Computational Science Message-ID: <9C5EDABC60AD90488D506008E9277E4A1C20A33173@ES02SNLNT.srn.sandia.gov> Hello, Dr. Roscoe Bartlett, Sandia National Laboratory, Dr. Jeffrey Carver, University of Alabama, and Dr. Lorin Hochstein, University of Southern California, are conducting a survey of software development practices among computational scientists. This survey seeks to understand current software development practices and identify areas of need. The survey should take approximately 15 minutes to complete. The survey can be accessed at: https://spreadsheets.google.com/viewform?hl=en&formkey=dFFxQUtEOWtjVDFzdGx5c0JzYUVla2c6MQ#gid=0 This survey has been approved by The University of Alabama IRB board. If there is another group of individuals who you think might provide useful feedback, please forward this email to them also. Thanks, - Roscoe ----------------------------------------------------------------------- Dr. Roscoe A. Bartlett Sandia National Laboratories Department of Optimization and Uncertainty Estimation Trilinos Software Engineering Technologies and Integration Lead (505) 844-5097 -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.alyn.roberts at gmail.com Tue Aug 31 12:03:37 2010 From: j.alyn.roberts at gmail.com (Jeremy Roberts) Date: Tue, 31 Aug 2010 13:03:37 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: References: Message-ID: Hi Barry, Thanks for the quick response. I have the unknown vector u globally accessible and so forgo use of the user-defined context (I tried to get it to work---can it be used in Fortran?). I used call SNESSetJacobian( snes, Jshell, Jshell, FOO, PETSC_NULL_OBJECT, ierr ) where FOO is an empty function having the correct argument types. It seems to work now, and I get the exact same answer using an explicit Jacobian matrix and the shell version. Is there a way to get around needing FOO at all? Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From bsmith at mcs.anl.gov Tue Aug 31 12:14:27 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 31 Aug 2010 13:14:27 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: References: Message-ID: On Aug 31, 2010, at 1:03 PM, Jeremy Roberts wrote: > > Hi Barry, > > Thanks for the quick response. > > I have the unknown vector u globally accessible and so forgo use of the user-defined context (I tried to get it to work---can it be used in Fortran?). > > I used > > call SNESSetJacobian( snes, Jshell, Jshell, FOO, PETSC_NULL_OBJECT, ierr ) > > where FOO is an empty function having the correct argument types. It seems to work now, and I get the exact same answer using an explicit Jacobian matrix and the shell version. Is there a way to get around needing FOO at all? > If it works great. But I how you know what the "unknown vector u " that is "globally accessible" in SNES is? How do you know it is the same each time a new Jacobian is needed? The only save way is to copy the vector passed into the FOO funcion. Barry > Jeremy > > From rabartl at sandia.gov Tue Aug 31 12:16:01 2010 From: rabartl at sandia.gov (Bartlett, Roscoe A) Date: Tue, 31 Aug 2010 11:16:01 -0600 Subject: [petsc-users] Participation Requested: Survey about Software Practices in Computational Science Message-ID: <9C5EDABC60AD90488D506008E9277E4A1C20A331A9@ES02SNLNT.srn.sandia.gov> Please update the updated link: https://spreadsheets.google.com/viewform?hl=en&formkey=dGZwR1BfQ2NiNGh6SWt4ZjBCTnFoVmc6MQ#gid=0 _____________________________________________ From: Bartlett, Roscoe A Sent: Tuesday, August 31, 2010 10:47 AM To: 'petsc-users at mcs.anl.gov' Subject: Participation Requested: Survey about Software Practices in Computational Science Hello, Dr. Roscoe Bartlett, Sandia National Laboratory, Dr. Jeffrey Carver, University of Alabama, and Dr. Lorin Hochstein, University of Southern California, are conducting a survey of software development practices among computational scientists. This survey seeks to understand current software development practices and identify areas of need. The survey should take approximately 15 minutes to complete. The survey can be accessed at: https://spreadsheets.google.com/viewform?hl=en&formkey=dFFxQUtEOWtjVDFzdGx5c0JzYUVla2c6MQ#gid=0 This survey has been approved by The University of Alabama IRB board. If there is another group of individuals who you think might provide useful feedback, please forward this email to them also. Thanks, - Roscoe ----------------------------------------------------------------------- Dr. Roscoe A. Bartlett Sandia National Laboratories Department of Optimization and Uncertainty Estimation Trilinos Software Engineering Technologies and Integration Lead (505) 844-5097 -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.alyn.roberts at gmail.com Tue Aug 31 13:17:00 2010 From: j.alyn.roberts at gmail.com (Jeremy Roberts) Date: Tue, 31 Aug 2010 14:17:00 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: References: Message-ID: To implement the safe method---i.e. copying the unknown vector u within FOO---what is proper generic form of FOO? I guess I'm not clear exactly how FOO and jac_shell (the J*x routine) are linked. It appears they aren't, given I can use an empty subroutine, but how then is a local copy of u within FOO used in for J(u) in J(U)*x of jac_shell? On Tue, Aug 31, 2010 at 1:14 PM, Barry Smith wrote: > > On Aug 31, 2010, at 1:03 PM, Jeremy Roberts wrote: > > > > > Hi Barry, > > > > Thanks for the quick response. > > > > I have the unknown vector u globally accessible and so forgo use of the > user-defined context (I tried to get it to work---can it be used in > Fortran?). > > > > I used > > > > call SNESSetJacobian( snes, Jshell, Jshell, FOO, PETSC_NULL_OBJECT, ierr > ) > > > > where FOO is an empty function having the correct argument types. It > seems to work now, and I get the exact same answer using an explicit > Jacobian matrix and the shell version. Is there a way to get around needing > FOO at all? > > > > If it works great. But I how you know what the "unknown vector u " that > is "globally accessible" in SNES is? How do you know it is the same each > time a new Jacobian is needed? The only save way is to copy the vector > passed into the FOO funcion. > > Barry > > > > > Jeremy > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jed at 59A2.org Tue Aug 31 13:29:17 2010 From: jed at 59A2.org (Jed Brown) Date: Tue, 31 Aug 2010 20:29:17 +0200 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: References: Message-ID: <87occifxfm.fsf@59A2.org> On Tue, 31 Aug 2010 14:17:00 -0400, Jeremy Roberts wrote: > To implement the safe method---i.e. copying the unknown vector u within > FOO---what is proper generic form of FOO? > > I guess I'm not clear exactly how FOO and jac_shell (the J*x routine) are > linked. It appears they aren't, given I can use an empty subroutine, but > how then is a local copy of u within FOO used in for J(u) in J(U)*x of > jac_shell? FOO is the function called to *update* the Jacobian. It has the same prototype as the FormJacobian routines you see in the examples: FormJacobian(snes,X,J,Jpre,matstructure,user,ierr) It sounds like you just need to save the vector. Jed From bsmith at mcs.anl.gov Tue Aug 31 13:27:49 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 31 Aug 2010 14:27:49 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: References: Message-ID: <79F68651-2151-48B6-A9B2-E1CDB3F6C17A@mcs.anl.gov> On Aug 31, 2010, at 2:17 PM, Jeremy Roberts wrote: > To implement the safe method---i.e. copying the unknown vector u within FOO---what is proper generic form of FOO? > > I guess I'm not clear exactly how FOO and jac_shell (the J*x routine) are linked. It appears they aren't, given I can use an empty subroutine, but how then is a local copy of u within FOO used in for J(u) in J(U)*x of jac_shell? Don't ask me. You wrote the code, I have no idea how you are accessing u. But you need to compute J(u)*x so you need to use u. subroutine yourfoo(snes,u,A,B,flg,ierr) common /mycommonblock/ v call veccopy(u,v,ierr) return and create the v upfront in your main program. Of course, you don't need to use common blocks but that is one way of maintaining this global variables. Barry > > > On Tue, Aug 31, 2010 at 1:14 PM, Barry Smith wrote: > > On Aug 31, 2010, at 1:03 PM, Jeremy Roberts wrote: > > > > > Hi Barry, > > > > Thanks for the quick response. > > > > I have the unknown vector u globally accessible and so forgo use of the user-defined context (I tried to get it to work---can it be used in Fortran?). > > > > I used > > > > call SNESSetJacobian( snes, Jshell, Jshell, FOO, PETSC_NULL_OBJECT, ierr ) > > > > where FOO is an empty function having the correct argument types. It seems to work now, and I get the exact same answer using an explicit Jacobian matrix and the shell version. Is there a way to get around needing FOO at all? > > > > If it works great. But I how you know what the "unknown vector u " that is "globally accessible" in SNES is? How do you know it is the same each time a new Jacobian is needed? The only save way is to copy the vector passed into the FOO funcion. > > Barry > > > > > Jeremy > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.alyn.roberts at gmail.com Tue Aug 31 14:16:29 2010 From: j.alyn.roberts at gmail.com (Jeremy Roberts) Date: Tue, 31 Aug 2010 15:16:29 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: <79F68651-2151-48B6-A9B2-E1CDB3F6C17A@mcs.anl.gov> References: <79F68651-2151-48B6-A9B2-E1CDB3F6C17A@mcs.anl.gov> Message-ID: Ah, I understand now what you mean. I have u in a module used by all subroutines that need u, including the main program where it is an argument of SNESSolve and the subroutine jac_shell. I assumed having all routines use the same variable makes it the same everywhere at all times...maybe I'm just lucky with this particular problem. Putting it as you do, I see why the user might not want to assume what goes into solve is consistent with (points to?) what enters FOO at any given call. Thanks, Jeremy P.S. I've attached the working example, where "x" is the unknown vector. On Tue, Aug 31, 2010 at 2:27 PM, Barry Smith wrote: > > On Aug 31, 2010, at 2:17 PM, Jeremy Roberts wrote: > > To implement the safe method---i.e. copying the unknown vector u within > FOO---what is proper generic form of FOO? > > I guess I'm not clear exactly how FOO and jac_shell (the J*x routine) are > linked. It appears they aren't, given I can use an empty subroutine, but > how then is a local copy of u within FOO used in for J(u) in J(U)*x of > jac_shell? > > > Don't ask me. You wrote the code, I have no idea how you are accessing u. > But you need to compute J(u)*x so you need to use u. > > subroutine yourfoo(snes,u,A,B,flg,ierr) > common /mycommonblock/ v > > call veccopy(u,v,ierr) > return > > and create the v upfront in your main program. Of course, you don't need > to use common blocks but that is one way of maintaining this global > variables. > > Barry > > > > > > On Tue, Aug 31, 2010 at 1:14 PM, Barry Smith wrote: > >> >> On Aug 31, 2010, at 1:03 PM, Jeremy Roberts wrote: >> >> > >> > Hi Barry, >> > >> > Thanks for the quick response. >> > >> > I have the unknown vector u globally accessible and so forgo use of the >> user-defined context (I tried to get it to work---can it be used in >> Fortran?). >> > >> > I used >> > >> > call SNESSetJacobian( snes, Jshell, Jshell, FOO, PETSC_NULL_OBJECT, ierr >> ) >> > >> > where FOO is an empty function having the correct argument types. It >> seems to work now, and I get the exact same answer using an explicit >> Jacobian matrix and the shell version. Is there a way to get around needing >> FOO at all? >> > >> >> If it works great. But I how you know what the "unknown vector u " that >> is "globally accessible" in SNES is? How do you know it is the same each >> time a new Jacobian is needed? The only save way is to copy the vector >> passed into the FOO funcion. >> >> Barry >> >> >> >> > Jeremy >> > >> > >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: exJac.F Type: text/x-fortran Size: 6990 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: exJac_mod.F Type: text/x-fortran Size: 5670 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: exJac_mod2.F Type: text/x-fortran Size: 135 bytes Desc: not available URL: From bsmith at mcs.anl.gov Tue Aug 31 14:17:54 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 31 Aug 2010 15:17:54 -0400 Subject: [petsc-users] A matrix-free Jacobian for SNES using MatShell In-Reply-To: References: <79F68651-2151-48B6-A9B2-E1CDB3F6C17A@mcs.anl.gov> Message-ID: On Aug 31, 2010, at 3:16 PM, Jeremy Roberts wrote: > Ah, I understand now what you mean. I have u in a module used by all subroutines that need u, including the main program where it is an argument of SNESSolve and the subroutine jac_shell. I assumed having all routines use the same variable makes it the same everywhere at all times...maybe I'm just lucky with this particular problem. Putting it as you do, I see why the user might not want to assume what goes into solve is consistent with (points to?) what enters FOO at any given call. It does not neccessarily match, you should not depend on it. Barry > > Thanks, > Jeremy > > P.S. I've attached the working example, where "x" is the unknown vector. > > On Tue, Aug 31, 2010 at 2:27 PM, Barry Smith wrote: > > On Aug 31, 2010, at 2:17 PM, Jeremy Roberts wrote: > >> To implement the safe method---i.e. copying the unknown vector u within FOO---what is proper generic form of FOO? >> >> I guess I'm not clear exactly how FOO and jac_shell (the J*x routine) are linked. It appears they aren't, given I can use an empty subroutine, but how then is a local copy of u within FOO used in for J(u) in J(U)*x of jac_shell? > > Don't ask me. You wrote the code, I have no idea how you are accessing u. But you need to compute J(u)*x so you need to use u. > > subroutine yourfoo(snes,u,A,B,flg,ierr) > common /mycommonblock/ v > > call veccopy(u,v,ierr) > return > > and create the v upfront in your main program. Of course, you don't need to use common blocks but that is one way of maintaining this global variables. > > Barry > > > >> >> >> On Tue, Aug 31, 2010 at 1:14 PM, Barry Smith wrote: >> >> On Aug 31, 2010, at 1:03 PM, Jeremy Roberts wrote: >> >> > >> > Hi Barry, >> > >> > Thanks for the quick response. >> > >> > I have the unknown vector u globally accessible and so forgo use of the user-defined context (I tried to get it to work---can it be used in Fortran?). >> > >> > I used >> > >> > call SNESSetJacobian( snes, Jshell, Jshell, FOO, PETSC_NULL_OBJECT, ierr ) >> > >> > where FOO is an empty function having the correct argument types. It seems to work now, and I get the exact same answer using an explicit Jacobian matrix and the shell version. Is there a way to get around needing FOO at all? >> > >> >> If it works great. But I how you know what the "unknown vector u " that is "globally accessible" in SNES is? How do you know it is the same each time a new Jacobian is needed? The only save way is to copy the vector passed into the FOO funcion. >> >> Barry >> >> >> >> > Jeremy >> > >> > >> >> > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zhaonanavril at gmail.com Tue Aug 31 16:58:30 2010 From: zhaonanavril at gmail.com (nan zhao) Date: Tue, 31 Aug 2010 15:58:30 -0600 Subject: [petsc-users] Can I call PetscInitialize twice in a programm Message-ID: <1283291910.30914.6.camel@localhost.localdomain> Hi, I am now using petsc to develop some application which need to solve two physical systems. I want to use Petsc as the linear solver. but I am not sure if I can all PetscInitialize twice. becasue the two system are solving at the same time period. And also I want to use MPI to do parallel computing. Can I call MPI:INIT() before I call PetscInitialize? Thank you very much! Nan From jed at 59A2.org Tue Aug 31 17:06:30 2010 From: jed at 59A2.org (Jed Brown) Date: Wed, 01 Sep 2010 00:06:30 +0200 Subject: [petsc-users] Can I call PetscInitialize twice in a programm In-Reply-To: <1283291910.30914.6.camel@localhost.localdomain> References: <1283291910.30914.6.camel@localhost.localdomain> Message-ID: <87aao2fndl.fsf@59A2.org> On Tue, 31 Aug 2010 15:58:30 -0600, nan zhao wrote: > Hi, > > I am now using petsc to develop some application which need to solve two > physical systems. I want to use Petsc as the linear solver. but I am not > sure if I can all PetscInitialize twice. No, you can only call it once. > becasue the two system are solving at the same time period. And also I > want to use MPI to do parallel computing. Can I call MPI:INIT() before > I call PetscInitialize? You can, but it's usually not necessary since PetscInitialize will call it for you otherwise (and then PetscFinalize will call MPI_Finalize). Jed From bsmith at mcs.anl.gov Tue Aug 31 17:04:21 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 31 Aug 2010 18:04:21 -0400 Subject: [petsc-users] Can I call PetscInitialize twice in a programm In-Reply-To: <1283291910.30914.6.camel@localhost.localdomain> References: <1283291910.30914.6.camel@localhost.localdomain> Message-ID: On Aug 31, 2010, at 5:58 PM, nan zhao wrote: > Hi, > > I am now using petsc to develop some application which need to solve two > physical systems. I want to use Petsc as the linear solver. but I am not > sure if I can all PetscInitialize twice. becasue the two system are > solving at the same time period. And also I want to use MPI to do > parallel computing. Can I call MPI:INIT() before I call PetscInitialize? Yes and you can call PetscInitialize()/ Finalize() multiple times but that is not the standard usage model. Usually you put PetscInitialize() right at the beginning of the code and PetscFinalize() right at the end. Barry > > Thank you very much! > > Nan > From bsmith at mcs.anl.gov Tue Aug 31 17:05:01 2010 From: bsmith at mcs.anl.gov (Barry Smith) Date: Tue, 31 Aug 2010 18:05:01 -0400 Subject: [petsc-users] Can I call PetscInitialize twice in a programm In-Reply-To: <87aao2fndl.fsf@59A2.org> References: <1283291910.30914.6.camel@localhost.localdomain> <87aao2fndl.fsf@59A2.org> Message-ID: On Aug 31, 2010, at 6:06 PM, Jed Brown wrote: > On Tue, 31 Aug 2010 15:58:30 -0600, nan zhao wrote: >> Hi, >> >> I am now using petsc to develop some application which need to solve two >> physical systems. I want to use Petsc as the linear solver. but I am not >> sure if I can all PetscInitialize twice. > > No, you can only call it once. This is no longer true, though it was true for 15 years. Barry > >> becasue the two system are solving at the same time period. And also I >> want to use MPI to do parallel computing. Can I call MPI:INIT() before >> I call PetscInitialize? > > You can, but it's usually not necessary since PetscInitialize will call > it for you otherwise (and then PetscFinalize will call MPI_Finalize). > > Jed From jed at 59A2.org Tue Aug 31 17:11:56 2010 From: jed at 59A2.org (Jed Brown) Date: Wed, 01 Sep 2010 00:11:56 +0200 Subject: [petsc-users] Can I call PetscInitialize twice in a programm In-Reply-To: References: <1283291910.30914.6.camel@localhost.localdomain> <87aao2fndl.fsf@59A2.org> Message-ID: <877hj6fn4j.fsf@59A2.org> On Tue, 31 Aug 2010 18:05:01 -0400, Barry Smith wrote: > > On Aug 31, 2010, at 6:06 PM, Jed Brown wrote: > > > On Tue, 31 Aug 2010 15:58:30 -0600, nan zhao wrote: > >> Hi, > >> > >> I am now using petsc to develop some application which need to solve two > >> physical systems. I want to use Petsc as the linear solver. but I am not > >> sure if I can all PetscInitialize twice. > > > > No, you can only call it once. > > This is no longer true, though it was true for 15 years. Shows how old I am. ;-) Presumably this only works if PETSc is *not* calling MPI_Init(). Jed