I'm going to mastering MPI in this summer. I started to read "An Introduction to Parallel Programming" by Peter Pacheco, and solving its exercise. In one of it's MPI exercise he asked for implementing simple prefix sum with MPI_Scan, but I couldn't implement it with MPI_Scan. I found a solution by using MPI_Scatter, and MPI_Gather. Please help me to find an answer for MPI_Scan.
// declaring array and result
// generating random array
MPI_Bcast( &array, n, MPI_FLOAT, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Scan(array, result, n, MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
I'm expecting to have prefix sum in result but for some reason it is not working.