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

Cyrill Vonplanta cyrill.von.planta at usi.ch
Tue Mar 5 03:08:45 CST 2019


Yes, this does the trick for me. Thanks.

Thx Cyrill

> On 5 Mar 2019, at 00:10, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
> 
> 
>   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 <petsc-users at mcs.anl.gov> wrote:
>> 
>> On Mon, Mar 4, 2019 at 11:28 AM Cyrill Vonplanta via petsc-users <petsc-users at 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]);
>> }
>> 
>>  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/
> 



More information about the petsc-users mailing list