Skip to content

Commit 3d0a84f

Browse files
Igor S. Gerasimovfoxtran
authored andcommitted
Create window with num_active
1 parent 1aa575c commit 3d0a84f

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

src/CXX/SLB4MPI/SLB4MPI/work_stealing_load_balancer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace SLB4MPI {
1818
MPI_Win window_actual_rank; ///< actual rank to compute (for fast look up)
1919
MPI_Win window_done; ///< status of thread
2020
int actual_rank; ///< rank for computing
21+
int num_active; ///< number of active ranks
2122
bool done; ///< does it compute all elements in its own rank? Implemented for non-blocking check with MPI_LOCK_SHARED
2223
#endif
2324
public:

src/CXX/work_stealing_load_balancer.cxx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,13 @@ SLB4MPI::WorkStealingLoadBalancer::WorkStealingLoadBalancer(const MPI_Comm commu
3030
#ifdef SLB4MPI_WITH_MPI
3131
this->actual_rank = this->rank;
3232
this->done = false;
33+
this->num_active = this->nranks;
3334

34-
void * baseaddr;
35-
36-
MPI_Win_allocate(sizeof(int), sizeof(int), MPI_INFO_NULL, this->communicator, baseaddr, &(this->window_num_active));
35+
MPI_Win_create(&(this->num_active), sizeof(int), sizeof(int), MPI_INFO_NULL, this->communicator, &(this->window_num_active));
3736
MPI_Win_create(&(this->actual_rank), sizeof(int), sizeof(int), MPI_INFO_NULL, this->communicator, &(this->window_actual_rank));
3837
MPI_Win_create(&(this->bounds), 2*sizeof(int64_t), sizeof(int64_t), MPI_INFO_NULL, this->communicator, &(this->window_bounds));
3938
MPI_Win_create(&(this->done), sizeof(bool), sizeof(bool), MPI_INFO_NULL, this->communicator, &(this->window_done));
4039

41-
if (this->rank == this->root) {
42-
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, this->root, 0, this->window_num_active);
43-
MPI_Put(&(this->nranks), 1, MPI_INT, this->root, 0, 1, MPI_INT, this->window_num_active);
44-
MPI_Win_unlock(this->root, this->window_num_active);
45-
}
46-
4740
MPI_Barrier(this->communicator);
4841
#endif
4942
}
@@ -83,8 +76,7 @@ bool SLB4MPI::WorkStealingLoadBalancer::get_range(int64_t& lower_bound, int64_t&
8376
if (upper_bound + 1 > this->upper_bound && !this->done) {
8477
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, this->root, 0, this->window_num_active);
8578
int minus_one = -1;
86-
int num_active;
87-
MPI_Fetch_and_op(&minus_one, &num_active, MPI_INT, this->root, 0, MPI_SUM, this->window_num_active);
79+
MPI_Fetch_and_op(&minus_one, &(this->num_active), MPI_INT, this->root, 0, MPI_SUM, this->window_num_active);
8880
MPI_Win_unlock(this->root, this->window_num_active);
8981
this->actual_rank = (this->actual_rank + 1) % this->nranks;
9082
this->done = true;
@@ -141,11 +133,10 @@ bool SLB4MPI::WorkStealingLoadBalancer::get_range(int64_t& lower_bound, int64_t&
141133
}
142134
}
143135
// if could not steal job, check how many threads finished job
144-
int num_active;
145136
MPI_Win_lock(MPI_LOCK_SHARED, this->root, 0, this->window_num_active);
146-
MPI_Get(&num_active, 1, MPI_INT, this->root, 0, 1, MPI_INT, this->window_num_active);
137+
MPI_Get(&(this->num_active), 1, MPI_INT, this->root, 0, 1, MPI_INT, this->window_num_active);
147138
MPI_Win_unlock(this->root, this->window_num_active);
148-
if (num_active == 0) return false;
139+
if (this->num_active == 0) return false;
149140
this->actual_rank = (this->actual_rank + 1) % this->nranks;
150141
hop_count = 0;
151142
nohop_count = nohop_count + 1;

0 commit comments

Comments
 (0)