I am writing a function in c++ that computes the sum of double numbers in parallel using MPI.
I assume that each process has its number and the problem is to find the sum of all numbers in each processor in parallel using binary tree method where each node is a process. So the algorithm must work in O(logn).
Does anybody has any ideas about this problem or already ready code in MPI?
Yes, use the MPI_Reduce function where the op argument is MPI_SUM. AFAIK the standard doesn’t specify how the reduction is done, but I’m quite sure any competitive MPI library will use a tree reduction algorithm.