Matrix-Vector Multiplication

Hello,
I am trying to do a matrix vector multiplication using MPI. The matrix is a diagonal one, so I store the diagonal elements in a vector. then I distribute the element of two vectors among processors and do the multiplication. at the end I gather the local result. the problem is that the size of vector is changing and it gives me some strange results.
Last edited on
The opposite of MPI_Scatterv is MPI_Gatherv, not MPI_Gather.

"Strange results" is also not a helpful description.
Last edited on
I mean the size of second vector changes from 4 to a big number. and I get this answer

1
2
3
4
-1.45682e+144
-1.45682e+144
-1.45682e+144
-1.45682e+144


after your answer I tried this,

MPI_Gatherv(&local_res, local_n, MPI_DOUBLE, &res, scounts.data(), displs.data(),MPI_DOUBLE, 0,MPI_COMM_WORLD);

but still the same answer and this error " (*_Pnext)->_Myproxy = nullptr;"
Last edited on
Try
MPI_Gatherv( local_res.data(), local_n, MPI_DOUBLE, res.data(), scounts.data(), displs.data(),MPI_DOUBLE, 0,MPI_COMM_WORLD);


Surely, we've been here before?
&local_res is a pointer to the vector itself, NOT to its data buffer. You need local_res.data()
Similarly with &res - should be res.data()
Last edited on
Thanks for your answer. Yes, you explained this before in one thread, I went for that first but I had a mistake, I wrote &res instead of res.data() but for the other arguments I had used .data(). That's why in the first try I didn't get the right answer.
Last edited on
If you make the change that I posted then your code runs and produces the correct answer for 1, 2, 3 or 4 processors.
Yes,it's working now, thank you.
Topic archived. No new replies allowed.