I have an problem in a parallelised code where I need to reduce values from all processors to the root process, summing them and then assigning the sum to an array element. I would like to do this in a loop such that each MPI_Reduce() call reduces to consecutive elements along an array. I would like to know how to point to the specific location in the array.
The part of the for-loop code is shown below:
for(int i = 1; i < N_t; i++) {
...............
loc_EK = valEK * (cblas_ddot(loc_N, loc_vx, 1, loc_vx, 1) +
cblas_ddot(loc_N, loc_vy, 1, loc_vy, 1));
loc_EP = valEP * cblas_dasum(loc_N, loc_y, 1);
loc_ET = loc_EP + loc_EK;
MPI_Reduce(&loc_EK, (EK + 1 + i), 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Reduce(&loc_EP, (EP + 1 + i), 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Reduce(&loc_ET, (ET + 1 + i), 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
}
}
What I have tried:
I am currectly pointing the the array positions using (EK+i+1), where EK is the pointer to a dynamic array. I have tried using EK[i+1] but as expected this did not work. How should I fix this so that I can assign each reduced sum to elements of the array pointed to by EK?