mpi_tree.hpp 2.9 KB

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