Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ OBJS_CELL=atom_pseudo.o\
mdcell.o\
cif_io.o\
ucell_io.o\
read_cube.o\
write_cube.o\
write_pao.o\
output_log.o\

OBJS_DEEPKS=lcao_deepks.o\
deepks_basic.o\
Expand Down Expand Up @@ -626,7 +630,6 @@ OBJS_IO=module_parameter/input_conv.o\
module_bessel/numerical_basis_output.o\
output.o\
module_output/print_info.o\
module_output/read_cube.o\
module_wf/read_wfc_pw.o\
module_wf/read_wf2rho_pw.o\
module_restart/restart.o\
Expand All @@ -645,17 +648,14 @@ OBJS_IO=module_parameter/input_conv.o\
module_wannier/to_w90_pw_setup.o\
module_wannier/fr_overlap.o\
module_unk/unk_overlap_pw.o\
module_output/write_pao.o\
module_wf/write_wfc_pw.o\
module_output/write_cube.o\
module_elf/write_elf.o\
module_dipole/write_dipole.o\
module_current/td_current_io.o\
module_current/td_current_io_comm.o\
td_efield_io.o\
td_vector_pot_io.o\
module_chgpot/write_libxc_r.o\
module_output/output_log.o\
module_hs/output_mat_sparse.o\
module_ctrl/ctrl_scf_lcao.o\
module_ctrl/ctrl_runner_lcao.o\
Expand Down Expand Up @@ -692,7 +692,7 @@ OBJS_IO=module_parameter/input_conv.o\
module_hs/cal_plpr.o\

OBJS_IO_LCAO=module_hs/cal_r_overlap_r.o\
module_output/write_orb_info.o\
write_orb_info.o\
module_dos/write_dos_lcao.o\
module_energy/write_proj_band_lcao.o\
module_energy/write_eig_occ.o\
Expand Down Expand Up @@ -797,7 +797,7 @@ OBJS_PARALLEL=parallel_common.o\
para_pw_world.o\
para_diag_world.o\
para_rgrid_world.o\
para_bgroup_world.o\
para_bdiff_ksame_world.o\
para_matrix_world.o\
para_mpi_func.o\
para_setup.o\
Expand Down
2 changes: 1 addition & 1 deletion source/source_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ add_library(
module_parallel/para_pw_world.cpp
module_parallel/para_diag_world.cpp
module_parallel/para_rgrid_world.cpp
module_parallel/para_bgroup_world.cpp
module_parallel/para_bdiff_ksame_world.cpp
module_parallel/para_matrix_world.cpp
module_parallel/para_mpi_func.cpp
module_parallel/para_setup.cpp
Expand Down
33 changes: 33 additions & 0 deletions source/source_base/module_parallel/para_bdiff_ksame_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "para_bdiff_ksame_world.h"

namespace Parallel
{

ParaBdiffKsameWorld::ParaBdiffKsameWorld()
: ParaWorld("bdiff_ksame"), my_bndgroup_(0), nbndgroup_(1)
{
}

#ifdef __MPI
ParaBdiffKsameWorld::ParaBdiffKsameWorld(const MPI_Comm& intra_comm, const MPI_Comm& inter_comm, int nbndgroup)
: ParaWorld("bdiff_ksame", intra_comm), inter_comm_(inter_comm), nbndgroup_(nbndgroup)
{
if (inter_comm != MPI_COMM_NULL)
{
MPI_Comm_rank(inter_comm, &my_bndgroup_);
}
}
#endif

void ParaBdiffKsameWorld::reduce_across_bdiff_ksame(double& value) const
{
#ifdef __MPI
if (inter_comm_ == MPI_COMM_NULL || nbndgroup_ <= 1)
{
return;
}
MPI_Allreduce(MPI_IN_PLACE, &value, 1, MPI_DOUBLE, MPI_SUM, inter_comm_);
#endif
}

} // namespace Parallel
87 changes: 87 additions & 0 deletions source/source_base/module_parallel/para_bdiff_ksame_world.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#ifndef PARA_BDIFF_KSAME_WORLD_H
#define PARA_BDIFF_KSAME_WORLD_H

#include "para_world.h"

namespace Parallel
{

/**
* @brief bdiff_ksame parallel domain: band-group communication topology
* inside one k-pool.
*
* Self-contained replacement for INT_BGROUP + BP_WORLD +
* GlobalV::MY_BNDGROUP/NPROC_IN_BNDGROUP/RANK_IN_BPGROUP.
*
* The domain has two communicators:
* - intra: INT_BGROUP (bsame_kdiff; same band group, different k/pw)
* - inter: BP_WORLD (bdiff_ksame; different band groups, same k)
*
* Tests only need this header.
*/
class ParaBdiffKsameWorld : public ParaWorld
{
public:
/**
* @brief Construct a serial domain (single band group).
*/
ParaBdiffKsameWorld();

#ifdef __MPI
/**
* @brief Construct a domain from intra and inter communicators.
*
* @param[in] intra_comm intra-group communicator (e.g. INT_BGROUP)
* @param[in] inter_comm inter-group communicator (e.g. BP_WORLD)
* @param[in] nbndgroup number of band groups
*/
ParaBdiffKsameWorld(const MPI_Comm& intra_comm, const MPI_Comm& inter_comm, int nbndgroup);
#endif

/// Band group index of this process.
int my_bndgroup() const { return my_bndgroup_; }

/// Number of band groups.
int nbndgroup() const { return nbndgroup_; }

/// Rank within the band group (alias for rank()).
int rank_in_bpgroup() const { return rank(); }

/// Number of processes in the band group (alias for size()).
int nproc_in_bndgroup() const { return size(); }

#ifdef __MPI
/// Inter-group communicator (BP_WORLD / bdiff_ksame equivalent).
MPI_Comm inter_comm() const { return inter_comm_; }
#endif

/**
* @brief Sum a scalar across the band groups of this k-pool.
*
* Band-parallel eigensolvers (bpcg) shard the band range across the
* BNDPAR band groups of a k-pool: every process only accumulates the
* partial sum over its own band window. This reduction combines those
* partial sums on the bdiff_ksame (BP_WORLD) communicator, which links
* the same rank position of every band group inside one k-pool, so each
* band window contributes exactly once.
*
* It must run BEFORE ParaKmeshWorld::reduce_across_pools so that the
* k-pool reduction receives one complete per-k-pool partial sum.
* No-op when there is only a single band group.
*
* @param[in,out] value local partial sum, overwritten with the
* k-pool-wide total
*/
void reduce_across_bdiff_ksame(double& value) const;

private:
int my_bndgroup_ = 0;
int nbndgroup_ = 1;
#ifdef __MPI
MPI_Comm inter_comm_ = MPI_COMM_NULL;
#endif
};

} // namespace Parallel

#endif // PARA_BDIFF_KSAME_WORLD_H
22 changes: 0 additions & 22 deletions source/source_base/module_parallel/para_bgroup_world.cpp

This file was deleted.

67 changes: 0 additions & 67 deletions source/source_base/module_parallel/para_bgroup_world.h

This file was deleted.

60 changes: 60 additions & 0 deletions source/source_base/module_parallel/para_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "para_tag.h"

#ifdef __MPI
#include "source_base/global_variable.h"
#include "source_base/parallel_comm.h"
#endif

Expand All @@ -19,4 +20,63 @@ ParaWorld make_pw_world()
#endif
}

// Reduce-only overload: no k-point distribution data.
ParaKmeshWorld make_kmesh_world()
{
#ifdef __MPI
int mpi_initialized = 0;
MPI_Initialized(&mpi_initialized);
// Any distributed layout (k pools or band groups) may need the
// world-wide max/min reductions, so build the MPI domain whenever
// more than one process is running. The sum reduction no-ops for
// kpar <= 1 on its own.
if (mpi_initialized && GlobalV::NPROC > 1)
{
// Build from globals but skip distribute_kpoints (nkstot=0).
return ParaKmeshWorld(MPI_COMM_WORLD, GlobalV::KPAR, GlobalV::MY_POOL, 0, 1);
}
#endif
return ParaKmeshWorld();
}

// Temporary bridge: construct a kmesh-domain ParaKmeshWorld from the old
// globals. Delete this file once ParaCollection is wired into driver init.
ParaKmeshWorld make_kmesh_world(int nkstot, int nspin)
{
#ifdef __MPI
// Fall back to a serial single-pool domain when MPI is not initialized
// (e.g. unit tests linked against the MPI-compiled base library) or when
// there is only one k-pool, so that no MPI call is made on an unset
// communicator.
int mpi_initialized = 0;
MPI_Initialized(&mpi_initialized);
if (mpi_initialized && GlobalV::KPAR > 1)
{
return ParaKmeshWorld(MPI_COMM_WORLD, GlobalV::KPAR, GlobalV::MY_POOL,
nkstot, nspin);
}
#endif
return ParaKmeshWorld(nkstot, nspin);
}

// Temporary bridge: construct a bdiff_ksame-domain ParaBdiffKsameWorld from
// the old globals. Delete this file once ParaCollection is wired into driver init.
ParaBdiffKsameWorld make_bdiff_ksame_world()
{
#ifdef __MPI
int mpi_initialized = 0;
MPI_Initialized(&mpi_initialized);
// NPROC_IN_BNDGROUP stays 0 until divide_pools has run, which also
// guards unit tests that link the MPI base library without a layout.
if (mpi_initialized && INT_BGROUP != MPI_COMM_NULL && BP_WORLD != MPI_COMM_NULL
&& GlobalV::NPROC_IN_BNDGROUP > 1)
{
int nbndgroup = 1;
MPI_Comm_size(BP_WORLD, &nbndgroup);
return ParaBdiffKsameWorld(INT_BGROUP, BP_WORLD, nbndgroup);
}
#endif
return ParaBdiffKsameWorld();
}

} // namespace Parallel
Loading
Loading