简体   繁体   中英

How many times is the reduce operation called by MPI_Reduce?

I use the same operation (first code) described here [1].

MPI_Reduce(local, global, 1, mpi_datatype, mpi_selectop, 0, MPI_COMM_WORLD);

I saw that MPI_Reduce is called by p-1 number of process in the communicator but this is false for other reduce functions like MPI_Allreduce.

1Q - Is there a pattern to know how many times an operation created is called by MPI_Reduce?

2Q - Is there a way to reduce the number of calls of MPI_Reduce to only one process (root) but with input entries of all process?

[1] First k results

First, I assume you mean MPI user reduction function when you write MPI_Reduce .

1) It is not defined how often the user reduction function is called. For example a MPI Implementation is explicitly allowed to call the reduction operation on chunks of the input data. Therefore you should not make any assumptions about that with respect to correctness. If you want to optimize, then measure it for your specific situation.

2) If you insist to call the reduction operation only on the root rank you could use MPI_Gather (if memory permits). MPI_Reduce_Local might help you a bit, but it is not a collective reduction, only a way to call an MPI_Op . This will be much less efficient because you are wasting computing and communication capacity of the non-food ranks. Effectively you are going from O(log n) to O(n) in terms of time complexity.

There might be a better solution if you can describe the actual problem you are trying to solve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM