Skip to content

Commit b839503

Browse files
author
abacus_fixer
committed
Move __MPI guards inside Parallel_Common bcast functions
Restructure parallel_common.cpp following parallel_reduce.cpp style: the file-level #ifdef around all 11 bcast_* definitions is replaced by function-body guards, so serial builds get no-op definitions instead of link errors. Callers no longer need #ifdef __MPI around bcast calls (consistent with Parallel_Reduce::reduce_* usage); the guard previously restored around bcast_bool in to_w90.cpp is removed again as the net change there is zero. This fixes the "build without MPI" link failure reported by CI: undefined reference to Parallel_Common::bcast_bool(bool&). - Verified: incremental build with MPI passes with no errors; g++ -fsyntax-only of parallel_common.cpp without __MPI passes
1 parent c2dd552 commit b839503

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

source/source_base/parallel_common.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,79 @@
66

77
#include <cstring>
88

9-
#ifdef __MPI
109
void Parallel_Common::bcast_string(std::string& object) // Peize Lin fix bug 2019-03-18
1110
{
11+
#ifdef __MPI
1212
int size = object.size();
1313
MPI_Bcast(&size, 1, MPI_INT, 0, MPI_COMM_WORLD);
14-
14+
1515
int my_rank;
1616
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
17-
17+
1818
if (0 != my_rank)
1919
{
2020
object.resize(size);
2121
}
2222

2323
MPI_Bcast(&object[0], size, MPI_CHAR, 0, MPI_COMM_WORLD);
24+
#endif
2425
return;
2526
}
2627

2728
void Parallel_Common::bcast_string(std::string* object, const int n) // Peize Lin fix bug 2019-03-18
2829
{
30+
#ifdef __MPI
2931
for (int i = 0; i < n; i++)
3032
bcast_string(object[i]);
33+
#endif
3134
return;
3235
}
3336

3437
void Parallel_Common::bcast_complex_double(std::complex<double>& object)
3538
{
39+
#ifdef __MPI
3640
MPI_Bcast(&object, 1, MPI_DOUBLE_COMPLEX, 0, MPI_COMM_WORLD);
41+
#endif
3742
}
3843

3944
void Parallel_Common::bcast_complex_double(std::complex<double>* object, const int n)
4045
{
46+
#ifdef __MPI
4147
MPI_Bcast(object, n, MPI_DOUBLE_COMPLEX, 0, MPI_COMM_WORLD);
48+
#endif
4249
}
4350

4451
void Parallel_Common::bcast_double(double& object)
4552
{
53+
#ifdef __MPI
4654
MPI_Bcast(&object, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
55+
#endif
4756
}
4857

4958
void Parallel_Common::bcast_double(double* object, const int n)
5059
{
60+
#ifdef __MPI
5161
MPI_Bcast(object, n, MPI_DOUBLE, 0, MPI_COMM_WORLD);
62+
#endif
5263
}
5364

5465
void Parallel_Common::bcast_int(int& object)
5566
{
67+
#ifdef __MPI
5668
MPI_Bcast(&object, 1, MPI_INT, 0, MPI_COMM_WORLD);
69+
#endif
5770
}
5871

5972
void Parallel_Common::bcast_int(int* object, const int n)
6073
{
74+
#ifdef __MPI
6175
MPI_Bcast(object, n, MPI_INT, 0, MPI_COMM_WORLD);
76+
#endif
6277
}
6378

6479
void Parallel_Common::bcast_bool(bool& object)
6580
{
81+
#ifdef __MPI
6682
int swap = object;
6783
int my_rank;
6884
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
@@ -71,11 +87,12 @@ void Parallel_Common::bcast_bool(bool& object)
7187
MPI_Bcast(&swap, 1, MPI_INT, 0, MPI_COMM_WORLD);
7288
if (my_rank != 0)
7389
object = static_cast<bool>(swap);
90+
#endif
7491
}
7592

7693
void Parallel_Common::bcast_char(char* object, const int n)
7794
{
95+
#ifdef __MPI
7896
MPI_Bcast(object, n, MPI_CHAR, 0, MPI_COMM_WORLD);
79-
}
80-
8197
#endif
98+
}

0 commit comments

Comments
 (0)