Dear all,
I want to build the scalar product between rows of a
TrilinosWrappers::SparseMatrix and a TrilinosWrappers::MPI::Vector.
I implemented this by looping over the elements of the rows via iterators
(it = systemMatrix.begin(row) , itend = systemMatrix.end(row)
-> while (it != itend) { ... it++; } )
Inside while, I calculate it->value (to get the matrix element) times vec(it->column())
(to get the corresponding vector element) and sum it up.
I calculate the scalar product for a set of rows and store the result in a FullMatrix
which I finally write to a file from the master process,
after gathering the local full matrices from all processors.
Attached is a small example which demonstrates this in practice.
In a parallel program,
vec(it->column()) only works if
it->column() is a locally owned element of the vector. So I wrapped this read access in
if(
vec.in_local_range(it->column() ) .
Another problem is the following:
Say row 5 lives on processor 0 and has non-zero entries at columns 10,15,20,25,30.
Columns 10,15,20 live on processor 0 as well but columns 25,30 live on processor 1.
Then, I will never add the contributions to the scalar product from columns 25 and 30 because on processor 1,
systemMatrix.begin(5) == systemMatrix.end(5)
which is also stated in the docu.
How can I deal with this?
Best,
Simon