Skip to content
Advertisement

Convert a list of Vector to a matrix with petsc4py

I have a list of vectors that I want to gather in a single matrix Z. Here is the code I tried to use :

JavaScript

I tried setValues and setValuesBlocked. When I run this script on one core, that works well. The result printed is :

JavaScript

but in parallel I have issues :

JavaScript

I think it’s because PetSc waits for the local indices in the function setValues, but I don’t know how to access it (local_size gives the local size of the matrix, if I put Z.local_size[0] in setValues, the result in parallel is

JavaScript

)

Which function or what argument should I use to fulfill this ?

EDIT :

I tried a more tedious way to fill the matrix Z, using the following double loop :

JavaScript

once again in sequential, that works fine, but if I run it over 2 cores here is the result, totally wrong !

JavaScript

Advertisement

Answer

Thank to the help of the team developping PetSc, I managed to do it. Here is the code :

JavaScript

We need to use a dense matrix, and the function getDenseColumnVec allows to access to a column of the matrix, and modify it at will.

That works both in sequential and parallel.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement