| 1 | /**
|
|---|
| 2 | * @file comm_mpi.hpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Wed Jun 16 13:21:06 2010
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Class for MPI-based communication.
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifndef COMM_MPI_HPP_
|
|---|
| 11 | #define COMM_MPI_HPP_
|
|---|
| 12 |
|
|---|
| 13 | #ifndef HAVE_MPI
|
|---|
| 14 | #error You need MPI in order to compile CommMPI
|
|---|
| 15 | #endif
|
|---|
| 16 |
|
|---|
| 17 | #include <cstdarg>
|
|---|
| 18 | #include <cstdio>
|
|---|
| 19 | #include <list>
|
|---|
| 20 | #include <map>
|
|---|
| 21 | #include <vector>
|
|---|
| 22 |
|
|---|
| 23 | #include "base/has_tempgrids.hpp"
|
|---|
| 24 | #include "comm/comm.hpp"
|
|---|
| 25 | #include "comm/mpi/settings.hpp"
|
|---|
| 26 | #include "comm/mpi/has_request_vec.hpp"
|
|---|
| 27 |
|
|---|
| 28 | namespace VMG
|
|---|
| 29 | {
|
|---|
| 30 |
|
|---|
| 31 | class DomainDecomposition;
|
|---|
| 32 | class GridIteratorSet;
|
|---|
| 33 | class TempGrid;
|
|---|
| 34 |
|
|---|
| 35 | class CommMPI : public Comm, HasTempGrids, HasRequestVec
|
|---|
| 36 | {
|
|---|
| 37 | public:
|
|---|
| 38 | CommMPI(const Boundary& boundary, DomainDecomposition* domain_dec, const MPI_Comm& mpi_comm) :
|
|---|
| 39 | Comm(boundary, domain_dec),
|
|---|
| 40 | win_created(false)
|
|---|
| 41 | {
|
|---|
| 42 | InitCommMPI(mpi_comm);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | CommMPI(const Boundary& boundary, DomainDecomposition* domain_dec) :
|
|---|
| 46 | Comm(boundary, domain_dec),
|
|---|
| 47 | win_created(false)
|
|---|
| 48 | {
|
|---|
| 49 | InitCommMPI(MPI_COMM_WORLD);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | virtual ~CommMPI();
|
|---|
| 53 |
|
|---|
| 54 | Grid& GetCoarserGrid(Multigrid& multigrid);
|
|---|
| 55 | Grid& GetFinerGrid(Multigrid& multigrid);
|
|---|
| 56 | Grid& GetGlobalCoarseGrid(Multigrid& multigrid);
|
|---|
| 57 |
|
|---|
| 58 | void CommFromGhosts(Grid& grid);
|
|---|
| 59 | void CommToGhosts(Grid& grid);
|
|---|
| 60 | void CommToGhostsRB(Grid& grid, const int& offset);
|
|---|
| 61 | void CommSubgrid(Grid& grid_old, Grid& grid_new);
|
|---|
| 62 | void CommAddSubgrid(Grid& grid_old, Grid& grid_new);
|
|---|
| 63 |
|
|---|
| 64 | void CommToGhostsAsyncStart(Grid& grid);
|
|---|
| 65 | void CommToGhostsAsyncFinish();
|
|---|
| 66 | void CommFromGhostsAsyncStart(Grid& grid);
|
|---|
| 67 | void CommFromGhostsAsyncFinish(Grid& grid);
|
|---|
| 68 |
|
|---|
| 69 | vmg_float GlobalSum(const vmg_float& value);
|
|---|
| 70 | vmg_float GlobalSumRoot(const vmg_float& value);
|
|---|
| 71 | void GlobalSumArray(vmg_float* array, const vmg_int& size);
|
|---|
| 72 |
|
|---|
| 73 | void PrintString(const char* format, ...);
|
|---|
| 74 | void PrintStringOnce(const char* format, ...);
|
|---|
| 75 | void PrintXML(const std::string& filename, const std::string& xml_data);
|
|---|
| 76 | void PrintXMLAll(const std::string& filename, const std::string& xml_data);
|
|---|
| 77 | void PrintAllSettings();
|
|---|
| 78 | void PrintDefect(Grid& sol, Grid& rhs, const char* information);
|
|---|
| 79 | void PrintGrid(Grid& grid, const char* information);
|
|---|
| 80 | void PrintCorrectedGrid(Grid& grid, const char* information);
|
|---|
| 81 | void PrintInnerGrid(Grid& grid, const char* information);
|
|---|
| 82 | void PrintInnerCorrectedGrid(Grid& grid, const char* information);
|
|---|
| 83 |
|
|---|
| 84 | void CommParticles(const Grid& grid, std::list<Particle::Particle>& particles);
|
|---|
| 85 | void CommLCListGhosts(const Grid& grid, Particle::LinkedCellList& lc);
|
|---|
| 86 | void CommAddPotential(std::list<Particle::Particle>& particles);
|
|---|
| 87 | void CommAddPotential(Particle::LinkedCellList& lc);
|
|---|
| 88 |
|
|---|
| 89 | int GlobalRank() const;
|
|---|
| 90 | Index GlobalPos() const;
|
|---|
| 91 | Index GlobalProcs() const;
|
|---|
| 92 |
|
|---|
| 93 | void PostInit(Multigrid& sol, Multigrid& rhs)
|
|---|
| 94 | {
|
|---|
| 95 | settings.ComputeSettings(sol, rhs, comm_global);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | virtual void DebugPrintError(const Grid& sol, const char* information) {}
|
|---|
| 99 | virtual void DebugPrintErrorNorm(Grid& sol) {}
|
|---|
| 100 | virtual void DebugPrintGridStructure(Multigrid& multigrid) {}
|
|---|
| 101 |
|
|---|
| 102 | private:
|
|---|
| 103 | void InitCommMPI(const MPI_Comm& comm);
|
|---|
| 104 |
|
|---|
| 105 | void CreateOutputFiles(const Grid& grid, const std::stringstream& serial_data, const char* information,
|
|---|
| 106 | const Index& begin_global, const Index& end_global,
|
|---|
| 107 | const Index& begin_local, const Index& end_local);
|
|---|
| 108 |
|
|---|
| 109 | void CreateParallelOutputFile(const Grid& grid, MPI_Comm& comm,
|
|---|
| 110 | const int& output_count, const char* information,
|
|---|
| 111 | const Index& begin_global, const Index& end_global,
|
|---|
| 112 | const Index& begin_local, const Index& end_local);
|
|---|
| 113 |
|
|---|
| 114 | MPI_File CreateSerialOutputFile(const Grid& grid, MPI_Comm& comm,
|
|---|
| 115 | const int& output_count, const char* information,
|
|---|
| 116 | const Index& begin_global, const Index& end_global,
|
|---|
| 117 | const Index& begin_local, const Index& end_local);
|
|---|
| 118 |
|
|---|
| 119 | void FinalizeSerialOutputFile(MPI_File& file);
|
|---|
| 120 |
|
|---|
| 121 | std::string CreateOutputDirectory();
|
|---|
| 122 |
|
|---|
| 123 | MPI_Comm comm_global;
|
|---|
| 124 | bool win_created;
|
|---|
| 125 | MPI_Win win;
|
|---|
| 126 | MPI_Info info;
|
|---|
| 127 |
|
|---|
| 128 | std::vector< std::vector<vmg_float> > receive_buffer;
|
|---|
| 129 |
|
|---|
| 130 | protected:
|
|---|
| 131 | void Isend(Grid& grid, VMG::MPI::Datatype& type, const MPI_Comm& comm, const int& tag);
|
|---|
| 132 | void IsendAll(Grid& grid, std::vector<VMG::MPI::Datatype>& types, const MPI_Comm& comm, const int& tag_start);
|
|---|
| 133 | void Irecv(Grid& grid, VMG::MPI::Datatype& type, const MPI_Comm& comm, const int& tag);
|
|---|
| 134 | void IrecvAll(Grid& grid, std::vector<VMG::MPI::Datatype>& types, const MPI_Comm& comm, const int& tag_start);
|
|---|
| 135 | void IrecvAllBuffered(std::vector<VMG::MPI::Datatype>& types, const MPI_Comm& comm, const int& tag_start);
|
|---|
| 136 | void AddBufferAll(Grid& grid, std::vector<VMG::MPI::Datatype>& types);
|
|---|
| 137 |
|
|---|
| 138 | VMG::MPI::Settings settings;
|
|---|
| 139 | };
|
|---|
| 140 |
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | #endif /* COMM_MPI_HPP_ */
|
|---|