user1079226
user1079226

Reputation: 153

Giving jobs to threads - MPI

I am passing in a value into my MPI program written in C. So if I pass in a value of 5, I want to to give the number 5 to thread number one, number 4 to thread number 2 etc. How would I do this?

At the end I have a MPI reduce which does the product of all these values (5*4*3...), so I don't really need to do anything in the thread but I just need to pass different values to each thread.

Upvotes: 0

Views: 92

Answers (1)

Neo
Neo

Reputation: 1554

This sounds like an assignment, so I will only write out the pseudo-code.

  1. Read value (5 for eg.) into some variable
  2. MPI_Init
  3. Get rank of MPI process using MPI_Comm_rank
  4. In a loop, assign a value to some variable based on rank of process
  5. Invoke MPI_Reduce on the variable initialized in step 4.
  6. MPI_Finalize
  7. Print from single/multiple processes based on requirement

Even I think that you actually mean processes, and NOT threads (as suszterpatt already pointed out in the comment).

Upvotes: 2

Related Questions