Skip to content

Commit

Permalink
Restructure scope code. (#259)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez authored Jul 27, 2024
1 parent 3adb1cd commit 56e3529
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 328 deletions.
2 changes: 1 addition & 1 deletion include/quo-vadis.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ qv_scope_nobjs(
int
qv_scope_taskid(
qv_scope_t *scope,
int *taskid
int *rank
);

/**
Expand Down
7 changes: 2 additions & 5 deletions src/quo-vadis-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ qvi_mpi_scope_get(
const int rc = qvi_new(&izgroup, comm);
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;

return qvi_scope_get(izgroup, iscope, scope);
return qv_scope_s::makei(izgroup, iscope, scope);
}

int
Expand All @@ -87,10 +87,7 @@ qvi_mpi_scope_comm_dup(
qv_scope_t *scope,
MPI_Comm *comm
) {
qvi_group_mpi_t *const mpi_group = dynamic_cast<qvi_group_mpi_t *>(
qvi_scope_group(scope)
);
return mpi_group->comm_dup(comm);
return dynamic_cast<qvi_group_mpi_t *>(scope->group())->comm_dup(comm);
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/quo-vadis-omp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ qvi_omp_scope_get(
*scope = nullptr;
return rc;
}
return qvi_scope_get(zgroup, iscope, scope);
return qv_scope_s::makei(zgroup, iscope, scope);
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/quo-vadis-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ qvi_process_scope_get(
*scope = nullptr;
return rc;
}
return qvi_scope_get(zgroup, iscope, scope);
return qv_scope_s::makei(zgroup, iscope, scope);
}

int
Expand Down
16 changes: 8 additions & 8 deletions src/quo-vadis-pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ qvi_pthread_routine(
void *arg
) {
qvi_pthread_args_s *arg_ptr = (qvi_pthread_args_s *)arg;
qvi_scope_bind_push(arg_ptr->scope);
// TODO(skg) Check return code.
arg_ptr->scope->bind_push();

void *const ret = arg_ptr->th_routine(arg_ptr->th_routine_argp);
qvi_delete(&arg_ptr);
Expand All @@ -66,9 +67,8 @@ qv_pthread_scope_split(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_thsplit(
scope, npieces, color_array, nthreads,
QV_HW_OBJ_LAST, subscope
return scope->thsplit(
npieces, color_array, nthreads, QV_HW_OBJ_LAST, subscope
);
}
qvi_catch_and_return();
Expand All @@ -86,8 +86,8 @@ qv_pthread_scope_split_at(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_thsplit_at(
scope, type, color_array, nthreads, subscopes
return scope->thsplit_at(
type, color_array, nthreads, subscopes
);
}
qvi_catch_and_return();
Expand All @@ -108,7 +108,7 @@ qv_pthread_create(
// pthread_create(), return a reasonable errno.
if (qvi_unlikely(rc != QV_SUCCESS)) return ENOMEM;

auto group = dynamic_cast<qvi_group_pthread_t *>(qvi_scope_group(scope));
auto group = dynamic_cast<qvi_group_pthread_t *>(scope->group());
qvi_pthread_group_pthread_create_args_s *cargs = nullptr;
rc = qvi_new(&cargs, group->thgroup, qvi_pthread_routine, arg_ptr);
if (qvi_unlikely(rc != QV_SUCCESS)) {
Expand All @@ -129,7 +129,7 @@ qv_pthread_scopes_free(
return QV_ERR_INVLD_ARG;
}
try {
qvi_scope_thdelete(&scopes, nscopes);
qv_scope_s::thdel(&scopes, nscopes);
return QV_SUCCESS;
}
qvi_catch_and_return();
Expand Down
39 changes: 17 additions & 22 deletions src/quo-vadis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ qv_scope_bind_push(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_bind_push(scope);
return scope->bind_push();
}
qvi_catch_and_return();
}
Expand All @@ -54,7 +54,7 @@ qv_scope_bind_pop(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_bind_pop(scope);
return scope->bind_pop();
}
qvi_catch_and_return();
}
Expand All @@ -69,7 +69,7 @@ qv_scope_bind_string(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_bind_string(scope, format, str);
return scope->bind_string(format, str);
}
qvi_catch_and_return();
}
Expand All @@ -82,7 +82,7 @@ qv_scope_free(
return QV_ERR_INVLD_ARG;
}
try {
qvi_scope_delete(&scope);
qv_scope_s::del(&scope);
return QV_SUCCESS;
}
qvi_catch_and_return();
Expand All @@ -98,7 +98,8 @@ qv_scope_nobjs(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_nobjects(scope, obj, nobjs);
*nobjs = scope->nobjects(obj);
return QV_SUCCESS;
}
qvi_catch_and_return();
}
Expand All @@ -107,13 +108,14 @@ qv_scope_nobjs(
int
qv_scope_taskid(
qv_scope_t *scope,
int *taskid
int *rank
) {
if (qvi_unlikely(!scope || !taskid)) {
if (qvi_unlikely(!scope || !rank)) {
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_group_rank(scope, taskid);
*rank = scope->group_rank();
return QV_SUCCESS;
}
qvi_catch_and_return();
}
Expand All @@ -128,7 +130,8 @@ qv_scope_ntasks(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_group_size(scope, ntasks);
*ntasks = scope->group_size();
return QV_SUCCESS;
}
qvi_catch_and_return();
}
Expand All @@ -141,7 +144,7 @@ qv_scope_barrier(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_barrier(scope);
return scope->barrier();
}
qvi_catch_and_return();
}
Expand All @@ -159,9 +162,7 @@ qv_scope_create(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_create(
scope, type, nobjs, hints, subscope
);
return scope->create(type, nobjs, hints, subscope);
}
qvi_catch_and_return();
}
Expand All @@ -180,9 +181,7 @@ qv_scope_split(
// We use the sentinel value QV_HW_OBJ_LAST to differentiate between
// calls from split() and split_at(). Since this call doesn't have a
// hardware type argument, we use QV_HW_OBJ_LAST as the hardware type.
return qvi_scope_split(
scope, npieces, color, QV_HW_OBJ_LAST, subscope
);
return scope->split(npieces, color, QV_HW_OBJ_LAST, subscope);
}
qvi_catch_and_return();
}
Expand All @@ -198,9 +197,7 @@ qv_scope_split_at(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_split_at(
scope, type, group_id, subscope
);
return scope->split_at(type, group_id, subscope);
}
qvi_catch_and_return();
}
Expand All @@ -217,9 +214,7 @@ qv_scope_get_device_id(
return QV_ERR_INVLD_ARG;
}
try {
return qvi_scope_device_id(
scope, dev_obj, dev_index, id_type, dev_id
);
return scope->device_id(dev_obj, dev_index, id_type, dev_id);
}
qvi_catch_and_return();
}
Expand Down
Loading

0 comments on commit 56e3529

Please sign in to comment.