Skip to content

Commit

Permalink
Implement most of qv_scope_create().
Browse files Browse the repository at this point in the history
The only missing parts are the following:
* Adding hint support
* Adding the Fortran interface

Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez committed Apr 26, 2022
1 parent 24dd97b commit c460005
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/quo-vadis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ qv_scope_split_at(
return rc;
}

// TODO(skg) Add Fortran interface.
int
qv_scope_create(
qv_context_t *ctx,
Expand All @@ -295,7 +296,7 @@ qv_scope_create(

qv_scope_t *isubscope = nullptr;
int rc = qvi_scope_create(
scope, type, nobjs, hint, subscope
scope, type, nobjs, hint, &isubscope
);
if (rc != QV_SUCCESS) {
qvi_scope_free(&isubscope);
Expand Down
27 changes: 27 additions & 0 deletions src/qvi-group-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ qvi_group_mpi_s::barrier(void)
return qvi_mpi_group_barrier(mpi_group);
}

int
qvi_group_mpi_s::self(
qvi_group_t **child
) {
int rc = QV_SUCCESS;

qvi_group_mpi_t *ichild = qvi_new qvi_group_mpi_t();
if (!ichild) {
rc = QV_ERR_OOR;
goto out;
}
// Initialize the child with the parent's MPI instance.
rc = ichild->initialize(mpi);
if (rc != QV_SUCCESS) goto out;
// Create the underlying group using MPI_COMM_SELF.
rc = qvi_mpi_group_create_from_mpi_comm(
mpi, MPI_COMM_SELF, &ichild->mpi_group
);
out:
if (rc != QV_SUCCESS) {
delete ichild;
ichild = nullptr;
}
*child = ichild;
return rc;
}

int
qvi_group_mpi_s::split(
int color,
Expand Down
8 changes: 8 additions & 0 deletions src/qvi-group-mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ struct qvi_group_mpi_s : public qvi_group_s {
virtual int size(void);
/** Group barrier. */
virtual int barrier(void);
/**
* Creates a new self group with a single member: the caller.
* Returns the appropriate newly created child group to the caller.
*/
virtual int
self(
qvi_group_s **child
);
/**
* Creates new groups by splitting this group based on color, key.
* Returns the appropriate newly created child group to the caller.
Expand Down
19 changes: 14 additions & 5 deletions src/qvi-group-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ qvi_group_process_s::barrier(void)
}

int
qvi_group_process_s::split(
int,
int,
qvi_group_process_s::self(
qvi_group_t **child
) {
// NOTE: The concept of coloring with a provided
// key doesn't apply here, so ignore.
int rc = QV_SUCCESS;

qvi_group_process_t *ichild = qvi_new qvi_group_process_t();
Expand All @@ -86,6 +82,19 @@ qvi_group_process_s::split(
return rc;
}

int
qvi_group_process_s::split(
int,
int,
qvi_group_t **child
) {
// NOTE: The concept of coloring with a provided key doesn't apply here, so
// ignore. Also, because this is in the context of a process, the concept
// of splitting doesn't really apply here, so just create another process
// group, self will suffice.
return self(child);
}

int
qvi_group_process_s::gather(
qvi_bbuff_t *txbuff,
Expand Down
8 changes: 8 additions & 0 deletions src/qvi-group-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ struct qvi_group_process_s : public qvi_group_s {
virtual int size(void);
/** Group barrier. */
virtual int barrier(void);
/**
* Creates a new self group with a single member: the caller.
* Returns the appropriate newly created child group to the caller.
*/
virtual int
self(
qvi_group_s **child
);
/**
* Creates new groups by splitting this group based on color, key.
* Returns the appropriate newly created child group to the caller.
Expand Down
8 changes: 8 additions & 0 deletions src/qvi-group.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ struct qvi_group_s {
virtual int size(void) = 0;
/** Group barrier. */
virtual int barrier(void) = 0;
/**
* Creates a new self group with a single member: the caller.
* Returns the appropriate newly created child group to the caller.
*/
virtual int
self(
qvi_group_s **child
) = 0;
/**
* Creates new groups by splitting this group based on color, key.
* Returns the appropriate newly created child group to the caller.
Expand Down
34 changes: 21 additions & 13 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ qvi_scope_new(

qv_scope_t *iscope = qvi_new qv_scope_t();
if (!scope) rc = QV_ERR_OOR;
// hwpool and group will be initialized in qvi_scope_init().
// hwpool and group will be initialized in scope_init().
if (rc != QV_SUCCESS) qvi_scope_free(&iscope);
*scope = iscope;
return rc;
Expand Down Expand Up @@ -718,29 +718,30 @@ qvi_scope_split_at(

int
qvi_scope_create(
qv_scope_t *scope,
qv_scope_t *parent,
qv_hw_obj_type_t type,
int nobjs,
qv_scope_create_hint_t hint,
qv_scope_t **subscope
qv_scope_t **child
) {
// TODO(skg) Implement use of hints.
QVI_UNUSED(hint);

qv_scope_t *isubscope = nullptr;
hwloc_bitmap_t cpuset = nullptr;
qvi_group_t *group = nullptr;
qvi_hwpool_t *hwpool = nullptr;

qv_scope_t *ichild = nullptr;
hwloc_bitmap_t cpuset = nullptr;
// TODO(skg) We need to acquire these resources.
int rc = qvi_rmi_get_cpuset_for_nobjs(
scope->rmi,
qvi_hwpool_cpuset_get(scope->hwpool),
parent->rmi,
qvi_hwpool_cpuset_get(parent->hwpool),
type, nobjs, &cpuset
);
if (rc != QV_SUCCESS) {
goto out;
}
// Now that we have the desired cpuset, create
// a corresponding hardware and subscope.
// Now that we have the desired cpuset,
// create a corresponding hardware pool.
rc = qvi_hwpool_new(&hwpool);
if (rc != QV_SUCCESS) {
goto out;
Expand All @@ -750,13 +751,20 @@ qvi_scope_create(
if (rc != QV_SUCCESS) {
goto out;
}
// Create underlying group. Notice the use of self here.
rc = parent->group->self(&group);
// Create and initialize the new scope.
rc = qvi_scope_new(&ichild);
if (rc != QV_SUCCESS) goto out;

rc = scope_init(ichild, parent->rmi, group, hwpool);
out:
qvi_hwloc_bitmap_free(&cpuset);
if (rc != QV_SUCCESS) {
qvi_hwloc_bitmap_free(&cpuset);
qvi_hwpool_free(&hwpool);
qvi_scope_free(&isubscope);
qvi_scope_free(&ichild);
}
*subscope = isubscope;
*child = ichild;
return rc;
}

Expand Down
4 changes: 2 additions & 2 deletions src/qvi-scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ qvi_scope_split_at(
*/
int
qvi_scope_create(
qv_scope_t *scope,
qv_scope_t *parent,
qv_hw_obj_type_t type,
int nobjs,
qv_scope_create_hint_t hint,
qv_scope_t **subscope
qv_scope_t **child
);

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/test-mpi-scopes.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ main(

scope_report(ctx, wrank, sub_scope, "sub_scope");

if (wrank == 0) {
qv_scope_t *create_scope;
rc = qv_scope_create(
ctx, sub_scope, QV_HW_OBJ_CORE, 1, 0, &create_scope
);
if (rc != QV_SUCCESS) {
ers = "qv_scope_create() failed";
panic("%s (rc=%s)", ers, qv_strerr(rc));
}

int n_core;
rc = qv_scope_nobjs(
ctx,
create_scope,
QV_HW_OBJ_CORE,
&n_core
);
if (rc != QV_SUCCESS) {
ers = "qv_scope_nobjs() failed";
panic("%s (rc=%s)", ers, qv_strerr(rc));
}
printf("[%d] Number of cores in create_scope is %d\n", wrank, n_core);

scope_report(ctx, wrank, create_scope, "create_scope");

rc = qv_scope_free(ctx, create_scope);
if (rc != QV_SUCCESS) {
ers = "qv_scope_free() failed";
panic("%s (rc=%s)", ers, qv_strerr(rc));
}
}

char *binds;
rc = qv_bind_string(ctx, QV_BIND_STRING_AS_LIST, &binds);
if (rc != QV_SUCCESS) {
Expand Down

0 comments on commit c460005

Please sign in to comment.