Hernan
Hernan

Reputation: 6063

MPI_REDUCE a dynamically computed array

I am trying to use MPI_REDUCE in C (or c++) to find the minimum (and the index) in an array. I have this working for regular array, but now I want to switch to one in which the value is dynamically computed. i.e the value of arr[n] is calculated by calling fun(n). Due to memory problems I cannot compute all values an put them in a regular array.

How can I achieve this?

Thanks in advance,

Upvotes: 1

Views: 382

Answers (1)

suszterpatt
suszterpatt

Reputation: 8273

You'll need to use MPI_Op_create() to create a custom MPI operation: in your case, this operation would compare the values obtained by calling fun() on each element of the array, and select the minimum. You can then use this custom operation in the Op argument of MPI_Reduce().

Upvotes: 2

Related Questions