Skip to content

Commit ec6f175

Browse files
author
abacus_fixer
committed
refactor(parallel): rename bgroup domain to bdiff_ksame in module_parallel
The bgroup name is misleading: it does not say which two axes the domain connects. Rename the new module_parallel band-group domain after its tag bdiff_ksame (different band groups, same k), matching ParaTag: para_bgroup_world.{h,cpp} -> para_bdiff_ksame_world.{h,cpp} ParaBgroupWorld -> ParaBdiffKsameWorld make_bgroup_world() -> make_bdiff_ksame_world() reduce_across_bgroups() -> reduce_across_bdiff_ksame() Legacy globals INT_BGROUP / BP_WORLD and the GlobalV::MY_BNDGROUP-style member names are the old parallel-layer API and are left unchanged; the new domain is only a self-contained bridge over them.
1 parent 86499a2 commit ec6f175

12 files changed

Lines changed: 55 additions & 53 deletions

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ OBJS_PARALLEL=parallel_common.o\
797797
para_pw_world.o\
798798
para_diag_world.o\
799799
para_rgrid_world.o\
800-
para_bgroup_world.o\
800+
para_bdiff_ksame_world.o\
801801
para_matrix_world.o\
802802
para_mpi_func.o\
803803
para_setup.o\

source/source_base/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ add_library(
7979
module_parallel/para_pw_world.cpp
8080
module_parallel/para_diag_world.cpp
8181
module_parallel/para_rgrid_world.cpp
82-
module_parallel/para_bgroup_world.cpp
82+
module_parallel/para_bdiff_ksame_world.cpp
8383
module_parallel/para_matrix_world.cpp
8484
module_parallel/para_mpi_func.cpp
8585
module_parallel/para_setup.cpp

source/source_base/module_parallel/para_bgroup_world.cpp renamed to source/source_base/module_parallel/para_bdiff_ksame_world.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#include "para_bgroup_world.h"
1+
#include "para_bdiff_ksame_world.h"
22

33
namespace Parallel
44
{
55

6-
ParaBgroupWorld::ParaBgroupWorld()
6+
ParaBdiffKsameWorld::ParaBdiffKsameWorld()
77
: ParaWorld("bdiff_ksame"), my_bndgroup_(0), nbndgroup_(1)
88
{
99
}
1010

1111
#ifdef __MPI
12-
ParaBgroupWorld::ParaBgroupWorld(const MPI_Comm& intra_comm, const MPI_Comm& inter_comm, int nbndgroup)
12+
ParaBdiffKsameWorld::ParaBdiffKsameWorld(const MPI_Comm& intra_comm, const MPI_Comm& inter_comm, int nbndgroup)
1313
: ParaWorld("bdiff_ksame", intra_comm), inter_comm_(inter_comm), nbndgroup_(nbndgroup)
1414
{
1515
if (inter_comm != MPI_COMM_NULL)
@@ -19,7 +19,7 @@ ParaBgroupWorld::ParaBgroupWorld(const MPI_Comm& intra_comm, const MPI_Comm& int
1919
}
2020
#endif
2121

22-
void ParaBgroupWorld::reduce_across_bgroups(double& value) const
22+
void ParaBdiffKsameWorld::reduce_across_bdiff_ksame(double& value) const
2323
{
2424
#ifdef __MPI
2525
if (inter_comm_ == MPI_COMM_NULL || nbndgroup_ <= 1)

source/source_base/module_parallel/para_bgroup_world.h renamed to source/source_base/module_parallel/para_bdiff_ksame_world.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
#ifndef PARA_BGROUP_WORLD_H
2-
#define PARA_BGROUP_WORLD_H
1+
#ifndef PARA_BDIFF_KSAME_WORLD_H
2+
#define PARA_BDIFF_KSAME_WORLD_H
33

44
#include "para_world.h"
55

66
namespace Parallel
77
{
88

99
/**
10-
* @brief bgroup parallel domain: band group communication topology.
10+
* @brief bdiff_ksame parallel domain: band-group communication topology
11+
* inside one k-pool.
1112
*
1213
* Self-contained replacement for INT_BGROUP + BP_WORLD +
1314
* GlobalV::MY_BNDGROUP/NPROC_IN_BNDGROUP/RANK_IN_BPGROUP.
1415
*
15-
* The band group domain has two communicators:
16-
* - intra: INT_BGROUP (same band group, different k/pw)
17-
* - inter: BP_WORLD (different band groups, same k)
16+
* The domain has two communicators:
17+
* - intra: INT_BGROUP (bsame_kdiff; same band group, different k/pw)
18+
* - inter: BP_WORLD (bdiff_ksame; different band groups, same k)
1819
*
1920
* Tests only need this header.
2021
*/
21-
class ParaBgroupWorld : public ParaWorld
22+
class ParaBdiffKsameWorld : public ParaWorld
2223
{
2324
public:
2425
/**
25-
* @brief Construct a serial bgroup domain (single band group).
26+
* @brief Construct a serial domain (single band group).
2627
*/
27-
ParaBgroupWorld();
28+
ParaBdiffKsameWorld();
2829

2930
#ifdef __MPI
3031
/**
31-
* @brief Construct a bgroup domain from intra and inter communicators.
32+
* @brief Construct a domain from intra and inter communicators.
3233
*
3334
* @param[in] intra_comm intra-group communicator (e.g. INT_BGROUP)
3435
* @param[in] inter_comm inter-group communicator (e.g. BP_WORLD)
3536
* @param[in] nbndgroup number of band groups
3637
*/
37-
ParaBgroupWorld(const MPI_Comm& intra_comm, const MPI_Comm& inter_comm, int nbndgroup);
38+
ParaBdiffKsameWorld(const MPI_Comm& intra_comm, const MPI_Comm& inter_comm, int nbndgroup);
3839
#endif
3940

4041
/// Band group index of this process.
@@ -50,7 +51,7 @@ class ParaBgroupWorld : public ParaWorld
5051
int nproc_in_bndgroup() const { return size(); }
5152

5253
#ifdef __MPI
53-
/// Inter-group communicator (BP_WORLD equivalent).
54+
/// Inter-group communicator (BP_WORLD / bdiff_ksame equivalent).
5455
MPI_Comm inter_comm() const { return inter_comm_; }
5556
#endif
5657

@@ -60,9 +61,9 @@ class ParaBgroupWorld : public ParaWorld
6061
* Band-parallel eigensolvers (bpcg) shard the band range across the
6162
* BNDPAR band groups of a k-pool: every process only accumulates the
6263
* partial sum over its own band window. This reduction combines those
63-
* partial sums on BP_WORLD (bdiff_ksame), which links the same rank
64-
* position of every band group inside one k-pool, so each band window
65-
* contributes exactly once.
64+
* partial sums on the bdiff_ksame (BP_WORLD) communicator, which links
65+
* the same rank position of every band group inside one k-pool, so each
66+
* band window contributes exactly once.
6667
*
6768
* It must run BEFORE ParaKmeshWorld::reduce_across_pools so that the
6869
* k-pool reduction receives one complete per-k-pool partial sum.
@@ -71,7 +72,7 @@ class ParaBgroupWorld : public ParaWorld
7172
* @param[in,out] value local partial sum, overwritten with the
7273
* k-pool-wide total
7374
*/
74-
void reduce_across_bgroups(double& value) const;
75+
void reduce_across_bdiff_ksame(double& value) const;
7576

7677
private:
7778
int my_bndgroup_ = 0;
@@ -83,4 +84,4 @@ class ParaBgroupWorld : public ParaWorld
8384

8485
} // namespace Parallel
8586

86-
#endif // PARA_BGROUP_WORLD_H
87+
#endif // PARA_BDIFF_KSAME_WORLD_H

source/source_base/module_parallel/para_bridge.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ ParaKmeshWorld make_kmesh_world(int nkstot, int nspin)
5959
return ParaKmeshWorld(nkstot, nspin);
6060
}
6161

62-
// Temporary bridge: construct a bgroup-domain ParaBgroupWorld from the old
63-
// globals. Delete this file once ParaCollection is wired into driver init.
64-
ParaBgroupWorld make_bgroup_world()
62+
// Temporary bridge: construct a bdiff_ksame-domain ParaBdiffKsameWorld from
63+
// the old globals. Delete this file once ParaCollection is wired into driver init.
64+
ParaBdiffKsameWorld make_bdiff_ksame_world()
6565
{
6666
#ifdef __MPI
6767
int mpi_initialized = 0;
@@ -73,10 +73,10 @@ ParaBgroupWorld make_bgroup_world()
7373
{
7474
int nbndgroup = 1;
7575
MPI_Comm_size(BP_WORLD, &nbndgroup);
76-
return ParaBgroupWorld(INT_BGROUP, BP_WORLD, nbndgroup);
76+
return ParaBdiffKsameWorld(INT_BGROUP, BP_WORLD, nbndgroup);
7777
}
7878
#endif
79-
return ParaBgroupWorld();
79+
return ParaBdiffKsameWorld();
8080
}
8181

8282
} // namespace Parallel

source/source_base/module_parallel/para_bridge.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef PARA_BRIDGE_H
22
#define PARA_BRIDGE_H
33

4-
#include "para_bgroup_world.h"
4+
#include "para_bdiff_ksame_world.h"
55
#include "para_kmesh_world.h"
66
#include "para_world.h"
77

@@ -45,14 +45,15 @@ ParaKmeshWorld make_kmesh_world(int nkstot, int nspin);
4545
ParaKmeshWorld make_kmesh_world();
4646

4747
/**
48-
* @brief Temporary bridge: construct a bgroup-domain ParaBgroupWorld from
49-
* the old globals INT_BGROUP / BP_WORLD (MPI) or as a serial domain.
48+
* @brief Temporary bridge: construct a bdiff_ksame-domain
49+
* ParaBdiffKsameWorld from the old globals INT_BGROUP / BP_WORLD (MPI) or
50+
* as a serial domain.
5051
*
5152
* Falls back to a serial single-band-group domain when MPI is not
5253
* initialized or the pool layout has not been set up yet (e.g. unit
5354
* tests), so that no MPI call is made on an unset communicator.
5455
*/
55-
ParaBgroupWorld make_bgroup_world();
56+
ParaBdiffKsameWorld make_bdiff_ksame_world();
5657

5758
} // namespace Parallel
5859

source/source_base/module_parallel/para_kmesh_world.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Parallel
1919
* The k-pool split (kpar) is independent of bndpar: the domain knows
2020
* nothing about band groups. Reductions that must span both dimensions
2121
* (e.g. the total electron count under BPCG) therefore combine
22-
* ParaBgroupWorld::reduce_across_bgroups (band dimension, run FIRST)
22+
* ParaBdiffKsameWorld::reduce_across_bdiff_ksame (band dimension, run FIRST)
2323
* with reduce_across_pools (k dimension, run SECOND).
2424
*
2525
* In serial builds all operations degenerate to single-pool behavior.
@@ -117,7 +117,7 @@ class ParaKmeshWorld : public ParaWorld
117117
*
118118
* Precondition: with band parallelism (bndpar > 1) the caller must
119119
* first combine the band-group partial sums (e.g.
120-
* ParaBgroupWorld::reduce_across_bgroups) so that every process of a
120+
* ParaBdiffKsameWorld::reduce_across_bdiff_ksame) so that every process of a
121121
* k-pool holds one complete per-pool partial sum.
122122
*
123123
* No-op when kpar() <= 1.

source/source_base/module_parallel/test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ AddTest(
3030
)
3131

3232
AddTest(
33-
TARGET MODULE_BASE_para_bgroup_world
34-
SOURCES para_bgroup_world_test.cpp ../para_bgroup_world.cpp ../para_world.cpp
33+
TARGET MODULE_BASE_para_bdiff_ksame_world
34+
SOURCES para_bdiff_ksame_world_test.cpp ../para_bdiff_ksame_world.cpp ../para_world.cpp
3535
)
3636

3737
AddTest(
@@ -80,7 +80,7 @@ target_compile_definitions(MODULE_BASE_para_setup_mpi PRIVATE __MPI)
8080
# Built with add_executable (not AddTest) so that no direct-run CTest entry is
8181
# created; the binary is only exercised through mpirun by the .sh test below,
8282
# matching the multi-process requirement of these cases.
83-
add_executable(MODULE_BASE_para_kmesh_world_mpi test_para_kmesh_world_mpi.cpp ../para_bgroup_world.cpp ../para_kmesh_world.cpp ../para_world.cpp)
83+
add_executable(MODULE_BASE_para_kmesh_world_mpi test_para_kmesh_world_mpi.cpp ../para_bdiff_ksame_world.cpp ../para_kmesh_world.cpp ../para_world.cpp)
8484
target_link_libraries(MODULE_BASE_para_kmesh_world_mpi PRIVATE MPI::MPI_CXX GTest::gtest GTest::gtest_main abacus::linalg_libs)
8585
target_compile_definitions(MODULE_BASE_para_kmesh_world_mpi PRIVATE __MPI)
8686

source/source_base/module_parallel/test/para_bgroup_world_test.cpp renamed to source/source_base/module_parallel/test/para_bdiff_ksame_world_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "gtest/gtest.h"
22

3-
#include "../para_bgroup_world.h"
3+
#include "../para_bdiff_ksame_world.h"
44

5-
TEST(ParaBgroupWorldTest, SerialMode)
5+
TEST(ParaBdiffKsameWorldTest, SerialMode)
66
{
7-
const Parallel::ParaBgroupWorld world;
7+
const Parallel::ParaBdiffKsameWorld world;
88
EXPECT_EQ(world.tag(), "bdiff_ksame");
99
EXPECT_EQ(world.my_bndgroup(), 0);
1010
EXPECT_EQ(world.nbndgroup(), 1);
@@ -13,9 +13,9 @@ TEST(ParaBgroupWorldTest, SerialMode)
1313
EXPECT_TRUE(world.valid());
1414
}
1515

16-
TEST(ParaBgroupWorldTest, AliasesMatchBase)
16+
TEST(ParaBdiffKsameWorldTest, AliasesMatchBase)
1717
{
18-
const Parallel::ParaBgroupWorld world;
18+
const Parallel::ParaBdiffKsameWorld world;
1919
EXPECT_EQ(world.rank_in_bpgroup(), world.rank());
2020
EXPECT_EQ(world.nproc_in_bndgroup(), world.size());
2121
}

source/source_base/module_parallel/test/test_para_kmesh_world_mpi.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include "gtest/gtest.h"
22

3-
#include "../para_bgroup_world.h"
3+
#include "../para_bdiff_ksame_world.h"
44
#include "../para_kmesh_world.h"
55

66
// Run with: mpirun -np 4 ./MODULE_BASE_para_kmesh_world_mpi
77
//
88
// The sum reduction protocol has two layers:
9-
// 1. ParaBgroupWorld::reduce_across_bgroups (band dimension, BPCG shards)
9+
// 1. ParaBdiffKsameWorld::reduce_across_bdiff_ksame (band dimension, BPCG shards)
1010
// 2. ParaKmeshWorld::reduce_across_pools (k dimension, one
1111
// contribution per k-pool: the first rank of each k-pool injects the
1212
// partial sum, everyone else injects zero)
@@ -26,12 +26,12 @@ TEST(ParaKmeshWorldMpiTest, ReduceAcrossBandGroupsBndpar2)
2626
// which links the same rank position of every band group.
2727
MPI_Comm bp_world = MPI_COMM_NULL;
2828
MPI_Comm_split(MPI_COMM_WORLD, myrank % 2, myrank / 2, &bp_world);
29-
Parallel::ParaBgroupWorld bgroup(MPI_COMM_WORLD, bp_world, 2);
29+
Parallel::ParaBdiffKsameWorld bdiff(MPI_COMM_WORLD, bp_world, 2);
3030

3131
// Each band group holds a partial occupation sum of 14 (28 electrons
3232
// split into two band windows).
3333
double sumk = 14.0;
34-
bgroup.reduce_across_bgroups(sumk);
34+
bdiff.reduce_across_bdiff_ksame(sumk);
3535
EXPECT_DOUBLE_EQ(sumk, 28.0);
3636

3737
// max/min stay world-wide (idempotent) and must span the band groups
@@ -114,7 +114,7 @@ TEST(ParaKmeshWorldMpiTest, SinglePoolIsNoOp)
114114
ASSERT_EQ(nprocs, 4);
115115

116116
// kpar == 1: the sum reduction must be a no-op regardless of the
117-
// world size (the band dimension is handled by ParaBgroupWorld).
117+
// world size (the band dimension is handled by ParaBdiffKsameWorld).
118118
Parallel::ParaKmeshWorld kmesh(MPI_COMM_WORLD, 1, 0, 0, 1);
119119
double sumk = 42.0;
120120
kmesh.reduce_across_pools(sumk);

0 commit comments

Comments
 (0)