Re: [petsc-users] MatCreateTranspose

2024-04-12 Thread Pierre Jolivet


> On 12 Apr 2024, at 11:51 AM, Carl-Johan Thore  
> wrote:
> 
> On Fri, Apr 12, 2024 at 11:16 AM Pierre Jolivet  > wrote:
>> 
>> 
>>> On 12 Apr 2024, at 11:10 AM, Carl-Johan Thore >> > wrote:
>>> 
>>> Pierre, I see that you've already done a merge request for this. Thanks!
>>> I have tested this and it works nicely in my application
>> 
>> I guess your matrix is symmetric in pattern?
>> Because otherwise, I don’t think this should work.
>> But if it’s OK for your use case, I could simply add a PetscCheck() that the 
>> input Mat is symmetric and then get this integrated (better to have 
>> something partially working than nothing at all, I guess).
>> Please let me know.
>> 
>> Thanks,
>> Pierre
> 
> Yes, unless I'm mistaken it's structurally symmetric. Would be great to have 
> this integrated.

OK, I’ll work on finalizing this.

> (I don't now what you have in mind for the check, but 
> MatIsStructurallySymmetric did not work for me)

You’ll have to call MatSetOption(A, MAT_STRUCTURALLY_SYMMETRIC, PETSC_TRUE) 
before KSPSolveTranspose().

Thanks,
Pierre

> /Carl-Johan
> 
> 
>  
>>> /Carl-Johan
>>> 
>>> On Wed, Apr 10, 2024 at 8:24 AM Carl-Johan Thore >> > wrote:
 
 
 On Tue, Apr 9, 2024 at 5:31 PM Pierre Jolivet >>> > wrote:
> 
>> On 9 Apr 2024, at 4:19 PM, Carl-Johan Thore > > wrote:
>> 
>> This Message Is From an External Sender
>> This message came from outside your organization.
>> Thanks for the suggestion. I don't have a factored matrix (and can't 
>> really use direct linear solvers) so MatSolveTranspose doesn't seem to 
>> be an option. 
>> I should have mentioned that I've also tried KSPSolveTranspose but that 
>> doesn't work with pcredistribute
> 
> I’m not a frequent PCREDISTRIBUTE user, but it looks like 
> https://urldefense.us/v3/__https://petsc.org/release/src/ksp/pc/impls/redistribute/redistribute.c.html*line332__;Iw!!G_uCfscf7eWS!Z3r5Vel5sbPcmhUVW14FZ6PsYuoOjHTQALmGl5fdDTHAI1ylX6YQfiOTutFQCeLQewR7-dZQ2k-7sSa95-LFDg$
>   could be copy/paste’d into PCApplyTranspose_Redistribute() by just 
> changing a MatMult() to MatMultTranspose() and KSPSolve() to 
> KSPSolveTranspose().
> Would you be willing to contribute (and test) this?
> Then, KSPSolveTranspose() — which should be the function you call — will 
> work.
> 
> Thanks,
> Pierre
 
 Thanks, that sounds promising. Yes, I'll try to make a contribution
 /Carl-Johan
>> 



Re: [petsc-users] MatCreateTranspose

2024-04-12 Thread Carl-Johan Thore
On Fri, Apr 12, 2024 at 11:16 AM Pierre Jolivet  wrote:

>
>
> On 12 Apr 2024, at 11:10 AM, Carl-Johan Thore 
> wrote:
>
> Pierre, I see that you've already done a merge request for this. Thanks!
> I have tested this and it works nicely in my application
>
>
> I guess your matrix is symmetric in pattern?
> Because otherwise, I don’t think this should work.
> But if it’s OK for your use case, I could simply add a PetscCheck() that
> the input Mat is symmetric and then get this integrated (better to have
> something partially working than nothing at all, I guess).
> Please let me know.
>
> Thanks,
> Pierre
>

Yes, unless I'm mistaken it's structurally symmetric. Would be great to
have this integrated.
(I don't now what you have in mind for the check, but
MatIsStructurallySymmetric did not work for me)
/Carl-Johan




> /Carl-Johan
>
> On Wed, Apr 10, 2024 at 8:24 AM Carl-Johan Thore 
> wrote:
>
>>
>>
>> On Tue, Apr 9, 2024 at 5:31 PM Pierre Jolivet  wrote:
>>
>>>
>>> On 9 Apr 2024, at 4:19 PM, Carl-Johan Thore 
>>> wrote:
>>>
>>> This Message Is From an External Sender
>>> This message came from outside your organization.
>>> Thanks for the suggestion. I don't have a factored matrix (and can't
>>> really use direct linear solvers) so MatSolveTranspose doesn't seem to
>>> be an option.
>>> I should have mentioned that I've also tried KSPSolveTranspose but that
>>> doesn't work with pcredistribute
>>>
>>>
>>> I’m not a frequent PCREDISTRIBUTE user, but it looks like
>>> https://urldefense.us/v3/__https://petsc.org/release/src/ksp/pc/impls/redistribute/redistribute.c.html*line332__;Iw!!G_uCfscf7eWS!eKgr2PYF7SG39RXX3djw6sMcERzrkuIDlriMyaTiUBJLndZZjvPWDIExlBIgGGHuniBRgDKoQ2YiNQFa0Rh356QrCz6dDw$
>>>   could
>>> be copy/paste’d into PCApplyTranspose_Redistribute() by just changing a
>>> MatMult() to MatMultTranspose() and KSPSolve() to KSPSolveTranspose().
>>> Would you be willing to contribute (and test) this?
>>> Then, KSPSolveTranspose() — which should be the function you call — will
>>> work.
>>>
>>> Thanks,
>>> Pierre
>>>
>>
>> Thanks, that sounds promising. Yes, I'll try to make a contribution
>> /Carl-Johan
>>
>
>


Re: [petsc-users] MatCreateTranspose

2024-04-12 Thread Pierre Jolivet


> On 12 Apr 2024, at 11:10 AM, Carl-Johan Thore  
> wrote:
> 
> Pierre, I see that you've already done a merge request for this. Thanks!
> I have tested this and it works nicely in my application

I guess your matrix is symmetric in pattern?
Because otherwise, I don’t think this should work.
But if it’s OK for your use case, I could simply add a PetscCheck() that the 
input Mat is symmetric and then get this integrated (better to have something 
partially working than nothing at all, I guess).
Please let me know.

Thanks,
Pierre

> /Carl-Johan
> 
> On Wed, Apr 10, 2024 at 8:24 AM Carl-Johan Thore  > wrote:
>> 
>> 
>> On Tue, Apr 9, 2024 at 5:31 PM Pierre Jolivet > > wrote:
>>> 
 On 9 Apr 2024, at 4:19 PM, Carl-Johan Thore >>> > wrote:
 
 This Message Is From an External Sender
 This message came from outside your organization.
 Thanks for the suggestion. I don't have a factored matrix (and can't 
 really use direct linear solvers) so MatSolveTranspose doesn't seem to be 
 an option. 
 I should have mentioned that I've also tried KSPSolveTranspose but that 
 doesn't work with pcredistribute
>>> 
>>> I’m not a frequent PCREDISTRIBUTE user, but it looks like 
>>> https://urldefense.us/v3/__https://petsc.org/release/src/ksp/pc/impls/redistribute/redistribute.c.html*line332__;Iw!!G_uCfscf7eWS!dzQtfplyy0liDIzLvwZPEQ15gmxeoXxZBqfgkYyHOUdkUhP-wvoKWG58yEPisaaRzqydtExDOol1d4MSyysHYQ$
>>>   could be copy/paste’d into PCApplyTranspose_Redistribute() by just 
>>> changing a MatMult() to MatMultTranspose() and KSPSolve() to 
>>> KSPSolveTranspose().
>>> Would you be willing to contribute (and test) this?
>>> Then, KSPSolveTranspose() — which should be the function you call — will 
>>> work.
>>> 
>>> Thanks,
>>> Pierre
>> 
>> Thanks, that sounds promising. Yes, I'll try to make a contribution
>> /Carl-Johan



Re: [petsc-users] MatCreateTranspose

2024-04-12 Thread Carl-Johan Thore
Pierre, I see that you've already done a merge request for this. Thanks!
I have tested this and it works nicely in my application
/Carl-Johan

On Wed, Apr 10, 2024 at 8:24 AM Carl-Johan Thore 
wrote:

>
>
> On Tue, Apr 9, 2024 at 5:31 PM Pierre Jolivet  wrote:
>
>>
>> On 9 Apr 2024, at 4:19 PM, Carl-Johan Thore 
>> wrote:
>>
>> This Message Is From an External Sender
>> This message came from outside your organization.
>> Thanks for the suggestion. I don't have a factored matrix (and can't
>> really use direct linear solvers) so MatSolveTranspose doesn't seem to
>> be an option.
>> I should have mentioned that I've also tried KSPSolveTranspose but that
>> doesn't work with pcredistribute
>>
>>
>> I’m not a frequent PCREDISTRIBUTE user, but it looks like
>> https://urldefense.us/v3/__https://petsc.org/release/src/ksp/pc/impls/redistribute/redistribute.c.html*line332__;Iw!!G_uCfscf7eWS!d3xUyKqZovzqGxg2_Ek4FStdTXsvnabp6mvY0kSRCCRZXZ6y6pd8MUnEi9sZR8QjNGiwWLxXy3N08YLxKwIcWBQ9Jbc-Qg$
>>   could
>> be copy/paste’d into PCApplyTranspose_Redistribute() by just changing a
>> MatMult() to MatMultTranspose() and KSPSolve() to KSPSolveTranspose().
>> Would you be willing to contribute (and test) this?
>> Then, KSPSolveTranspose() — which should be the function you call — will
>> work.
>>
>> Thanks,
>> Pierre
>>
>
> Thanks, that sounds promising. Yes, I'll try to make a contribution
> /Carl-Johan
>


Re: [petsc-users] MatCreateTranspose

2024-04-10 Thread Carl-Johan Thore
On Tue, Apr 9, 2024 at 5:31 PM Pierre Jolivet  wrote:

>
> On 9 Apr 2024, at 4:19 PM, Carl-Johan Thore 
> wrote:
>
> This Message Is From an External Sender
> This message came from outside your organization.
> Thanks for the suggestion. I don't have a factored matrix (and can't
> really use direct linear solvers) so MatSolveTranspose doesn't seem to be
> an option.
> I should have mentioned that I've also tried KSPSolveTranspose but that
> doesn't work with pcredistribute
>
>
> I’m not a frequent PCREDISTRIBUTE user, but it looks like
> https://urldefense.us/v3/__https://petsc.org/release/src/ksp/pc/impls/redistribute/redistribute.c.html*line332__;Iw!!G_uCfscf7eWS!cgAsxyEH_bcrB52QRg6oG5BdTF8bLQr9pb71JxdsoP7FOO0BCi8XGqL6D3oXT9GrnsuqWfA8MuLi8xxWvmzAKeSxmS6R2g$
>   could
> be copy/paste’d into PCApplyTranspose_Redistribute() by just changing a
> MatMult() to MatMultTranspose() and KSPSolve() to KSPSolveTranspose().
> Would you be willing to contribute (and test) this?
> Then, KSPSolveTranspose() — which should be the function you call — will
> work.
>
> Thanks,
> Pierre
>

Thanks, that sounds promising. Yes, I'll try to make a contribution
/Carl-Johan


Re: [petsc-users] MatCreateTranspose

2024-04-09 Thread Pierre Jolivet

> On 9 Apr 2024, at 4:19 PM, Carl-Johan Thore  wrote:
> 
> This Message Is From an External Sender
> This message came from outside your organization.
> Thanks for the suggestion. I don't have a factored matrix (and can't really 
> use direct linear solvers) so MatSolveTranspose doesn't seem to be an option. 
> I should have mentioned that I've also tried KSPSolveTranspose but that 
> doesn't work with pcredistribute

I’m not a frequent PCREDISTRIBUTE user, but it looks like 
https://urldefense.us/v3/__https://petsc.org/release/src/ksp/pc/impls/redistribute/redistribute.c.html*line332__;Iw!!G_uCfscf7eWS!bgGlN3dW5g5M98EkZPPaYivRkcXtawYE_jKsdMC0zK2bDy4u1Qy1KOMIcZ-_sBABRkHTzGlKHmAefb8Ozy3XbQ$
  could be copy/paste’d into PCApplyTranspose_Redistribute() by just changing a 
MatMult() to MatMultTranspose() and KSPSolve() to KSPSolveTranspose().
Would you be willing to contribute (and test) this?
Then, KSPSolveTranspose() — which should be the function you call — will work.

Thanks,
Pierre

> /Carl-Johan
> 
> On Tue, Apr 9, 2024 at 3:59 PM Zhang, Hong  > wrote:
>> Carl-Johan,
>> You can use MatSolveTranspose() to solve A'*x = b. See 
>> petsc/src/ksp/ksp/tutorials/ex79.c
>> 
>> `MatCreateTranspose()` is used if you only need a matrix that behaves like 
>> the transpose, but don't need the storage to be changed, i.e., A and A' 
>> share same matrix storage, thus MatGetRow() needs to get columns of A, which 
>> is not supported.
>> 
>> Hong
>> From: petsc-users > > on behalf of Carl-Johan Thore 
>> mailto:carljohanth...@gmail.com>>
>> Sent: Tuesday, April 9, 2024 6:38 AM
>> To: petsc-users mailto:petsc-users@mcs.anl.gov>>
>> Subject: [petsc-users] MatCreateTranspose
>>  
>> This Message Is From an External Sender 
>> This message came from outside your organization. 
>>  
>> Hi,
>> 
>> I have a matrix A with transpose A' and would like to solve the linear 
>> system A'*x = b using the pcredistribute preconditioner. It seemed like a 
>> good idea to use MatCreateTranspose, but this leads to
>> 
>> [0]PETSC ERROR: - Error Message 
>> --
>> [0]PETSC ERROR: No support for this operation for this object type
>> [0]PETSC ERROR: No method getrow for Mat of type transpose
>> [0]PETSC ERROR: See 
>> https://urldefense.us/v3/__https://petsc.org/release/faq/__;!!G_uCfscf7eWS!bgGlN3dW5g5M98EkZPPaYivRkcXtawYE_jKsdMC0zK2bDy4u1Qy1KOMIcZ-_sBABRkHTzGlKHmAefb8Z27cesg$
>>   
>> 
>>  for trouble shooting.
>> [0]PETSC ERROR: Petsc Release Version 3.21.0, unknown
>> [0]PETSC ERROR: Configure options COPTFLAGS="-O3 -march=native" 
>> CXXOPTFLAGS="-O3 -march=native" --with-fortran-bindings=0 FOPTFLAGS="-O3 
>> -march=native" CUDAOPTFLAGS=-O3 --with-cuda --with-cusp --with-debugging=0 
>> --download-scalapack --download-hdf5 --download-zlib --download-mumps 
>> --download-parmetis --download-metis --download-ptscotch --download-hypre 
>> --download-spai
>> [0]PETSC ERROR: #1 MatGetRow() at 
>> /mnt/c/mathware/petsc/petsc-v3-21-0/src/mat/interface/matrix.c:573
>> [0]PETSC ERROR: #2 PCSetUp_Redistribute() at 
>> /mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/pc/impls/redistribute/redistribute.c:111
>> [0]PETSC ERROR: #3 PCSetUp() at 
>> /mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/pc/interface/precon.c:1079
>> [0]PETSC ERROR: #4 KSPSetUp() at 
>> /mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/ksp/interface/itfunc.c:415
>> 
>> MatTranspose is a working alternative, but MatCreateTranspose would be 
>> preferable. In principle the solution seems straightforward -- just add a 
>> getrow method -- but is it, and is it a good idea (performancewise etc)?
>> 
>> Kind regards,
>> Carl-Johan 



Re: [petsc-users] MatCreateTranspose

2024-04-09 Thread Carl-Johan Thore
Thanks for the suggestion. I don't have a factored matrix (and can't really
use direct linear solvers) so MatSolveTranspose doesn't seem to be an
option.
I should have mentioned that I've also tried KSPSolveTranspose but that
doesn't work with pcredistribute
/Carl-Johan

On Tue, Apr 9, 2024 at 3:59 PM Zhang, Hong  wrote:

> Carl-Johan,
> You can use MatSolveTranspose() to solve A'*x = b. See
> petsc/src/ksp/ksp/tutorials/ex79.c
>
> `MatCreateTranspose()` is used if you only need a matrix that behaves like
> the transpose, but don't need the storage to be changed, i.e., A and A'
> share same matrix storage, thus MatGetRow() needs to get columns of A,
> which is not supported.
>
> Hong
> --
> *From:* petsc-users  on behalf of
> Carl-Johan Thore 
> *Sent:* Tuesday, April 9, 2024 6:38 AM
> *To:* petsc-users 
> *Subject:* [petsc-users] MatCreateTranspose
>
> Hi, I have a matrix A with transpose A' and would like to solve the linear
> system A'*x = b using the pcredistribute preconditioner. It seemed like a
> good idea to use MatCreateTranspose, but this leads to [0]PETSC ERROR:
> -
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
> Hi,
>
> I have a matrix A with transpose A' and would like to solve the linear
> system A'*x = b using the pcredistribute preconditioner. It seemed like a
> good idea to use MatCreateTranspose, but this leads to
>
> [0]PETSC ERROR: - Error Message
> --
> [0]PETSC ERROR: No support for this operation for this object type
> [0]PETSC ERROR: No method getrow for Mat of type transpose
> [0]PETSC ERROR: See 
> https://urldefense.us/v3/__https://petsc.org/release/faq/__;!!G_uCfscf7eWS!ep5IoJ3UZoQ62Wb4ElaMmi9G3Svqdr3ldXVnCRd-47InZQBv34SgL7WDdEFLYJDtFYzCdxXGf4WaQ9U5JwPTNHtq_gyDKw$
>  
> 
> for trouble shooting.
> [0]PETSC ERROR: Petsc Release Version 3.21.0, unknown
> [0]PETSC ERROR: Configure options COPTFLAGS="-O3 -march=native"
> CXXOPTFLAGS="-O3 -march=native" --with-fortran-bindings=0 FOPTFLAGS="-O3
> -march=native" CUDAOPTFLAGS=-O3 --with-cuda --with-cusp --with-debugging=0
> --download-scalapack --download-hdf5 --download-zlib --download-mumps
> --download-parmetis --download-metis --download-ptscotch --download-hypre
> --download-spai
> [0]PETSC ERROR: #1 MatGetRow() at
> /mnt/c/mathware/petsc/petsc-v3-21-0/src/mat/interface/matrix.c:573
> [0]PETSC ERROR: #2 PCSetUp_Redistribute() at
> /mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/pc/impls/redistribute/redistribute.c:111
> [0]PETSC ERROR: #3 PCSetUp() at
> /mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/pc/interface/precon.c:1079
> [0]PETSC ERROR: #4 KSPSetUp() at
> /mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/ksp/interface/itfunc.c:415
>
> MatTranspose is a working alternative, but MatCreateTranspose would be
> preferable. In principle the solution seems straightforward -- just add a
> getrow method -- but is it, and is it a good idea (performancewise etc)?
>
> Kind regards,
> Carl-Johan
>


Re: [petsc-users] MatCreateTranspose

2024-04-09 Thread Zhang, Hong via petsc-users
Carl-Johan,
You can use MatSolveTranspose() to solve A'*x = b. See 
petsc/src/ksp/ksp/tutorials/ex79.c

`MatCreateTranspose()` is used if you only need a matrix that behaves like the 
transpose, but don't need the storage to be changed, i.e., A and A' share same 
matrix storage, thus MatGetRow() needs to get columns of A, which is not 
supported.

Hong

From: petsc-users  on behalf of Carl-Johan 
Thore 
Sent: Tuesday, April 9, 2024 6:38 AM
To: petsc-users 
Subject: [petsc-users] MatCreateTranspose

Hi, I have a matrix A with transpose A' and would like to solve the linear 
system A'*x = b using the pcredistribute preconditioner. It seemed like a good 
idea to use MatCreateTranspose, but this leads to [0]PETSC ERROR: 
-
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.

ZjQcmQRYFpfptBannerEnd
Hi,

I have a matrix A with transpose A' and would like to solve the linear system 
A'*x = b using the pcredistribute preconditioner. It seemed like a good idea to 
use MatCreateTranspose, but this leads to

[0]PETSC ERROR: - Error Message 
--
[0]PETSC ERROR: No support for this operation for this object type
[0]PETSC ERROR: No method getrow for Mat of type transpose
[0]PETSC ERROR: See 
https://urldefense.us/v3/__https://petsc.org/release/faq/__;!!G_uCfscf7eWS!ZjJecuElTk9FpHCmWARWcvLbSCiWXeEshhB3Z61WIK2V0KX6gOTrfRK8nMlqoZ8Q7Q1y7I3VGWH_MP7gYz7pNt0l$
 

 for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.21.0, unknown
[0]PETSC ERROR: Configure options COPTFLAGS="-O3 -march=native" 
CXXOPTFLAGS="-O3 -march=native" --with-fortran-bindings=0 FOPTFLAGS="-O3 
-march=native" CUDAOPTFLAGS=-O3 --with-cuda --with-cusp --with-debugging=0 
--download-scalapack --download-hdf5 --download-zlib --download-mumps 
--download-parmetis --download-metis --download-ptscotch --download-hypre 
--download-spai
[0]PETSC ERROR: #1 MatGetRow() at 
/mnt/c/mathware/petsc/petsc-v3-21-0/src/mat/interface/matrix.c:573
[0]PETSC ERROR: #2 PCSetUp_Redistribute() at 
/mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/pc/impls/redistribute/redistribute.c:111
[0]PETSC ERROR: #3 PCSetUp() at 
/mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/pc/interface/precon.c:1079
[0]PETSC ERROR: #4 KSPSetUp() at 
/mnt/c/mathware/petsc/petsc-v3-21-0/src/ksp/ksp/interface/itfunc.c:415

MatTranspose is a working alternative, but MatCreateTranspose would be 
preferable. In principle the solution seems straightforward -- just add a 
getrow method -- but is it, and is it a good idea (performancewise etc)?

Kind regards,
Carl-Johan