Re: [petsc-users] Compute the sum of the absolute values of the off-block diagonal entries of each row

2019-03-04 Thread Smith, Barry F. via petsc-users


   How about something like,

   MatMPIAIJGetSeqAIJ(A,NULL,&Ao,NULL);

> MatGetOwnershipRange(A, &rS, &rE);
> for (r = 0; r < rE-rS; ++r) {
>   sum = 0.0;
>   MatGetRow(Ao, r, &ncols, NULL, &vals);
>   for (c = 0; c < ncols; ++c) sum += PetscAbsScalar(vals[c]);
   // do what you need with sum
> }


   Barry



> On Mar 4, 2019, at 10:38 AM, Matthew Knepley via petsc-users 
>  wrote:
> 
> On Mon, Mar 4, 2019 at 11:28 AM Cyrill Vonplanta via petsc-users 
>  wrote:
> Dear Petsc Users,
> 
> I am trying to implement a variant of the $l^1$-Gauss-Seidel smoother from 
> https://doi.org/10.1137/100798806 (eq. 6.1 and below). One of the main issues 
> is that I need to compute the sum  $\sum_j |a_{i_j}|$ of the matrix entries 
> that are not part of the local diagonal block. I was looking for something 
> like MatGetRowSumAbs but it looks like it hasn't been made yet.
> 
> I guess i have to come up with something myself, but would you know of some 
> workaround for this without going too deep into PETCs?
> 
> MatGetOwnershipRange(A, &rS, &rE);
> for (r = rS; r < rE; ++r) {
>   sum = 0.0;
>   MatGetRow(A, r, &ncols, &cols, &vals);
>   for (c = 0; c < ncols; ++c) if ((cols[c] < rS) || (cols[c] >= rE)) sum += 
> PetscAbsScalar(vals[c]);
> }
> 
>   Thanks,
> 
>  Matt
>  
> Best Cyrill
> -- 
> 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
> 
> https://www.cse.buffalo.edu/~knepley/



Re: [petsc-users] Compute the sum of the absolute values of the off-block diagonal entries of each row

2019-03-04 Thread Jed Brown via petsc-users
"Zhang, Junchao via petsc-users"  writes:

> Perhaps PETSc should have a MatGetRemoteRow (or
> MatGetRowOffDiagonalBlock) (A, r, &ncols, &cols, &vals).  MatGetRow()
> internally has to allocate memory and sort indices and values from
> local diagonal block and off-diagonal block. It is totally a waste in
> this case -- users do not care column indices and the local block.
> With MatGetRemoteRow(A, r, &ncols, NULL, &vals), PETSc just needs to
> set an integer and a pointer.

I'm not wild about the resulting programming model, which is so
intimately tied to PETSc *AIJ storage conventions yet also likely not
efficient for operations like SOR.  Perhaps PETSc MatSOR should be
taught about a supplemental diagonal, such as produced by the "l^1"
scheme?


Re: [petsc-users] Compute the sum of the absolute values of the off-block diagonal entries of each row

2019-03-04 Thread Zhang, Junchao via petsc-users


On Mon, Mar 4, 2019 at 10:39 AM Matthew Knepley via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
On Mon, Mar 4, 2019 at 11:28 AM Cyrill Vonplanta via petsc-users 
mailto:petsc-users@mcs.anl.gov>> wrote:
Dear Petsc Users,

I am trying to implement a variant of the $l^1$-Gauss-Seidel smoother from 
https://doi.org/10.1137/100798806 (eq. 6.1 and below). One of the main issues 
is that I need to compute the sum  $\sum_j |a_{i_j}|$ of the matrix entries 
that are not part of the local diagonal block. I was looking for something like 
MatGetRowSumAbs but it looks like it hasn't been made yet.

I guess i have to come up with something myself, but would you know of some 
workaround for this without going too deep into PETCs?

MatGetOwnershipRange(A, &rS, &rE);
for (r = rS; r < rE; ++r) {
  sum = 0.0;
  MatGetRow(A, r, &ncols, &cols, &vals);
  for (c = 0; c < ncols; ++c) if ((cols[c] < rS) || (cols[c] >= rE)) sum += 
PetscAbsScalar(vals[c]);
}
Perhaps PETSc should have a MatGetRemoteRow (or MatGetRowOffDiagonalBlock) (A, 
r, &ncols, &cols, &vals).  MatGetRow() internally has to allocate memory and 
sort indices and values from local diagonal block and off-diagonal block. It is 
totally a waste in this case -- users do not care column indices and the local 
block.  With MatGetRemoteRow(A, r, &ncols, NULL, &vals), PETSc just needs to 
set an integer and a pointer.


  Thanks,

 Matt

Best Cyrill
--
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

https://www.cse.buffalo.edu/~knepley/


[petsc-users] Compute the sum of the absolute values of the off-block diagonal entries of each row

2019-03-04 Thread Cyrill Vonplanta via petsc-users
Dear Petsc Users,

I am trying to implement a variant of the $l^1$-Gauss-Seidel smoother from 
https://doi.org/10.1137/100798806 (eq. 6.1 and below). One of the main issues 
is that I need to compute the sum  $\sum_j |a_{i_j}|$ of the matrix entries 
that are not part of the local diagonal block. I was looking for something like 
MatGetRowSumAbs but it looks like it hasn't been made yet.

I guess i have to come up with something myself, but would you know of some 
workaround for this without going too deep into PETCs?

Best Cyrill



[petsc-users] Loading only upper + MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);

2019-03-04 Thread Klaus Burkart via petsc-users
Hello,

I want to solve many symmetric linear systems one after another in parallel 
using boomerAMG + KSPCG  and need to make the matrix transfer more efficient. 
Matrices are symmetric in structure and values. boomerAMG + KSPCG work fine.

So far I have been loading the entire matrices but I read in a paper, that it's 
sufficient to load the upper part only and tell petsc that the matrix is 
symmetric using MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE); Unfortunately all 
computations fail if I load only the upper values and use 
MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);
The idea is:
    if (matrix_.symmetric())
    {
    MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);
   //load only upper part of the matrix MatSetValues(...)

   }else //asymmetric matrix
   {   //load the entire matrix MatSetValues(...)
   }

Is it possible at all? 

Klaus