3

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Sigh... I really am an idiot. Thanks for pointing out my idiocy. It works now.
We've all been there, no worries!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.