Skip to content

Commit

Permalink
Cleanup some more code. (#295)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <[email protected]>
  • Loading branch information
samuelkgutierrez authored Jan 24, 2025
1 parent 75ff06e commit 45a63c0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/quo-vadis-pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ qv_pthread_scope_split_at(
return QV_ERR_INVLD_ARG;
}
try {
return scope->thsplit_at(
return scope->thread_split_at(
type, color_array, nthreads, subscopes
);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ qv_pthread_scopes_free(
return QV_ERR_INVLD_ARG;
}
try {
qv_scope::thdestroy(&scopes, nscopes);
qv_scope::thread_destroy(&scopes, nscopes);
return QV_SUCCESS;
}
qvi_catch_and_return();
Expand Down
2 changes: 1 addition & 1 deletion src/qvi-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ qvi_mpi_group_create_from_split(
const int mpirc = MPI_Comm_split(
parent->qvcomm.mpi_comm, color, key, &split_comm
);
if (mpirc != MPI_SUCCESS) return QV_ERR_MPI;
if (qvi_unlikely(mpirc != MPI_SUCCESS)) return QV_ERR_MPI;

const int rc = qvi_mpi_group_create_from_mpi_comm(
mpi, split_comm, child
Expand Down
18 changes: 10 additions & 8 deletions src/qvi-pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ int
qvi_pthread_group::rank(void)
{
std::lock_guard<std::mutex> guard(m_mutex);
assert(!m_tid2rank.empty());
return m_tid2rank.at(qvi_gettid());
}

qvi_task *
qvi_pthread_group::task(void)
{
std::lock_guard<std::mutex> guard(m_mutex);
assert(!m_tid2task.empty());
return m_tid2task.at(qvi_gettid());
}

Expand All @@ -152,17 +154,17 @@ qvi_pthread_group::m_subgroup_info(
int key,
qvi_subgroup_info *sginfo
) {
int rank = qvi_pthread_group::rank();
int master_rank = 0; // Choosing 0 as master.
const int master_rank = 0;
const int my_rank = qvi_pthread_group::rank();
// Gather colors and keys from ALL threads.
m_ckrs[rank].color = color;
m_ckrs[rank].key = key;
m_ckrs[rank].rank = rank;
m_ckrs[my_rank].color = color;
m_ckrs[my_rank].key = key;
m_ckrs[my_rank].rank = my_rank;
// Barrier to be sure that all threads have contributed their values.
pthread_barrier_wait(&m_barrier);
// Since these data are shared, only the master thread has to sort them.
// The same goes for calculating the number of distinct colors provided.
if(rank == master_rank){
if (my_rank == master_rank) {
// Sort the color/key/rank array. First according to color, then by key,
// but in the same color realm. If color and key are identical, sort by
// the rank from given group.
Expand All @@ -174,7 +176,7 @@ qvi_pthread_group::m_subgroup_info(
for (int i = 0; i < m_size; ++i) {
color_set.insert(m_ckrs[i].color);
}
m_ckrs[rank].ncolors = color_set.size();
m_ckrs[my_rank].ncolors = color_set.size();
}
//All threads wait for the number of colors to be computed.
pthread_barrier_wait(&m_barrier);
Expand All @@ -188,7 +190,7 @@ qvi_pthread_group::m_subgroup_info(
// Else we found the start of my color group.
const int current_color = m_ckrs[i].color;
for (int j = i; j < m_size && current_color == m_ckrs[j].color; ++j) {
if (m_ckrs[j].rank == rank) {
if (m_ckrs[j].rank == my_rank) {
sginfo->rank = group_rank;
}
group_size++;
Expand Down
8 changes: 4 additions & 4 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-basic-offset:4; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2020-2024 Triad National Security, LLC
* Copyright (c) 2020-2025 Triad National Security, LLC
* All rights reserved.
*
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
Expand Down Expand Up @@ -41,7 +41,7 @@ qv_scope::destroy(
}

void
qv_scope::thdestroy(
qv_scope::thread_destroy(
qv_scope_t ***kscopes,
uint_t k
) {
Expand Down Expand Up @@ -297,7 +297,7 @@ qv_scope::thread_split(
ithchildren[i] = child;
}
if (rc != QV_SUCCESS) {
qv_scope::thdestroy(&ithchildren, k);
qv_scope::thread_destroy(&ithchildren, k);
}
else {
// Subtract one to account for the parent's
Expand All @@ -312,7 +312,7 @@ qv_scope::thread_split(
}

int
qv_scope::thsplit_at(
qv_scope::thread_split_at(
qv_hw_obj_type_t type,
int *kgroup_ids,
uint_t k,
Expand Down
8 changes: 4 additions & 4 deletions src/qvi-scope.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-basic-offset:4; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2021-2024 Triad National Security, LLC
* Copyright (c) 2021-2025 Triad National Security, LLC
* All rights reserved.
*
* Copyright (c) 2021 Lawrence Livermore National Security, LLC
Expand Down Expand Up @@ -60,9 +60,9 @@ struct qv_scope {
destroy(
qv_scope_t **scope
);
/** Destroys scopes created by thsplit*. */
/** Destroys scopes created by thread_split*. */
static void
thdestroy(
thread_destroy(
qv_scope_t ***kscopes,
uint_t k
);
Expand Down Expand Up @@ -120,7 +120,7 @@ struct qv_scope {
);

int
thsplit_at(
thread_split_at(
qv_hw_obj_type_t type,
int *kgroup_ids,
uint_t k,
Expand Down

0 comments on commit 45a63c0

Please sign in to comment.