Matrix-Vector Multiplication

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


after your answer I tried this,

MPI_Gatherv(&local_res, local_n, MPI_DOUBLE, &res,,,MPI_DOUBLE, 0,MPI_COMM_WORLD);

but still the same answer and this error " (*_Pnext)->_Myproxy = nullptr;"
Last edited on

Surely, we've been here before?
&local_res is a pointer to the vector itself, NOT to its data buffer. You need
Similarly with &res - should be
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 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.