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

Simplify process code. #200

Merged
merged 1 commit into from
Jul 8, 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
15 changes: 1 addition & 14 deletions src/qvi-group-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@
#include "qvi-group-process.h"
#include "qvi-utils.h"

int
qvi_group_process_s::make_intrinsic(
qv_scope_intrinsic_t
) {
// NOTE: the provided scope doesn't affect how
// we create the process group, so we ignore it.
return qvi_process_group_create(
proc, &proc_group
);
}

int
qvi_group_process_s::self(
qvi_group_t **child
Expand All @@ -34,9 +23,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_create(
proc, &ichild->proc_group
);
rc = qvi_process_group_new(&ichild->proc_group);
out:
if (rc != QV_SUCCESS) {
qvi_delete(&ichild);
Expand Down
18 changes: 7 additions & 11 deletions src/qvi-group-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

/**
* @file qvi-group-process.h
*
*/

#ifndef QVI_GROUP_PROCESS_H
Expand All @@ -20,21 +19,14 @@
#include "qvi-process.h"

struct qvi_group_process_s : public qvi_group_s {
/** Process instance. */
qvi_process_t *proc = nullptr;
/** Underlying group instance. */
qvi_process_group_t *proc_group = nullptr;
/** Constructor. */
qvi_group_process_s(void)
{
const int rc = qvi_process_new(&proc);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
qvi_group_process_s(void) = default;
/** Destructor. */
virtual ~qvi_group_process_s(void)
{
qvi_process_group_free(&proc_group);
qvi_process_free(&proc);
}

virtual int
Expand All @@ -57,8 +49,12 @@ struct qvi_group_process_s : public qvi_group_s {

virtual int
make_intrinsic(
qv_scope_intrinsic_t intrinsic
);
qv_scope_intrinsic_t
) {
// NOTE: the provided scope doesn't affect how
// we create the process group, so we ignore it.
return qvi_process_group_new(&proc_group);
}

virtual int
self(
Expand Down
95 changes: 6 additions & 89 deletions src/qvi-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,16 @@
*/

#include "qvi-process.h"
#include "qvi-task.h"
#include "qvi-bbuff.h"
#include "qvi-utils.h"
#include "qvi-group.h"

// Type definitions.
typedef qvi_group_id_t qvi_process_group_id_t;

using qvi_process_group_tab_t = std::unordered_map<
qvi_process_group_id_t, qvi_process_group_t
>;

struct qvi_process_group_s {
/** ID used for table lookups */
qvi_process_group_id_t tabid = 0;
/** ID (rank) in group */
int id = 0;
/** Size of group */
int size = 0;
/** Constructor. */
qvi_process_group_s(void) = default;
/** Destructor. */
~qvi_process_group_s(void) = default;
/** Size of group. This is fixed. */
static constexpr int size = 1;
/** ID (rank) in group. This is fixed. */
static constexpr int rank = 0;
};

struct qvi_process_s {
/** Maintains the next available group ID value. */
qvi_process_group_tab_t group_tab;
/** Constructor. */
qvi_process_s(void) = default;
/** Destructor. */
~qvi_process_s(void) = default;
};

/**
* Returns the next available group ID.
*/
static int
next_group_tab_id(
qvi_process_t *,
qvi_process_group_id_t *gid
) {
return qvi_group_t::next_id(gid);
}

int
qvi_process_new(
qvi_process_t **proc
) {
return qvi_new(proc);
}

void
qvi_process_free(
qvi_process_t **proc
) {
return qvi_delete(proc);
}

int
qvi_process_node_barrier(
qvi_process_t *
) {
// Nothing to do since process groups contain a single member.
return QV_SUCCESS;
}

int
qvi_process_group_new(
qvi_process_group_t **procgrp
Expand All @@ -92,38 +36,11 @@ qvi_process_group_free(
qvi_delete(procgrp);
}

int
qvi_process_group_create(
qvi_process_t *proc,
qvi_process_group_t **group
) {
qvi_process_group_t *igroup = nullptr;
qvi_process_group_id_t gtid;

int rc = next_group_tab_id(proc, &gtid);
if (rc != QV_SUCCESS) goto out;

rc = qvi_process_group_new(&igroup);
if (rc != QV_SUCCESS) goto out;

igroup->tabid = gtid;
igroup->id = 0;
igroup->size = 1;

proc->group_tab.insert({gtid, *igroup});
out:
if (rc != QV_SUCCESS) {
qvi_process_group_free(&igroup);
}
*group = igroup;
return QV_SUCCESS;
}

int
qvi_process_group_id(
const qvi_process_group_t *group
) {
return group->id;
return group->rank;
}

int
Expand Down
43 changes: 3 additions & 40 deletions src/qvi-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,15 @@
#define QVI_PROCESS_H

#include "qvi-common.h"
#include "qvi-bbuff.h"

#ifdef __cplusplus
extern "C" {
#endif

// Forward declarations.
struct qvi_process_s;
typedef struct qvi_process_s qvi_process_t;

struct qvi_process_group_s;
typedef struct qvi_process_group_s qvi_process_group_t;

/**
*
*/
int
qvi_process_new(
qvi_process_t **proc
);

/**
*
*/
void
qvi_process_free(
qvi_process_t **proc
);

/**
*
*/
int
qvi_process_node_barrier(
qvi_process_t *proc
);

/**
*
*/
int
qvi_process_group_size(
const qvi_process_group_t *group
);

/**
*
*/
Expand All @@ -80,17 +44,16 @@ qvi_process_group_free(
*
*/
int
qvi_process_group_id(
qvi_process_group_size(
const qvi_process_group_t *group
);

/**
*
*/
int
qvi_process_group_create(
qvi_process_t *proc,
qvi_process_group_t **group
qvi_process_group_id(
const qvi_process_group_t *group
);

/**
Expand Down
Loading