Reputation: 4203
I have recently started trying to learn MPI to code in C. I am trying to write very small test codes to make sure I know what I'm doing as I go along. Unfortunately, I seem to be having an issue with one of them, which multiplies a matrix with a vector and outputs the resulting vector. Specifically, when I call:
MPI_Reduce(c, myc, 3, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
where myc is the part of the vector that is calculated by each processor, my final result is that c[i] = 0 for all i. The code that calculates myc is correct (checked using one processor and outputting myc instead of c). I assume I'm doing something very stupid here, but can't figure out what.
Upvotes: 3
Views: 10558
Reputation: 15100
So you want your answer in c
and not myc
?
The syntax is:
int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, int root, MPI_Comm comm)
so you are sending c
into myc
with your example.
Also note that recvbuf
is only valid on the root node, which in your case is node 0. All the others will have garbage in recvbuf
.
Upvotes: 5