|
7 | 7 | #include <cstring> |
8 | 8 |
|
9 | 9 | #ifdef __MPI |
10 | | -void Parallel_Common::bcast_string(std::string& object) // Peize Lin fix bug 2019-03-18 |
| 10 | +void Parallel_Common::bcast_string(std::string& object, MPI_Comm comm) // Peize Lin fix bug 2019-03-18 |
11 | 11 | { |
12 | 12 | int size = object.size(); |
13 | | - MPI_Bcast(&size, 1, MPI_INT, 0, MPI_COMM_WORLD); |
14 | | - |
| 13 | + MPI_Bcast(&size, 1, MPI_INT, 0, comm); |
| 14 | + |
15 | 15 | int my_rank; |
16 | | - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); |
17 | | - |
| 16 | + MPI_Comm_rank(comm, &my_rank); |
| 17 | + |
18 | 18 | if (0 != my_rank) |
19 | 19 | { |
20 | 20 | object.resize(size); |
21 | 21 | } |
22 | 22 |
|
23 | | - MPI_Bcast(&object[0], size, MPI_CHAR, 0, MPI_COMM_WORLD); |
| 23 | + MPI_Bcast(&object[0], size, MPI_CHAR, 0, comm); |
24 | 24 | return; |
25 | 25 | } |
26 | 26 |
|
27 | | -void Parallel_Common::bcast_string(std::string* object, const int n) // Peize Lin fix bug 2019-03-18 |
| 27 | +void Parallel_Common::bcast_string(std::string* object, const int n, MPI_Comm comm) // Peize Lin fix bug 2019-03-18 |
28 | 28 | { |
29 | 29 | for (int i = 0; i < n; i++) |
30 | | - bcast_string(object[i]); |
| 30 | + bcast_string(object[i], comm); |
31 | 31 | return; |
32 | 32 | } |
33 | 33 |
|
34 | | -void Parallel_Common::bcast_complex_double(std::complex<double>& object) |
| 34 | +void Parallel_Common::bcast_complex_double(std::complex<double>& object, MPI_Comm comm) |
35 | 35 | { |
36 | | - MPI_Bcast(&object, 1, MPI_DOUBLE_COMPLEX, 0, MPI_COMM_WORLD); |
| 36 | + MPI_Bcast(&object, 1, MPI_DOUBLE_COMPLEX, 0, comm); |
37 | 37 | } |
38 | 38 |
|
39 | | -void Parallel_Common::bcast_complex_double(std::complex<double>* object, const int n) |
| 39 | +void Parallel_Common::bcast_complex_double(std::complex<double>* object, const int n, MPI_Comm comm) |
40 | 40 | { |
41 | | - MPI_Bcast(object, n, MPI_DOUBLE_COMPLEX, 0, MPI_COMM_WORLD); |
| 41 | + MPI_Bcast(object, n, MPI_DOUBLE_COMPLEX, 0, comm); |
42 | 42 | } |
43 | 43 |
|
44 | | -void Parallel_Common::bcast_double(double& object) |
| 44 | +void Parallel_Common::bcast_double(double& object, MPI_Comm comm) |
45 | 45 | { |
46 | | - MPI_Bcast(&object, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
| 46 | + MPI_Bcast(&object, 1, MPI_DOUBLE, 0, comm); |
47 | 47 | } |
48 | 48 |
|
49 | | -void Parallel_Common::bcast_double(double* object, const int n) |
| 49 | +void Parallel_Common::bcast_double(double* object, const int n, MPI_Comm comm) |
50 | 50 | { |
51 | | - MPI_Bcast(object, n, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
| 51 | + MPI_Bcast(object, n, MPI_DOUBLE, 0, comm); |
52 | 52 | } |
53 | 53 |
|
54 | | -void Parallel_Common::bcast_int(int& object) |
| 54 | +void Parallel_Common::bcast_int(int& object, MPI_Comm comm) |
55 | 55 | { |
56 | | - MPI_Bcast(&object, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 56 | + MPI_Bcast(&object, 1, MPI_INT, 0, comm); |
57 | 57 | } |
58 | 58 |
|
59 | | -void Parallel_Common::bcast_int(int* object, const int n) |
| 59 | +void Parallel_Common::bcast_int(int* object, const int n, MPI_Comm comm) |
60 | 60 | { |
61 | | - MPI_Bcast(object, n, MPI_INT, 0, MPI_COMM_WORLD); |
| 61 | + MPI_Bcast(object, n, MPI_INT, 0, comm); |
62 | 62 | } |
63 | 63 |
|
64 | | -void Parallel_Common::bcast_bool(bool& object) |
| 64 | +void Parallel_Common::bcast_bool(bool& object, MPI_Comm comm) |
65 | 65 | { |
66 | 66 | int swap = object; |
67 | 67 | int my_rank; |
68 | | - MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); |
| 68 | + MPI_Comm_rank(comm, &my_rank); |
69 | 69 | if (my_rank == 0) |
70 | 70 | swap = object; |
71 | | - MPI_Bcast(&swap, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 71 | + MPI_Bcast(&swap, 1, MPI_INT, 0, comm); |
72 | 72 | if (my_rank != 0) |
73 | 73 | object = static_cast<bool>(swap); |
74 | 74 | } |
75 | 75 |
|
76 | | -void Parallel_Common::bcast_char(char* object, const int n) |
| 76 | +void Parallel_Common::bcast_char(char* object, const int n, MPI_Comm comm) |
77 | 77 | { |
78 | | - MPI_Bcast(object, n, MPI_CHAR, 0, MPI_COMM_WORLD); |
| 78 | + MPI_Bcast(object, n, MPI_CHAR, 0, comm); |
79 | 79 | } |
80 | 80 |
|
81 | 81 | #endif |
0 commit comments