parUtils.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. @file parUtils.h
  3. @brief A set of parallel utilities.
  4. @author Rahul S. Sampath, rahul.sampath@gmail.com
  5. @author Hari Sundar, hsundar@gmail.com
  6. @author Shravan Veerapaneni, shravan@seas.upenn.edu
  7. @author Santi Swaroop Adavani, santis@gmail.com
  8. @author Dhairya Malhotra, dhairya.malhotra@gmail.com
  9. */
  10. #ifndef __PVFMM_PAR_UTILS_H_
  11. #define __PVFMM_PAR_UTILS_H_
  12. #include "mpi.h"
  13. #include <vector>
  14. #include <vector.hpp>
  15. /**
  16. @namespace par
  17. @author Rahul Sampath
  18. @author Hari Sundar
  19. @brief Collection of Generic Parallel Functions: Sorting, Partitioning, Searching,...
  20. */
  21. namespace pvfmm{
  22. namespace par{
  23. /**
  24. @author Rahul S. Sampath
  25. */
  26. template <typename T>
  27. int Mpi_Alltoallv_sparse(T* sendbuf, int* sendcnts, int* sdispls,
  28. T* recvbuf, int* recvcnts, int* rdispls, const MPI_Comm& comm);
  29. /**
  30. @author Rahul S. Sampath
  31. */
  32. template <typename T>
  33. int Mpi_Alltoallv_dense(T* sendbuf, int* sendcnts, int* sdispls,
  34. T* recvbuf, int* recvcnts, int* rdispls, const MPI_Comm& comm);
  35. template<typename T>
  36. unsigned int defaultWeight(const T *a);
  37. /**
  38. @brief A parallel weighted partitioning function. In our implementation, we
  39. do not pose any restriction on the input or the number of processors. This
  40. function can be used with an odd number of processors as well. Some
  41. processors can pass an empty vector as input. The relative ordering of the
  42. elements is preserved.
  43. @author Hari Sundar
  44. @author Rahul Sampath
  45. @param[in,out] vec the input vector
  46. @param[in] getWeight function pointer to compute the weight of each
  47. element. If you pass NULL, then every element will get a weight equal to 1.
  48. @param[in] comm the communicator
  49. */
  50. template<typename T>
  51. int partitionW(Vector<T>& vec,
  52. unsigned int (*getWeight)(const T *), const MPI_Comm& comm);
  53. template<typename T>
  54. int partitionW(std::vector<T>& vec,
  55. unsigned int (*getWeight)(const T *), const MPI_Comm& comm);
  56. /**
  57. @brief A parallel hyper quick sort implementation.
  58. @author Dhairya Malhotra
  59. @param[in] in the input vector
  60. @param[out] out the output vector
  61. @param[in] comm the communicator
  62. */
  63. template<typename T>
  64. int HyperQuickSort(const Vector<T>& in, Vector<T> & out, const MPI_Comm& comm);
  65. template<typename T>
  66. int HyperQuickSort(const std::vector<T>& in, std::vector<T> & out, const MPI_Comm& comm);
  67. /**
  68. @brief Returns the scatter mapping which will sort the keys.
  69. @author Dhairya Malhotra
  70. @param[in] key the input keys to sort
  71. @param[out] scatter_index the output index vector for the scatter mapping
  72. @param[in] comm the MPI communicator
  73. @param[in] split_key for partitioning of sorted array, optional
  74. */
  75. template<typename T>
  76. int SortScatterIndex(const Vector<T>& key, Vector<size_t>& scatter_index,
  77. const MPI_Comm& comm, const T* split_key=NULL);
  78. /**
  79. @brief Forward scatter data based on scatter index.
  80. @author Dhairya Malhotra
  81. @param[in,out] data the data to scatter
  82. @param[in] scatter_index the index vector for the scatter mapping
  83. @param[in] comm the MPI communicator
  84. */
  85. template<typename T>
  86. int ScatterForward(Vector<T>& data, const Vector<size_t>& scatter_index,
  87. const MPI_Comm& comm);
  88. /**
  89. @brief Reverse scatter data based on scatter index.
  90. @author Dhairya Malhotra
  91. @param[in,out] data the data to scatter
  92. @param[in] scatter_index the index vector for the scatter mapping
  93. @param[in] comm the MPI communicator
  94. @param[in] loc_size the local array size after scatter, optional
  95. */
  96. template<typename T>
  97. int ScatterReverse(Vector<T>& data, const Vector<size_t>& scatter_index,
  98. const MPI_Comm& comm, size_t loc_size=0);
  99. }//end namespace
  100. }//end namespace
  101. #include "parUtils.txx"
  102. #endif //__PVFMM_PAR_UTILS_H_