Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code. #227

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/quo-vadis-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ qvi_mpi_scope_get(
*scope = nullptr;
// Create and initialize the base group.
qvi_zgroup_mpi_s *izgroup = nullptr;
int rc = qvi_new(&izgroup, comm);
if (rc != QV_SUCCESS) return rc;
const int rc = qvi_new(&izgroup, comm);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;

return qvi_scope_get(izgroup, iscope, scope);
}
Expand All @@ -73,7 +73,7 @@ qv_mpi_scope_get(
qv_scope_intrinsic_t iscope,
qv_scope_t **scope
) {
if (comm == MPI_COMM_NULL || !scope) {
if (qvi_unlikely(comm == MPI_COMM_NULL || !scope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -87,7 +87,7 @@ qvi_mpi_scope_comm_dup(
qv_scope_t *scope,
MPI_Comm *comm
) {
qvi_group_mpi_t *mpi_group = dynamic_cast<qvi_group_mpi_t *>(
qvi_group_mpi_t *const mpi_group = dynamic_cast<qvi_group_mpi_t *>(
qvi_scope_group_get(scope)
);
return mpi_group->comm_dup(comm);
Expand All @@ -98,7 +98,7 @@ qv_mpi_scope_comm_dup(
qv_scope_t *scope,
MPI_Comm *comm
) {
if (!scope || !comm) {
if (qvi_unlikely(!scope || !comm)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand Down
4 changes: 2 additions & 2 deletions src/quo-vadis-omp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ qvi_omp_scope_get(
// Create the base process group.
qvi_group_omp_s *zgroup = nullptr;
const int rc = qvi_new(&zgroup);
if (rc != QV_SUCCESS) {
if (qvi_unlikely(rc != QV_SUCCESS)) {
*scope = nullptr;
return rc;
}
Expand All @@ -43,7 +43,7 @@ qv_omp_scope_get(
qv_scope_intrinsic_t iscope,
qv_scope_t **scope
) {
if (!scope) {
if (qvi_unlikely(!scope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand Down
6 changes: 3 additions & 3 deletions src/quo-vadis-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ qvi_process_scope_get(
) {
// Create the base process group.
qvi_group_process_s *zgroup = nullptr;
int rc = qvi_new(&zgroup);
if (rc != QV_SUCCESS) {
const int rc = qvi_new(&zgroup);
if (qvi_unlikely(rc != QV_SUCCESS)) {
*scope = nullptr;
return rc;
}
Expand All @@ -36,7 +36,7 @@ qv_process_scope_get(
qv_scope_intrinsic_t iscope,
qv_scope_t **scope
) {
if (!scope) {
if (qvi_unlikely(!scope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand Down
12 changes: 7 additions & 5 deletions src/quo-vadis-pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ qv_pthread_scope_split(
int nthreads,
qv_scope_t ***subscope
) {
if (!scope || npieces < 0 || !color_array || nthreads < 0 || !subscope) {
const bool invld_args = !scope || npieces < 0 ||
!color_array || nthreads < 0 || !subscope;
if (qvi_unlikely(invld_args)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -80,7 +82,7 @@ qv_pthread_scope_split_at(
int nthreads,
qv_scope_t ***subscopes
) {
if (!scope || !color_array || nthreads < 0 || !subscopes) {
if (qvi_unlikely(!scope || !color_array || nthreads < 0 || !subscopes)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -95,7 +97,7 @@ int
qv_pthread_create(
pthread_t *thread,
const pthread_attr_t *attr,
void *(*thread_routine)(void *arg),
qvi_pthread_routine_fun_ptr_t thread_routine,
void *arg,
qv_scope_t *scope
) {
Expand All @@ -104,7 +106,7 @@ qv_pthread_create(
const int rc = qvi_new(&arg_ptr, scope, thread_routine, arg);
// Since this is meant to behave similarly to
// pthread_create(), return a reasonable errno.
if (rc != QV_SUCCESS) return ENOMEM;
if (qvi_unlikely(rc != QV_SUCCESS)) return ENOMEM;

return pthread_create(thread, attr, qvi_pthread_routine, arg_ptr);
}
Expand All @@ -114,7 +116,7 @@ qv_pthread_scopes_free(
int nscopes,
qv_scope_t **scopes
) {
if (nscopes < 0 || !scopes) {
if (qvi_unlikely(nscopes < 0 || !scopes)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand Down
26 changes: 13 additions & 13 deletions src/quo-vadis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ qv_version(
int *minor,
int *patch
) {
if (!major || !minor || !patch) {
if (qvi_unlikely(!major || !minor || !patch)) {
return QV_ERR_INVLD_ARG;
}

Expand All @@ -37,7 +37,7 @@ int
qv_scope_bind_push(
qv_scope_t *scope
) {
if (!scope) {
if (qvi_unlikely(!scope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -50,7 +50,7 @@ int
qv_scope_bind_pop(
qv_scope_t *scope
) {
if (!scope) {
if (qvi_unlikely(!scope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -65,7 +65,7 @@ qv_scope_bind_string(
qv_bind_string_format_t format,
char **str
) {
if (!scope || !str) {
if (qvi_unlikely(!scope || !str)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -78,7 +78,7 @@ int
qv_scope_free(
qv_scope_t *scope
) {
if (!scope) {
if (qvi_unlikely(!scope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -94,7 +94,7 @@ qv_scope_nobjs(
qv_hw_obj_type_t obj,
int *nobjs
) {
if (!scope || !nobjs) {
if (qvi_unlikely(!scope || !nobjs)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -108,7 +108,7 @@ qv_scope_taskid(
qv_scope_t *scope,
int *taskid
) {
if (!scope || !taskid) {
if (qvi_unlikely(!scope || !taskid)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -122,7 +122,7 @@ qv_scope_ntasks(
qv_scope_t *scope,
int *ntasks
) {
if (!scope || !ntasks) {
if (qvi_unlikely(!scope || !ntasks)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -135,7 +135,7 @@ int
qv_scope_barrier(
qv_scope_t *scope
) {
if (!scope) {
if (qvi_unlikely(!scope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -153,7 +153,7 @@ qv_scope_create(
qv_scope_create_hints_t hints,
qv_scope_t **subscope
) {
if (!scope || (nobjs < 0) || !subscope) {
if (qvi_unlikely(!scope || (nobjs < 0) || !subscope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -171,7 +171,7 @@ qv_scope_split(
int color,
qv_scope_t **subscope
) {
if (!scope || (npieces <= 0) | !subscope) {
if (qvi_unlikely(!scope || (npieces <= 0) | !subscope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -192,7 +192,7 @@ qv_scope_split_at(
int group_id,
qv_scope_t **subscope
) {
if (!scope || !subscope) {
if (qvi_unlikely(!scope || !subscope)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand All @@ -211,7 +211,7 @@ qv_scope_get_device_id(
qv_device_id_type_t id_type,
char **dev_id
) {
if (!scope || (dev_index < 0) || !dev_id) {
if (qvi_unlikely(!scope || (dev_index < 0) || !dev_id)) {
return QV_ERR_INVLD_ARG;
}
try {
Expand Down
6 changes: 3 additions & 3 deletions src/qvi-group-mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ struct qvi_group_mpi_s : public qvi_group_s {
gather(
qvi_bbuff_t *txbuff,
int root,
qvi_bbuff_t ***rxbuffs,
int *shared
bool *shared,
qvi_bbuff_t ***rxbuffs
) {
return qvi_mpi_group_gather_bbuffs(
mpi_group, txbuff, root, rxbuffs, shared
mpi_group, txbuff, root, shared, rxbuffs
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/qvi-group-omp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ struct qvi_group_omp_s : public qvi_group_s {
gather(
qvi_bbuff_t *txbuff,
int root,
qvi_bbuff_t ***rxbuffs,
int *shared
bool *shared,
qvi_bbuff_t ***rxbuffs
) {
return qvi_omp_group_gather_bbuffs(
th_group, txbuff, root, rxbuffs, shared
th_group, txbuff, root, shared, rxbuffs
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/qvi-group-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ struct qvi_group_process_s : public qvi_group_s {
gather(
qvi_bbuff_t *txbuff,
int root,
qvi_bbuff_t ***rxbuffs,
int *shared
bool *shared,
qvi_bbuff_t ***rxbuffs
) {
return qvi_process_group_gather_bbuffs(
proc_group, txbuff, root, rxbuffs, shared
proc_group, txbuff, root, shared, rxbuffs
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/qvi-group.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct qvi_group_s {
gather(
qvi_bbuff_t *txbuff,
int root,
qvi_bbuff_t ***rxbuffs,
int *shared
bool *shared,
qvi_bbuff_t ***rxbuffs
) = 0;
/** Scatters bbuffs from specified root. */
virtual int
Expand Down
6 changes: 3 additions & 3 deletions src/qvi-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ qvi_mpi_group_gather_bbuffs(
qvi_mpi_group_t *group,
qvi_bbuff_t *txbuff,
int root,
qvi_bbuff_t ***rxbuffs,
int *shared_alloc
bool *shared_alloc,
qvi_bbuff_t ***rxbuffs
) {
const int send_count = (int)qvi_bbuff_size(txbuff);
const int group_id = group->qvcomm.rank;
Expand Down Expand Up @@ -434,7 +434,7 @@ qvi_mpi_group_gather_bbuffs(
bbuffs = nullptr;
}
*rxbuffs = bbuffs;
*shared_alloc = 0;
*shared_alloc = false;
return rc;
}

Expand Down
4 changes: 2 additions & 2 deletions src/qvi-mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ qvi_mpi_group_gather_bbuffs(
qvi_mpi_group_t *group,
qvi_bbuff_t *txbuff,
int root,
qvi_bbuff_t ***rxbuffs,
int *shared_alloc
bool *shared_alloc,
qvi_bbuff_t ***rxbuffs
);

/**
Expand Down
20 changes: 9 additions & 11 deletions src/qvi-omp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,33 +212,31 @@ qvi_omp_group_gather_bbuffs(
qvi_omp_group_t *group,
qvi_bbuff_t *txbuff,
int,
qvi_bbuff_t ***rxbuffs,
int *shared_alloc
bool *shared_alloc,
qvi_bbuff_t ***rxbuffs
) {
const int group_size = group->size;
const int group_id = group->rank;
const int group_rank = group->rank;

qvi_bbuff_t **bbuffs = nullptr;
#pragma omp single copyprivate(bbuffs)
bbuffs = new qvi_bbuff_t *[group_size]();

const int rc = qvi_bbuff_dup(txbuff, &bbuffs[group_id]);
const int rc = qvi_bbuff_dup(txbuff, &bbuffs[group_rank]);
// Need to ensure that all threads have contributed to bbuffs.
#pragma omp barrier
if (rc != QV_SUCCESS) {
#pragma omp single
{
if (bbuffs) {
for (int i = 0; i < group_size; ++i) {
qvi_bbuff_free(&bbuffs[i]);
}
delete[] bbuffs;
if (bbuffs) {
for (int i = 0; i < group_size; ++i) {
qvi_bbuff_free(&bbuffs[i]);
}
delete[] bbuffs;
}
bbuffs = nullptr;
}
*rxbuffs = bbuffs;
*shared_alloc = 1;
*shared_alloc = true;
return rc;
}

Expand Down
6 changes: 3 additions & 3 deletions src/qvi-omp.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ int
qvi_omp_group_gather_bbuffs(
qvi_omp_group_t *group,
qvi_bbuff_t *txbuff,
int root,
qvi_bbuff_t ***rxbuffs,
int *shared_alloc
int,
bool *shared_alloc,
qvi_bbuff_t ***rxbuffs
);

int
Expand Down
Loading
Loading