Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Barry Smith
Slow assembly is usually due to under preallocation. You can change to using > MatSetOption(B, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_TRUE); to detect if you are under preallocating. See https://petsc.org/main/docs/manual/mat/#sec-matsparse

Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Barry Smith
The preallocator MatType matrix cannot be passed to the KSPSetOperators(), you need to create an actual matrix, for example MATAIJ and use the preallocator to set its preallocation and then fill up the MATAIJ matrix with the usual MatSetValues and pass that matrix to the KSPSetOperators. >

Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Tu, Jiannan
Hi Barry, The MATPREALLOCATOR solved problem of slow matrix assembly. But the solver failed because of "Matrix type preallocator does not have a multiply defined". I guess this is because the matrix-free is used. I am wondering how a preconditioner is applied to the matrix-vector multiply in Pe

Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Tu, Jiannan
Thanks, Barry. So I need actually two matrixes, one for preallocator and one for actual matrix that can be passed to KSPSetOperators(). -mat_type preallocator option is used to speed up doing insertion into preallocator, then use MatPreallocatorPreallocate() to preallocate actual matrix and do

Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Barry Smith
Yes, once you have preallocated the real matrix you can destroy the preallocation matrix whose only job is to gather the preallocation information > On Aug 18, 2022, at 12:52 PM, Tu, Jiannan wrote: > > Thanks, Barry. > > So I need actually two matrixes, one for preallocator and one for act

Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Tu, Jiannan
Barry, Thanks. The method works. Assembly of actual matrix now completes quickly. The convergency is much better for the first iteration. The residual normal is in the order of 10^-10 instead of 10^-2. However, there is an error message after the first iteration: "Object is in wrong state. Not

[petsc-users] `petsc4py` GPU support

2022-08-18 Thread Rohan Yadav
Hi, I'm trying to use `petsc4py` on a machine with CUDA GPUs. Is there a way to download a version of `petsc4py` from pip or conda with GPU support? If not, how do I go about installing `petsc4py` with GPU support from source? I can't find much documentation around doing this. Thanks, Rohan

Re: [petsc-users] `petsc4py` GPU support

2022-08-18 Thread Satish Balay via petsc-users
You could look at PETSc install instructions and examples https://petsc.org/release/install/install/#common-example-usages Assuming a linux box with cuda at /usr/local/cuda, mpicc etc in PATH, and have system blas/lapack installed, the following build process should work ./configure --with-cud

Re: [petsc-users] `petsc4py` GPU support

2022-08-18 Thread Rohan Yadav
I see. To confirm: 1) There are no installations of `petsc4py` with GPU support available through a package manager 2) Building and configuring PETSc with GPU support will also build a version of `petsc4py`. Thanks, Rohan On Thu, Aug 18, 2022 at 4:31 PM Satish Balay wrote: > You could look at P

Re: [petsc-users] `petsc4py` GPU support

2022-08-18 Thread Satish Balay via petsc-users
On Thu, 18 Aug 2022, Rohan Yadav wrote: > I see. To confirm: > 1) There are no installations of `petsc4py` with GPU support available > through a package manager You could try via pip - but its not any more simple. Here the model is - you install petsc via pip - and then petsc4py. Here you would

Re: [petsc-users] DMPlex Transitive closure

2022-08-18 Thread Matthew Knepley
On Wed, Aug 17, 2022 at 8:31 AM Nicholas Arnold-Medabalimi < narno...@umich.edu> wrote: > Good Morning > > I have been working with the transitive closure to check to see if a node > point has a cell that is rooted on a process. However, I think I am having > a more fundamental issue. Even just ca

Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Barry Smith
Is it in the first iteration of the first KSPSolve that you get this message? Or in the second call to KSPSolve? The error comes from a matrix vector product with your A matrix, what is that and where did it come from. The error message is not from your B matrix, that is not used in the

Re: [petsc-users] Using matrix-free with KSP

2022-08-18 Thread Tu, Jiannan
The program calls KSPSolve just once and the error occurs after the first iteration. I realized the matrix-vector product in my case is different from that approximating matrix-vector multiply by finite difference of function vector. It consists of two parts. One is multiplication of part of th