66 z_min = std::numeric_limits<int>::max();
67 z_max = std::numeric_limits<int>::min();
82 serialize(s__, zcol__.
x);
83 serialize(s__, zcol__.
y);
84 serialize(s__, zcol__.
z_min);
85 serialize(s__, zcol__.
z_max);
86 serialize(s__, zcol__.
z);
92 deserialize(s__, zcol__.
x);
93 deserialize(s__, zcol__.
y);
94 deserialize(s__, zcol__.
z_min);
95 deserialize(s__, zcol__.
z_max);
96 deserialize(s__, zcol__.
z);
100inline void serialize(
serializer& s__, std::vector<z_column_descriptor>
const& zcol__)
102 serialize(s__, zcol__.size());
103 for (
auto& e: zcol__) {
109inline void deserialize(
serializer& s__, std::vector<z_column_descriptor>& zcol__)
112 deserialize(s__, sz);
114 for (
size_t i = 0; i < sz; i++) {
115 deserialize(s__, zcol__[i]);
123Gvec send_recv(
mpi::Communicator const& comm__, Gvec
const& gv_src__,
int source__,
int dest__);
279 Gvec& operator=(
Gvec const& src__) =
delete;
291 bool reduce_gvec__,
double sym_tol__ = 1e-6)
311 double sym_tol__ = 1e-6)
330 bool reduce_gvec__,
double sym_tol__ = 1e-6)
345 ,
comm_{gvec_base__.comm()}
357 ,
comm_{mpi::Communicator::self()}
380 int xmin{0}, xmax{0};
381 int ymin{0}, ymax{0};
382 for (
int i = 0; i < ngv_loc__; i++) {
383 xmin = std::min(xmin, G(0, i));
384 xmax = std::max(xmax, G(0, i));
385 ymin = std::min(ymin, G(1, i));
386 ymax = std::max(ymax, G(1, i));
395 for (
int ig = 0; ig < ngv_loc__; ig++) {
396 zcol(G(0, ig), G(1, ig))++;
397 for (
int x : {0, 1, 2}) {
398 gvec_(x, ig) = G(x, ig);
403 for (
size_t i = 0; i < zcol.size(); i++) {
436 inline auto const& vk()
const
463 inline auto const unit_cell_lattice_vectors()
const
465 double const twopi = 6.2831853071795864769;
473 double const twopi_pow3 = 248.050213442398561403810520537;
486 RTE_ASSERT(rank__ < comm().size());
493 RTE_ASSERT(rank__ < comm().size());
500 RTE_ASSERT(rank__ < comm().size());
514 RTE_ASSERT(rank__ < comm().size());
528 return (comm().rank() == 0) ? 1 : 0;
538 template <index_domain_t
idx_t>
555 template <index_domain_t
idx_t>
565 return this->gvec<idx_t>(ig__) +
vk_;
572 template <index_domain_t
idx_t>
582 auto G = this->gvec<idx_t>(ig__);
590 template <index_domain_t
idx_t>
600 auto Gk = this->gvec<idx_t>(ig__) +
vk_;
628 for (
int i = 0; i < this->
num_shells(); i++) {
635 template <index_domain_t
idx_t>
653 auto v = g1__ - g2__;
655 RTE_ASSERT(idx >= 0);
677 inline bool reduced()
const
682 inline bool bare()
const
704 inline int gvec_base_mapping(
int igloc_base__)
const
710 inline int num_gvec_shells_local()
const
715 inline double gvec_shell_len_local(
int idx__)
const
720 inline int gvec_shell_idx_local(
int igloc__)
const
735 int ngv = this->
count();
736 this->comm().
bcast(&ngv, 1, rank__);
738 if (this->comm().rank() == rank__) {
739 RTE_ASSERT(ngv == this->
count());
740 copy(this->gvec_, result);
742 this->comm().
bcast(&result(0, 0), 3 * ngv, rank__);
746 inline auto& gvec_tp()
751 inline auto const& gvec_tp()
const
756 inline auto& gkvec_tp()
761 inline auto const& gkvec_tp()
const
802 void build_fft_distr();
864 template <
typename T>
865 void gather_pw_fft(std::complex<T>
const* f_pw_local__, std::complex<T>* f_pw_fft__)
const
874 template <
typename T>
875 void gather_pw_global(std::complex<T>
const* f_pw_fft__, std::complex<T>* f_pw_global__)
const
877 for (
int ig = 0; ig <
gvec().
count(); ig++) {
880 f_pw_global__[
gvec().
offset() + ig] = f_pw_fft__[ig1];
886 void scatter_pw_global(std::complex<T>
const* f_pw_global__, std::complex<T>* f_pw_fft__)
const
892 f_pw_fft__[
gvec_fft_slab_.offsets[i] + ig] = f_pw_global__[offset + ig];
900 for (
int ig = 0; ig < this->
count(); ig++) {
903 for (
int x : {0, 1, 2}) {
945 inline void print_gvec(std::ostream& out__)
const
948 pout <<
"rank: " << gvec_.comm().
rank() << std::endl;
949 pout <<
"-- list of G-vectors in the remapped distribution --" << std::endl;
954 pout <<
"igloc=" << igloc <<
" igsh=" << igsh <<
" G=" << G[0] <<
" " << G[1] <<
" " << G[2] << std::endl;
956 pout <<
"-- reverse list --" << std::endl;
958 pout <<
"G=" << e.first[0] <<
" " << e.first[1] <<
" " << e.first[2] <<
", igloc=" << e.second << std::endl;
960 out__ << pout.flush(0);
991 template <
typename T>
992 auto remap_forward(T* data__)
const
994 PROFILE(
"fft::Gvec_shells::remap_forward");
996 std::vector<T> send_buf(gvec_.
count());
997 std::vector<int> counts(
comm_.
size(), 0);
998 for (
int igloc = 0; igloc < gvec_.
count(); igloc++) {
999 int ig = gvec_.
offset() + igloc;
1000 int igsh = gvec_.
shell(ig);
1002 send_buf[
a2a_send_.offsets[r] + counts[r]] = data__[igloc];
1014 template <
typename T>
1015 void remap_backward(std::vector<T> buf__, T* data__)
const
1017 PROFILE(
"fft::Gvec_shells::remap_backward");
1019 std::vector<T> recv_buf(gvec_.
count());
1024 std::vector<int> counts(
comm_.
size(), 0);
1025 for (
int igloc = 0; igloc < gvec_.
count(); igloc++) {
1026 int ig = gvec_.
offset() + igloc;
1027 int igsh = gvec_.
shell(ig);
1029 data__[igloc] = recv_buf[
a2a_send_.offsets[r] + counts[r]];
1034 inline Gvec
const& gvec()
const
1041inline std::shared_ptr<Gvec>
1045 return std::make_shared<Gvec>(
r3::vector<double>({0, 0, 0}), M, gk_cutoff__, comm__,
false);
1048inline std::shared_ptr<Gvec>
1050 mpi::Communicator const& comm__ = mpi::Communicator::self(),
bool gamma__ =
false)
1052 return std::make_shared<Gvec>(vk__, reciprocal_lattice_vectors__, gk_cutoff__, comm__, gamma__);
1055inline void print(std::ostream& out__, Gvec
const& gvec__)
1057 std::map<int, std::vector<int>> gsh_map;
1058 for (
int i = 0; i < gvec__.num_gvec(); i++) {
1059 int igsh = gvec__.shell(i);
1060 if (gsh_map.count(igsh) == 0) {
1061 gsh_map[igsh] = std::vector<int>();
1063 gsh_map[igsh].push_back(i);
1066 out__ <<
"num_gvec : " << gvec__.num_gvec() << std::endl;
1067 out__ <<
"num_gvec_shells : " << gvec__.num_shells() << std::endl;
1069 for (
int igsh = 0; igsh < gvec__.num_shells(); igsh++) {
1070 auto len = gvec__.shell_len(igsh);
1071 out__ <<
"shell : " << igsh <<
", length : " << len << std::endl;
1072 for (
auto ig : gsh_map[igsh]) {
1075 out__ <<
" ig : " << ig <<
", G = " << G <<
", length diff : " << std::abs(Gc.length() - len) << std::endl;
Helper class to create FFT grids of given sizes and compute indices in space- and frequency domains.
Stores information about G-vector partitioning between MPI ranks for the FFT transformation.
mpi::Communicator const & comm_fft() const
Return FFT communicator.
int count() const
Local number of G-vectors for FFT-friendly distribution for this rank.
int zcol_count() const
Return local number of z-columns.
auto const & gvec_slab() const
Represents a "fat" slab of G-vectors in the FFT-friendly distribution.
mpi::block_data_descriptor gvec_fft_slab_
Distribution of G-vectors inside FFT-friendly "fat" slab.
int count(int rank__) const
Local number of G-vectors in the FFT distribution for a given rank.
mpi::Communicator const & comm_ortho_fft() const
Return a communicator that is orthogonal to the FFT communicator.
mpi::Communicator const & comm_ortho_fft_
Communicator which is orthogonal to FFT communicator.
sddk::mdarray< int, 2 > rank_map_
Mapping of MPI ranks used to split G-vectors to a 2D grid.
sddk::mdarray< double, 2 > gkvec_cart_array_
Cartesian coordinaes of a local set of G+k-vectors.
mpi::Communicator const & comm_fft_
Communicator for the FFT.
void update_gkvec_cart()
Update Cartesian coordinates after a change in lattice vectors.
sddk::mdarray< int, 2 > gvec_array_
Lattice coordinates of a local set of G-vectors.
auto const & gvec_array() const
Return the full array of the local G-vector Cartesian coodinates.
auto gkvec_cart(int igloc__) const
Return the Cartesian coordinates of the local G-vector.
mpi::block_data_descriptor gvec_distr_fft_
Distribution of G-vectors for FFT.
Gvec const & gvec_
Reference to the G-vector instance.
Gvec const & gvec() const
Return the original (not reshuffled) G-vector class.
void pile_gvec()
Stack together the G-vector slabs to make a larger ("fat") slab for a FFT driver.
int num_zcol_local_
Local number of z-columns.
Helper class to manage G-vector shells and redistribute G-vectors for symmetrization.
sddk::mdarray< int, 1 > gvec_shell_remapped_
Mapping between index of local G-vector and global index of G-vector shell.
int gvec_count_remapped() const
Local number of G-vectors in the remapped distribution with complete shells on each rank.
std::map< r3::vector< int >, int > idx_gvec_
A mapping between G-vector and it's local index in the new distribution.
mpi::Communicator const & comm_
Alias for the G-vector communicator.
r3::vector< int > gvec_remapped(int igloc__) const
G-vector by local index (in the remapped set).
mpi::block_data_descriptor a2a_recv_
Receiving counts and offsets.
int gvec_shell_remapped(int igloc__) const
Index of the G-vector shell by the local G-vector index (in the remapped set).
splindex_block_cyclic spl_num_gsh_
Split global index of G-shells between MPI ranks.
mpi::block_data_descriptor a2a_send_
Sending counts and offsets.
sddk::mdarray< int, 2 > gvec_remapped_
List of G-vectors in the remapped storage.
int index_by_gvec(r3::vector< int > G__) const
Return local index of the G-vector in the remapped set.
A set of G-vectors for FFTs and G+k basis functions.
int offset_
Offset in the global index for the local part of G-vectors.
int gvec_count(int rank__) const
Number of G-vectors for a fine-grained distribution.
int num_zcol() const
Return global number of z-columns.
sddk::mdarray< double, 1 > gvec_shell_len_
Radii (or lengths) of G-vector shells in a.u.^-1.
mpi::block_data_descriptor zcol_distr_
Fine-grained distribution of z-columns.
sddk::mdarray< uint32_t, 1 > gvec_full_index_
Mapping between G-vector index [0:num_gvec_) and a full index.
double gvec_len(int ig__) const
Return length of the G-vector.
sddk::mdarray< double, 2 > gvec_cart_
Cartiesian coordinaes of a local set of G-vectors.
Gvec(r3::matrix< double > M__, double Gmax__, bool reduce_gvec__, double sym_tol__=1e-6)
Constructor for G-vectors with mpi_comm_self()
int num_gvec() const
Return the total number of G-vectors within the cutoff.
auto gvec_local(int rank__) const
Return local list of G-vectors for a given rank.
int num_zcol_local() const
Return local number of z-columns.
Gvec(double Gmax__, Gvec const &gvec_base__)
Constructor for G-vector distribution based on a previous set.
std::vector< double > gvec_shell_len_local_
Radii of G-vector shells in the local index counting [0, num_gvec_shells_local)
int offset() const
Offset (in the global index) of G-vectors for a fine-grained distribution for a current MPI rank.
sddk::mdarray< int, 2 > gvec_
Lattice coordinates of a local set of G-vectors.
std::vector< z_column_descriptor > z_columns_
Global list of non-zero z-columns.
sddk::mdarray< int, 1 > gvec_shell_
Index of the shell to which the given G-vector belongs.
int skip_g0() const
Local starting index of G-vectors if G=0 is not counted.
Gvec(r3::vector< double > vk__, r3::matrix< double > M__, double Gmax__, mpi::Communicator const &comm__, bool reduce_gvec__, double sym_tol__=1e-6)
Constructor for G+k vectors.
sddk::mdarray< int, 1 > gvec_base_mapping_
Mapping between current and base G-vector sets.
void distribute_z_columns()
Distribute z-columns between MPI ranks.
sddk::mdarray< double, 1 > gvec_len_
Length of the local fraction of G-vectors.
r3::vector< double > vk_
k-vector of G+k.
int zcol_offset(int rank__) const
Offset in the global index of z-columns for a given rank.
int count() const
Number of G-vectors for a fine-grained distribution for the current MPI rank.
void find_gvec_shells()
Find a list of G-vector shells.
int gvec_offset(int rank__) const
Offset (in the global index) of G-vectors for a fine-grained distribution.
Gvec(r3::matrix< double > M__, double Gmax__, fft::Grid const &fft_grid__, mpi::Communicator const &comm__, bool reduce_gvec__, double sym_tol__=1e-6)
Constructor for G-vectors.
bool bare_gvec_
True if this a list of G-vectors without k-point shift.
int count_
Local number of G-vectors.
int num_shells() const
Return number of G-vector shells.
double sym_tol_
Symmetry tolerance of the real-space lattice.
void init_gvec_cart_local()
Initialize Cartesian coordinates of the local fraction of G-vectors.
int num_gvec_shells_local_
Local number of G-vector shells for the local number of G-vectors.
auto const & lattice_vectors(r3::matrix< double > lattice_vectors__)
Set the new reciprocal lattice vectors.
Gvec(r3::matrix< double > M__, double Gmax__, mpi::Communicator const &comm__, bool reduce_gvec__, double sym_tol__=1e-6)
Constructor for G-vectors.
int zcol_count(int rank__) const
Number of z-columns for a fine-grained distribution.
mpi::block_data_descriptor gvec_distr_
Fine-grained distribution of G-vectors.
r3::vector< int > gvec(int ig__) const
Return G vector in fractional coordinates.
sddk::mdarray< double, 2 > gkvec_cart_
Cartesian coordinaes of a local set of G+k-vectors.
std::vector< double > shells_len() const
Get lengths of all G-vector shells.
bool reduce_gvec_
Indicates that G-vectors are reduced by inversion symmetry.
int shell(int ig__) const
Return index of the G-vector shell by the G-vector index.
int index_by_gvec(r3::vector< int > const &G__) const
Return a global G-vector index in the range [0, num_gvec) by the G-vector.
int num_zcol_local_
Local number of z-columns.
int num_gvec_shells_
Number of G-vector shells (groups of G-vectors with the same length).
Gvec const * gvec_base_
Set of G-vectors on which the current G-vector distribution can be based.
mpi::Communicator comm_
Total communicator which is used to distribute G or G+k vectors.
Gvec & operator=(Gvec &&src__)=default
Move assignment operator.
double Gmax_
Cutoff for |G+k| vectors.
double omega() const
Return the volume of the real space unit cell that corresponds to the reciprocal lattice of G-vectors...
Gvec(r3::vector< double > vk__, r3::matrix< double > M__, int ngv_loc__, int const *gv__, mpi::Communicator const &comm__, bool reduce_gvec__)
Construct with the defined order of G-vectors.
r3::vector< double > gvec_cart(int ig__) const
Return G vector in Cartesian coordinates.
double shell_len(int igs__) const
Return length of the G-vector shell.
sddk::mdarray< double, 2 > gkvec_
Lattice coordinates of a local set of G+k-vectors.
Gvec(Gvec &&src__)=default
Move constructor.
auto const & gvec_local() const
Return local list of G-vectors.
r3::vector< int > gvec_by_full_index(uint32_t idx__) const
Return corresponding G-vector for an index in the range [0, num_gvec).
std::vector< int > gvec_shell_idx_local_
Mapping between local index of G-vector and local G-shell index.
void init(fft::Grid const &fft_grid)
Initialize everything.
auto const & lattice_vectors() const
Retrn a const reference to the reciprocal lattice vectors.
r3::vector< double > gkvec_cart(int ig__) const
Return G+k vector in fractional coordinates.
r3::matrix< double > lattice_vectors_
Reciprocal lattice vectors.
r3::vector< double > gkvec(int ig__) const
Return G+k vector in fractional coordinates.
Gvec(mpi::Communicator const &comm__)
Constructor for empty set of G-vectors.
int num_gvec_
Total number of G-vectors.
void init_gvec_local()
Initialize lattice coordinates of the local fraction of G-vectors.
void find_z_columns(double Gmax__, fft::Grid const &fft_box__)
Find z-columns of G-vectors inside a sphere with Gmax radius.
MPI communicator wrapper.
void bcast(T *buffer__, int count__, int root__) const
Perform buffer broadcast.
void allgather(T *buffer__, int const *recvcounts__, int const *displs__) const
In-place MPI_Allgatherv.
int size() const
Size of the communicator (number of ranks).
void allreduce(T *buffer__, int count__) const
Perform the in-place (the output buffer is used as the input buffer) all-to-all reduction.
int rank() const
Rank of MPI process inside communicator.
Parallel standard output.
Index descriptor of mdarray.
Serialize and deserialize objects.
splindex< Index_t >::location_t location(typename Index_t::global idx__) const
Return "local index, rank" pair for a global index.
Contains declaration and implementation of sddk::FFT3D_grid class.
Memory management functions and classes.
std::shared_ptr< Gvec > gkvec_factory(double gk_cutoff__, mpi::Communicator const &comm__)
This is only for debug purpose.
void serialize(serializer &s__, std::vector< z_column_descriptor > const &zcol__)
Serialize a vector of z-column descriptors.
auto get_min_grid(double cutoff__, r3::matrix< double > M__)
Get the minimum grid that circumscribes the cutoff sphere.
void deserialize(serializer &s__, std::vector< z_column_descriptor > &zcol__)
Deserialize a vector of z-column descriptors.
auto transpose(matrix< T > src)
Return transpose of the matrix.
auto inverse(matrix< int > src)
Return inverse of the integer matrix.
Namespace of the SIRIUS library.
Contains implementation of the parallel standard output.
Simple classes and functions to work with vectors and matrices of the R^3 space.
Eror and warning handling during run-time execution.
Serializer for simple data structures.
Contains definition of sddk::splindex_base and specializations of sddk::splindex class.
Descriptor of the z-column (x,y fixed, z varying) of the G-vectors.
z_column_descriptor(int x__, int y__, std::vector< int > z__)
Constructor.
std::vector< int > z
List of the Z-coordinates of the column.
z_column_descriptor()
Default constructor.
int z_min
Minimum z-coordinate.
int z_max
Maximum z-coordinate.
int y
Y-coordinate (can be negative and positive).
int x
X-coordinate (can be negative and positive).