[petsc-users] On the usage of MatSetValuesBlocked

Barry Smith bsmith at petsc.dev
Thu Nov 3 18:34:56 CDT 2022


   You should pass 1 and 1 not 3, because you are setting one block.

   Regarding all the integer values passed in to PETSc routines To be completely portable you need to declare them as PetscInt and pass the variables. But if you do not use --with-64-bit-indices in ./configure and you do not use some Fortran compiler option to promote all integers to 64 bit integers just passing in directly the 0 etc is fine.

   The reason you get different results with a 0 or a Fortran integer is because of the 3 PETSc tries to three indices from 0 value you pass in so it is readying memory it is not suppose to be reading. Once you change the 3 to 1 it will likely be fine.

  Barry


> On Nov 3, 2022, at 5:56 PM, Edoardo alinovi <edoardo.alinovi at gmail.com> wrote:
> 
> Barry,
> 
> Can you please provide me with an example on how to use MatSetValuesBlocked? 
> 
> To play it easy, let's say that I want to insert a 3x3 block matrix b into the matrix A, rows 0-2, columns 0-2. Up to what I've understood (very few apparently XD ), I would do like this:
> 
> b(3,3) = 11.0 
> call MatSetValuesBlocked(A, 3, 0, 3, 0, b, INSERT_VALUES, ierr).  
> 
> This does not work at all, I get this result that does not make any sense 😫
> 
> <image.png>
> 
> It places 6 values instead of 9 and it they are in odd locations (0 1 2 9 10 11).
> 
> Also I noted that I am getting  different results if in place of  the zero in red I use a fortran integer 😥
> 
> Super thanks for the help

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221103/cbf7247a/attachment-0001.html>


More information about the petsc-users mailing list