Skip to content

Commit

Permalink
Remove task creation from the base group. (#234)
Browse files Browse the repository at this point in the history
Most infrastructure requires a single base task during construction, but
pthread infrastructure does not, so save a little memory by moving task
creation into infrastructure-specific construction.

Signed-off-by: Samuel K. Gutierrez <[email protected]>
  • Loading branch information
samuelkgutierrez authored Jul 19, 2024
1 parent 487a055 commit e848c8b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 23 deletions.
20 changes: 18 additions & 2 deletions src/qvi-group-mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,39 @@
#include "qvi-mpi.h"

struct qvi_group_mpi_s : public qvi_group_s {
protected:
/** Task associated with this group. */
qvi_task_t *m_task = nullptr;
/** Points to the base MPI context information. */
qvi_mpi_t *mpi = nullptr;
/** Underlying group instance. */
qvi_mpi_group_t *mpi_group = nullptr;
public:
/** Default constructor. */
qvi_group_mpi_s(void) = default;
qvi_group_mpi_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
/** 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_task_t *
task(void)
{
return m_task;
}

virtual int
Expand Down
17 changes: 16 additions & 1 deletion src/qvi-group-omp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,29 @@
#include "qvi-omp.h"

struct qvi_group_omp_s : public qvi_group_s {
protected:
/** Task associated with this group. */
qvi_task_t *m_task = nullptr;
/** Underlying group instance. */
qvi_omp_group_t *th_group = nullptr;
public:
/** Constructor. */
qvi_group_omp_s(void) = default;
qvi_group_omp_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
/** Destructor. */
virtual ~qvi_group_omp_s(void)
{
qvi_omp_group_free(&th_group);
qvi_delete(&m_task);
}

virtual qvi_task_t *
task(void)
{
return m_task;
}

virtual int
Expand Down
17 changes: 16 additions & 1 deletion src/qvi-group-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,29 @@
#include "qvi-process.h"

struct qvi_group_process_s : public qvi_group_s {
protected:
/** Task associated with this group. */
qvi_task_t *m_task = nullptr;
/** Underlying group instance. */
qvi_process_group_t *proc_group = nullptr;
public:
/** Constructor. */
qvi_group_process_s(void) = default;
qvi_group_process_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
/** Destructor. */
virtual ~qvi_group_process_s(void)
{
qvi_process_group_free(&proc_group);
qvi_delete(&m_task);
}

virtual qvi_task_t *
task(void)
{
return m_task;
}

virtual int
Expand Down
21 changes: 3 additions & 18 deletions src/qvi-group.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,13 @@ using qvi_group_id_t = uint64_t;
* Virtual base group class.
*/
struct qvi_group_s : qvi_refc_s {
protected:
// TODO(skg) Remove from base.
/** Task associated with this group. */
qvi_task_t *m_task = nullptr;
public:
/** Constructor. */
qvi_group_s(void)
{
const int rc = qvi_new(&m_task);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
qvi_group_s(void) = default;
/** Virtual destructor. */
virtual ~qvi_group_s(void)
{
qvi_delete(&m_task);
}
virtual ~qvi_group_s(void) = default;
/** Returns pointer to the caller's task information. */
virtual qvi_task_t *
task(void)
{
return m_task;
}
task(void) = 0;
/** Returns the caller's group rank. */
virtual int
rank(void) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/qvi-task.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct qvi_task_s {
/** Returns the caller's thread ID. */
static pid_t
mytid(void);
/** Default constructor. */
/** Constructor. */
qvi_task_s(void);
/** Copy constructor. */
qvi_task_s(const qvi_task_s &src) = delete;
Expand Down

0 comments on commit e848c8b

Please sign in to comment.