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

Restructure some group code. #237

Merged
merged 1 commit into from
Jul 23, 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
33 changes: 27 additions & 6 deletions src/qvi-group-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,29 @@
*/

#include "qvi-group-mpi.h"
#include "qvi-task.h" // IWYU pragma: keep
#include "qvi-utils.h"

qvi_group_mpi_s::qvi_group_mpi_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}

qvi_group_mpi_s::qvi_group_mpi_s(
qvi_mpi_t *mpi_ctx
) : qvi_group_mpi_s()
{
if (!mpi_ctx) throw qvi_runtime_error();
m_mpi = mpi_ctx;
}

qvi_group_mpi_s::~qvi_group_mpi_s(void)
{
qvi_mpi_group_free(&m_mpi_group);
qvi_delete(&m_task);
}

int
qvi_group_mpi_s::make_intrinsic(
qv_scope_intrinsic_t scope
Expand All @@ -40,7 +61,7 @@ qvi_group_mpi_s::make_intrinsic(
if (rc != QV_SUCCESS) return rc;

return qvi_mpi_group_create_from_group_id(
mpi, mpi_group_type, &mpi_group
m_mpi, mpi_group_type, &m_mpi_group
);
}

Expand All @@ -50,11 +71,11 @@ qvi_group_mpi_s::self(
) {
// Create and initialize the child with the parent's MPI context.
qvi_group_mpi_t *ichild = nullptr;
int rc = qvi_new(&ichild, mpi);
int rc = qvi_new(&ichild, m_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
m_mpi, MPI_COMM_SELF, &ichild->m_mpi_group
);
out:
if (rc != QV_SUCCESS) {
Expand All @@ -72,12 +93,12 @@ qvi_group_mpi_s::split(
) {
// Create and initialize the child with the parent's MPI context.
qvi_group_mpi_t *ichild = nullptr;
int rc = qvi_new(&ichild, mpi);
int rc = qvi_new(&ichild, m_mpi);
if (rc != QV_SUCCESS) goto out;
// Split this group using MPI.
rc = qvi_mpi_group_create_from_split(
mpi, mpi_group, color,
key, &ichild->mpi_group
m_mpi, m_mpi_group, color,
key, &ichild->m_mpi_group
);
out:
if (rc != QV_SUCCESS) {
Expand Down
40 changes: 14 additions & 26 deletions src/qvi-group-mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,18 @@ struct qvi_group_mpi_s : public qvi_group_s {
/** Task associated with this group. */
qvi_task_t *m_task = nullptr;
/** Points to the base MPI context information. */
qvi_mpi_t *mpi = nullptr;
qvi_mpi_t *m_mpi = nullptr;
/** Underlying group instance. */
qvi_mpi_group_t *mpi_group = nullptr;
qvi_mpi_group_t *m_mpi_group = nullptr;
public:
/** Default constructor. */
qvi_group_mpi_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
qvi_group_mpi_s(void);
/** Constructor. */
qvi_group_mpi_s(
qvi_mpi_t *mpi_ctx
) : qvi_group_mpi_s()
{
if (!mpi_ctx) throw qvi_runtime_error();
mpi = mpi_ctx;
}
);
/** Destructor. */
virtual ~qvi_group_mpi_s(void)
{
qvi_mpi_group_free(&mpi_group);
qvi_delete(&m_task);
}
virtual ~qvi_group_mpi_s(void);

virtual qvi_task_t *
task(void)
Expand All @@ -60,19 +48,19 @@ struct qvi_group_mpi_s : public qvi_group_s {
virtual int
rank(void)
{
return qvi_mpi_group_id(mpi_group);
return qvi_mpi_group_id(m_mpi_group);
}

virtual int
size(void)
{
return qvi_mpi_group_size(mpi_group);
return qvi_mpi_group_size(m_mpi_group);
}

virtual int
barrier(void)
{
return qvi_mpi_group_barrier(mpi_group);
return qvi_mpi_group_barrier(m_mpi_group);
}

virtual int
Expand Down Expand Up @@ -100,7 +88,7 @@ struct qvi_group_mpi_s : public qvi_group_s {
qvi_bbuff_t ***rxbuffs
) {
return qvi_mpi_group_gather_bbuffs(
mpi_group, txbuff, root, shared, rxbuffs
m_mpi_group, txbuff, root, shared, rxbuffs
);
}

Expand All @@ -111,15 +99,15 @@ struct qvi_group_mpi_s : public qvi_group_s {
qvi_bbuff_t **rxbuff
) {
return qvi_mpi_group_scatter_bbuffs(
mpi_group, txbuffs, root, rxbuff
m_mpi_group, txbuffs, root, rxbuff
);
}
/** Returns a duplicate of the underlying MPI group communicator. */
int
comm_dup(
MPI_Comm *comm
) {
return qvi_mpi_group_comm_dup(mpi_group, comm);
return qvi_mpi_group_comm_dup(m_mpi_group, comm);
}
};
typedef qvi_group_mpi_s qvi_group_mpi_t;
Expand All @@ -131,16 +119,16 @@ struct qvi_zgroup_mpi_s : public qvi_group_mpi_s {
qvi_zgroup_mpi_s(
MPI_Comm comm
) {
int rc = qvi_mpi_new(&mpi);
int rc = qvi_mpi_new(&m_mpi);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
/** Initialize the MPI group with the provided communicator. */
rc = qvi_mpi_init(mpi, comm);
rc = qvi_mpi_init(m_mpi, comm);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
/** Destructor. */
virtual ~qvi_zgroup_mpi_s(void)
{
qvi_mpi_free(&mpi);
qvi_mpi_free(&m_mpi);
}
};

Expand Down
19 changes: 16 additions & 3 deletions src/qvi-group-omp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@
*/

#include "qvi-group-omp.h"
#include "qvi-task.h" // IWYU pragma: keep
#include "qvi-utils.h"
#include <omp.h>

qvi_group_omp_s::qvi_group_omp_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}

qvi_group_omp_s::~qvi_group_omp_s(void)
{
qvi_omp_group_free(&m_ompgroup);
qvi_delete(&m_task);
}

int
qvi_group_omp_s::make_intrinsic(
qv_scope_intrinsic_t
Expand All @@ -29,7 +42,7 @@ qvi_group_omp_s::make_intrinsic(
const int group_rank = omp_get_thread_num();
// NOTE: the provided scope doesn't affect how
// we create the thread group, so we ignore it.
return qvi_omp_group_new(group_size, group_rank, &th_group);
return qvi_omp_group_new(group_size, group_rank, &m_ompgroup);
}

int
Expand All @@ -42,7 +55,7 @@ qvi_group_omp_s::self(
int rc = qvi_new(&ichild);
if (rc != QV_SUCCESS) goto out;
// Create a group containing a single thread.
rc = qvi_omp_group_new(group_size, group_rank, &ichild->th_group);
rc = qvi_omp_group_new(group_size, group_rank, &ichild->m_ompgroup);
out:
if (rc != QV_SUCCESS) {
qvi_delete(&ichild);
Expand All @@ -62,7 +75,7 @@ qvi_group_omp_s::split(
if (rc != QV_SUCCESS) goto out;

rc = qvi_omp_group_create_from_split(
th_group, color, key, &ichild->th_group
m_ompgroup, color, key, &ichild->m_ompgroup
);
out:
if (rc != QV_SUCCESS) {
Expand Down
24 changes: 8 additions & 16 deletions src/qvi-group-omp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@ struct qvi_group_omp_s : public qvi_group_s {
/** Task associated with this group. */
qvi_task_t *m_task = nullptr;
/** Underlying group instance. */
qvi_omp_group_t *th_group = nullptr;
qvi_omp_group_t *m_ompgroup = nullptr;
public:
/** Constructor. */
qvi_group_omp_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
qvi_group_omp_s(void);
/** Destructor. */
virtual ~qvi_group_omp_s(void)
{
qvi_omp_group_free(&th_group);
qvi_delete(&m_task);
}
virtual ~qvi_group_omp_s(void);

virtual qvi_task_t *
task(void)
Expand All @@ -53,19 +45,19 @@ struct qvi_group_omp_s : public qvi_group_s {
virtual int
rank(void)
{
return qvi_omp_group_id(th_group);
return qvi_omp_group_id(m_ompgroup);
}

virtual int
size(void)
{
return qvi_omp_group_size(th_group);
return qvi_omp_group_size(m_ompgroup);
}

virtual int
barrier(void)
{
return qvi_omp_group_barrier(th_group);
return qvi_omp_group_barrier(m_ompgroup);
}

virtual int
Expand Down Expand Up @@ -102,7 +94,7 @@ struct qvi_group_omp_s : public qvi_group_s {
qvi_bbuff_t ***rxbuffs
) {
return qvi_omp_group_gather_bbuffs(
th_group, txbuff, root, shared, rxbuffs
m_ompgroup, txbuff, root, shared, rxbuffs
);
}

Expand All @@ -113,7 +105,7 @@ struct qvi_group_omp_s : public qvi_group_s {
qvi_bbuff_t **rxbuff
) {
return qvi_omp_group_scatter_bbuffs(
th_group, txbuffs, root, rxbuff
m_ompgroup, txbuffs, root, rxbuff
);
}
};
Expand Down
15 changes: 14 additions & 1 deletion src/qvi-group-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@
*/

#include "qvi-group-process.h"
#include "qvi-task.h" // IWYU pragma: keep
#include "qvi-utils.h"

qvi_group_process_s::qvi_group_process_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}

qvi_group_process_s::~qvi_group_process_s(void)
{
qvi_process_group_free(&m_proc_group);
qvi_delete(&m_task);
}

int
qvi_group_process_s::self(
qvi_group_t **child
Expand All @@ -23,7 +36,7 @@ qvi_group_process_s::self(
if (rc != QV_SUCCESS) goto out;
// Because this is in the context of a process, the concept of splitting
// doesn't really apply here, so just create another process group.
rc = qvi_process_group_new(&ichild->proc_group);
rc = qvi_process_group_new(&ichild->m_proc_group);
out:
if (rc != QV_SUCCESS) {
qvi_delete(&ichild);
Expand Down
26 changes: 9 additions & 17 deletions src/qvi-group-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ struct qvi_group_process_s : public qvi_group_s {
/** Task associated with this group. */
qvi_task_t *m_task = nullptr;
/** Underlying group instance. */
qvi_process_group_t *proc_group = nullptr;
qvi_process_group_t *m_proc_group = nullptr;
public:
/** Constructor. */
qvi_group_process_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
qvi_group_process_s(void);
/** Destructor. */
virtual ~qvi_group_process_s(void)
{
qvi_process_group_free(&proc_group);
qvi_delete(&m_task);
}
virtual ~qvi_group_process_s(void);

virtual qvi_task_t *
task(void)
Expand All @@ -47,19 +39,19 @@ struct qvi_group_process_s : public qvi_group_s {
virtual int
rank(void)
{
return qvi_process_group_id(proc_group);
return qvi_process_group_id(m_proc_group);
}

virtual int
size(void)
{
return qvi_process_group_size(proc_group);
return qvi_process_group_size(m_proc_group);
}

virtual int
barrier(void)
{
return qvi_process_group_barrier(proc_group);
return qvi_process_group_barrier(m_proc_group);
}

virtual int
Expand All @@ -68,7 +60,7 @@ struct qvi_group_process_s : public qvi_group_s {
) {
// NOTE: the provided scope doesn't affect how
// we create the process group, so we ignore it.
return qvi_process_group_new(&proc_group);
return qvi_process_group_new(&m_proc_group);
}

virtual int
Expand Down Expand Up @@ -97,7 +89,7 @@ struct qvi_group_process_s : public qvi_group_s {
qvi_bbuff_t ***rxbuffs
) {
return qvi_process_group_gather_bbuffs(
proc_group, txbuff, root, shared, rxbuffs
m_proc_group, txbuff, root, shared, rxbuffs
);
}

Expand All @@ -108,7 +100,7 @@ struct qvi_group_process_s : public qvi_group_s {
qvi_bbuff_t **rxbuff
) {
return qvi_process_group_scatter_bbuffs(
proc_group, txbuffs, root, rxbuff
m_proc_group, txbuffs, root, rxbuff
);
}
};
Expand Down
Loading
Loading