Skip to content

Commit 45a63c0

Browse files
Cleanup some more code. (#295)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 75ff06e commit 45a63c0

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

src/quo-vadis-pthread.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ qv_pthread_scope_split_at(
8686
return QV_ERR_INVLD_ARG;
8787
}
8888
try {
89-
return scope->thsplit_at(
89+
return scope->thread_split_at(
9090
type, color_array, nthreads, subscopes
9191
);
9292
}
@@ -129,7 +129,7 @@ qv_pthread_scopes_free(
129129
return QV_ERR_INVLD_ARG;
130130
}
131131
try {
132-
qv_scope::thdestroy(&scopes, nscopes);
132+
qv_scope::thread_destroy(&scopes, nscopes);
133133
return QV_SUCCESS;
134134
}
135135
qvi_catch_and_return();

src/qvi-mpi.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ qvi_mpi_group_create_from_split(
291291
const int mpirc = MPI_Comm_split(
292292
parent->qvcomm.mpi_comm, color, key, &split_comm
293293
);
294-
if (mpirc != MPI_SUCCESS) return QV_ERR_MPI;
294+
if (qvi_unlikely(mpirc != MPI_SUCCESS)) return QV_ERR_MPI;
295295

296296
const int rc = qvi_mpi_group_create_from_mpi_comm(
297297
mpi, split_comm, child

src/qvi-pthread.cc

+10-8
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ int
126126
qvi_pthread_group::rank(void)
127127
{
128128
std::lock_guard<std::mutex> guard(m_mutex);
129+
assert(!m_tid2rank.empty());
129130
return m_tid2rank.at(qvi_gettid());
130131
}
131132

132133
qvi_task *
133134
qvi_pthread_group::task(void)
134135
{
135136
std::lock_guard<std::mutex> guard(m_mutex);
137+
assert(!m_tid2task.empty());
136138
return m_tid2task.at(qvi_gettid());
137139
}
138140

@@ -152,17 +154,17 @@ qvi_pthread_group::m_subgroup_info(
152154
int key,
153155
qvi_subgroup_info *sginfo
154156
) {
155-
int rank = qvi_pthread_group::rank();
156-
int master_rank = 0; // Choosing 0 as master.
157+
const int master_rank = 0;
158+
const int my_rank = qvi_pthread_group::rank();
157159
// Gather colors and keys from ALL threads.
158-
m_ckrs[rank].color = color;
159-
m_ckrs[rank].key = key;
160-
m_ckrs[rank].rank = rank;
160+
m_ckrs[my_rank].color = color;
161+
m_ckrs[my_rank].key = key;
162+
m_ckrs[my_rank].rank = my_rank;
161163
// Barrier to be sure that all threads have contributed their values.
162164
pthread_barrier_wait(&m_barrier);
163165
// Since these data are shared, only the master thread has to sort them.
164166
// The same goes for calculating the number of distinct colors provided.
165-
if(rank == master_rank){
167+
if (my_rank == master_rank) {
166168
// Sort the color/key/rank array. First according to color, then by key,
167169
// but in the same color realm. If color and key are identical, sort by
168170
// the rank from given group.
@@ -174,7 +176,7 @@ qvi_pthread_group::m_subgroup_info(
174176
for (int i = 0; i < m_size; ++i) {
175177
color_set.insert(m_ckrs[i].color);
176178
}
177-
m_ckrs[rank].ncolors = color_set.size();
179+
m_ckrs[my_rank].ncolors = color_set.size();
178180
}
179181
//All threads wait for the number of colors to be computed.
180182
pthread_barrier_wait(&m_barrier);
@@ -188,7 +190,7 @@ qvi_pthread_group::m_subgroup_info(
188190
// Else we found the start of my color group.
189191
const int current_color = m_ckrs[i].color;
190192
for (int j = i; j < m_size && current_color == m_ckrs[j].color; ++j) {
191-
if (m_ckrs[j].rank == rank) {
193+
if (m_ckrs[j].rank == my_rank) {
192194
sginfo->rank = group_rank;
193195
}
194196
group_size++;

src/qvi-scope.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C++; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2020-2024 Triad National Security, LLC
3+
* Copyright (c) 2020-2025 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC
@@ -41,7 +41,7 @@ qv_scope::destroy(
4141
}
4242

4343
void
44-
qv_scope::thdestroy(
44+
qv_scope::thread_destroy(
4545
qv_scope_t ***kscopes,
4646
uint_t k
4747
) {
@@ -297,7 +297,7 @@ qv_scope::thread_split(
297297
ithchildren[i] = child;
298298
}
299299
if (rc != QV_SUCCESS) {
300-
qv_scope::thdestroy(&ithchildren, k);
300+
qv_scope::thread_destroy(&ithchildren, k);
301301
}
302302
else {
303303
// Subtract one to account for the parent's
@@ -312,7 +312,7 @@ qv_scope::thread_split(
312312
}
313313

314314
int
315-
qv_scope::thsplit_at(
315+
qv_scope::thread_split_at(
316316
qv_hw_obj_type_t type,
317317
int *kgroup_ids,
318318
uint_t k,

src/qvi-scope.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C++; c-basic-offset:4; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2021-2024 Triad National Security, LLC
3+
* Copyright (c) 2021-2025 Triad National Security, LLC
44
* All rights reserved.
55
*
66
* Copyright (c) 2021 Lawrence Livermore National Security, LLC
@@ -60,9 +60,9 @@ struct qv_scope {
6060
destroy(
6161
qv_scope_t **scope
6262
);
63-
/** Destroys scopes created by thsplit*. */
63+
/** Destroys scopes created by thread_split*. */
6464
static void
65-
thdestroy(
65+
thread_destroy(
6666
qv_scope_t ***kscopes,
6767
uint_t k
6868
);
@@ -120,7 +120,7 @@ struct qv_scope {
120120
);
121121

122122
int
123-
thsplit_at(
123+
thread_split_at(
124124
qv_hw_obj_type_t type,
125125
int *kgroup_ids,
126126
uint_t k,

0 commit comments

Comments
 (0)