mpi_tree.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * \file mpi_tree.hpp
  3. * \author Dhairya Malhotra, dhairya.malhotra@gmail.com
  4. * \date 12-11-2010
  5. * \brief This file contains the definition of a base class for a distributed
  6. * MPI tree.
  7. */
  8. #include <mpi.h>
  9. #include <vector>
  10. #include <string>
  11. #include <pvfmm_common.hpp>
  12. #include <mortonid.hpp>
  13. #include <tree.hpp>
  14. #ifndef _PVFMM_MPI_TREE_HPP_
  15. #define _PVFMM_MPI_TREE_HPP_
  16. namespace pvfmm{
  17. enum BoundaryType{
  18. FreeSpace,
  19. Periodic
  20. };
  21. /**
  22. * \brief Base class for distributed tree.
  23. */
  24. template <class TreeNode>
  25. class MPI_Tree: public Tree<TreeNode>{
  26. public:
  27. typedef TreeNode Node_t;
  28. typedef typename Node_t::Real_t Real_t;
  29. /**
  30. * \brief Constructor.
  31. */
  32. MPI_Tree(MPI_Comm c): Tree<Node_t>() {comm=c;}
  33. /**
  34. * \brief Virtual destructor.
  35. */
  36. virtual ~MPI_Tree() {}
  37. /**
  38. * \brief Initialize the distributed MPI tree.
  39. */
  40. virtual void Initialize(typename Node_t::NodeData* data_);
  41. /**
  42. * \brief Initialize the distributed MPI tree.
  43. */
  44. //void InitData(typename Node_t::NodeData& d1);
  45. /**
  46. * \brief Find the prticular node. If subdiv is true then subdivide
  47. * (non-ghost) nodes to create this node.
  48. */
  49. TreeNode* FindNode(MortonId& key, bool subdiv, TreeNode* start=NULL);
  50. /**
  51. * \brief Adaptive coarsening of distributed tree.
  52. */
  53. virtual void CoarsenTree();
  54. /**
  55. * \brief Adaptive refinement of distributed tree.
  56. */
  57. virtual void RefineTree();
  58. /**
  59. * \brief Redistribute the tree among the processes.
  60. */
  61. void RedistNodes(MortonId* loc_min=NULL);
  62. /**
  63. * \brief Performs global 2:1 balancing of the tree.
  64. */
  65. void Balance21(BoundaryType bndry=FreeSpace);
  66. /**
  67. * \brief Performs 2:1 balancing of the tree.
  68. */
  69. void Balance21_local(BoundaryType bndry=FreeSpace);
  70. /**
  71. * \brief Determines and sets colleagues for each node in the tree.
  72. * Two nodes are colleagues if they are at the same depth in the tree and
  73. * share either a face, edge or a vertex.
  74. */
  75. void SetColleagues(BoundaryType bndry=FreeSpace, Node_t* node=NULL) ;
  76. /**
  77. * \brief Checks if everything is okay with the distributed tree. Only needed
  78. * for debugging purposes.
  79. */
  80. bool CheckTree();
  81. /**
  82. * \brief Construct the LET by exchanging ghost octants.
  83. */
  84. void ConstructLET(BoundaryType bndry=FreeSpace);
  85. template <class VTKReal>
  86. struct VTUData_t{
  87. typedef VTKReal VTKReal_t;
  88. // Point data
  89. std::vector<VTKReal_t> coord;
  90. std::vector<std::vector<VTKReal_t> > value;
  91. std::vector<std::string> name;
  92. // Cell data
  93. std::vector<int32_t> connect;
  94. std::vector<int32_t> offset;
  95. std::vector<uint8_t> types;
  96. };
  97. /**
  98. * \brief Write to a <fname>.vtu file.
  99. */
  100. void Write2File(const char* fname, int lod=-1);
  101. /**
  102. * \brief Returns a pointer to the comm object.
  103. */
  104. const MPI_Comm* Comm() {return &comm;}
  105. protected:
  106. /**
  107. * \brief Returns a vector with the minimum Morton Id of the regions
  108. * controlled by each processor.
  109. */
  110. const std::vector<MortonId>& GetMins();
  111. private:
  112. void ConstructLET_Hypercube(BoundaryType bndry=FreeSpace);
  113. void ConstructLET_Sparse(BoundaryType bndry=FreeSpace);
  114. MPI_Comm comm;
  115. std::vector<MortonId> mins;
  116. };
  117. }//end namespace
  118. #include <mpi_tree.txx>
  119. #endif //_PVFMM_MPI_TREE_HPP_