00001 #ifndef Impala_Util_Mpi_Reduce_h
00002 #define Impala_Util_Mpi_Reduce_h
00003
00004 #include "Link/Mpi/MpiFuncs.h"
00005 #include <vector>
00006
00007 namespace Impala
00008 {
00009 namespace Util
00010 {
00011 namespace Mpi
00012 {
00013
00015 void Reduce(std::vector<double>& v)
00016 {
00017 #ifdef MPI_USED
00018 MPI_Barrier(MPI_COMM_WORLD);
00019 int gridSize = v.size();
00020
00021 double* grid = new double[gridSize];
00022 int i;
00023 for(i=0 ; i<gridSize ; ++i)
00024 grid[i] = v[i];
00025
00026 double* reducedGrid = 0;
00027 if(Link::Mpi::MyId() == 0)
00028 reducedGrid = new double[gridSize];
00029 MPI_Reduce(grid, reducedGrid, gridSize, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
00030 if(Link::Mpi::MyId() == 0)
00031 {
00032 for(i=0 ; i<gridSize ; ++i)
00033 v[i] = reducedGrid[i];
00034 delete reducedGrid;
00035 }
00036 #endif
00037 }
00038
00039 }
00040 }
00041 }
00042
00043 #endif
00044