Skip to content

Commit

Permalink
Add qvi_bbuff_dup() and use it. (#223)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez committed Jul 13, 2024
1 parent bc214af commit 1b4a6b6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
4 changes: 3 additions & 1 deletion src/quo-vadis-omp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ qv_omp_scope_get(
qv_scope_intrinsic_t iscope,
qv_scope_t **scope
) {
if (!scope) return QV_ERR_INVLD_ARG;
if (!scope) {
return QV_ERR_INVLD_ARG;
}
try {
return qvi_omp_scope_get(iscope, scope);
}
Expand Down
4 changes: 3 additions & 1 deletion src/quo-vadis-pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ qv_pthread_scopes_free(
int nscopes,
qv_scope_t **scopes
) {
if (nscopes < 0 || !scopes) return QV_ERR_INVLD_ARG;
if (nscopes < 0 || !scopes) {
return QV_ERR_INVLD_ARG;
}
try {
qvi_scope_kfree(&scopes, nscopes);
return QV_SUCCESS;
Expand Down
16 changes: 16 additions & 0 deletions src/qvi-bbuff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ struct qvi_bbuff_s {
data = calloc(capacity, sizeof(byte_t));
if (!data) throw qvi_runtime_error();
}
/** Copy constructor. */
qvi_bbuff_s(
const qvi_bbuff_s &src
) : qvi_bbuff_s()
{
const int rc = qvi_bbuff_append(this, src.data, src.size);
if (rc != QV_SUCCESS) throw qvi_runtime_error();
}
/** Destructor. */
~qvi_bbuff_s(void)
{
Expand All @@ -47,6 +55,14 @@ qvi_bbuff_new(
return qvi_new(buff);
}

int
qvi_bbuff_dup(
const qvi_bbuff_t *const src,
qvi_bbuff_t **buff
) {
return qvi_dup(*src, buff);
}

void
qvi_bbuff_free(
qvi_bbuff_t **buff
Expand Down
6 changes: 6 additions & 0 deletions src/qvi-bbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ qvi_bbuff_new(
qvi_bbuff_t **buff
);

int
qvi_bbuff_dup(
const qvi_bbuff_t *const src,
qvi_bbuff_t **buff
);

/**
*
*/
Expand Down
22 changes: 3 additions & 19 deletions src/qvi-omp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,9 @@ qvi_omp_group_gather_bbuffs(
#pragma omp single copyprivate(bbuffs)
bbuffs = new qvi_bbuff_t *[group_size]();

int rc = qvi_bbuff_new(&bbuffs[group_id]);
if (rc != QV_SUCCESS) goto out;

rc = qvi_bbuff_append(
bbuffs[group_id], qvi_bbuff_data(txbuff), qvi_bbuff_size(txbuff)
);
if (rc != QV_SUCCESS) goto out;

const int rc = qvi_bbuff_dup(txbuff, &bbuffs[group_id]);
// Need to ensure that all threads have contributed to bbuffs.
#pragma omp barrier
out:
if (rc != QV_SUCCESS) {
#pragma omp single
{
Expand Down Expand Up @@ -263,20 +255,12 @@ qvi_omp_group_scatter_bbuffs(
#pragma omp master
*tmp = txbuffs;
#pragma omp barrier
const int group_id = group->rank;
qvi_bbuff_t *inbuff = (*tmp)[group_id];
const size_t data_size = qvi_bbuff_size(inbuff);
void *data = qvi_bbuff_data(inbuff);

qvi_bbuff_t *inbuff = (*tmp)[group->rank];
qvi_bbuff_t *mybbuff = nullptr;
int rc = qvi_bbuff_new(&mybbuff);
if (rc == QV_SUCCESS) {
rc = qvi_bbuff_append(mybbuff, data, data_size);
}
const int rc = qvi_bbuff_dup(inbuff, &mybbuff);
#pragma omp barrier
#pragma omp single
delete tmp;

if (rc != QV_SUCCESS) {
qvi_bbuff_free(&mybbuff);
}
Expand Down
16 changes: 2 additions & 14 deletions src/qvi-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,13 @@ qvi_process_group_gather_bbuffs(
if (root != 0 || group_size != 1) {
qvi_abort();
}

int rc = QV_SUCCESS;
std::vector<size_t> rxcounts = {qvi_bbuff_size(txbuff)};
// Zero initialize array of pointers to nullptr.
qvi_bbuff_t **bbuffs = new qvi_bbuff_t *[group_size]();

byte_t *bytepos = (byte_t *)qvi_bbuff_data(txbuff);
for (int i = 0; i < group_size; ++i) {
rc = qvi_bbuff_new(&bbuffs[i]);
if (rc != QV_SUCCESS) break;
rc = qvi_bbuff_append(bbuffs[i], bytepos, rxcounts[i]);
if (rc != QV_SUCCESS) break;
bytepos += rxcounts[i];
}
const int rc = qvi_bbuff_dup(txbuff, &bbuffs[0]);
if (rc != QV_SUCCESS) {
if (bbuffs) {
for (int i = 0; i < group_size; ++i) {
qvi_bbuff_free(&bbuffs[i]);
}
qvi_bbuff_free(&bbuffs[0]);
delete[] bbuffs;
}
bbuffs = nullptr;
Expand Down

0 comments on commit 1b4a6b6

Please sign in to comment.