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

Cleanup some code. #249

Merged
merged 1 commit into from
Jul 26, 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
29 changes: 16 additions & 13 deletions src/qvi-bbuff-rmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* c = qvi_hwloc_bitmap_s
* d = qv_scope_create_hints_t
* h = qvi_hwpool_s *
* h = qvi_line_hwpool_t *
* i = int
* s = char *
* s = std::string
Expand Down Expand Up @@ -552,7 +551,7 @@ qvi_bbuff_rmi_pack_item_impl(
qvi_bbuff_t *buff,
const qvi_hwpool_s *data
) {
return data->pack(buff);
return data->packto(buff);
}

/**
Expand Down Expand Up @@ -672,7 +671,7 @@ qvi_bbuff_rmi_unpack_item(
size_t *bytes_written
) {
const int nw = asprintf(s, "%s", buffpos);
if (nw == -1) {
if (qvi_unlikely(nw == -1)) {
*s = nullptr;
*bytes_written = 0;
return QV_ERR_OOR;
Expand Down Expand Up @@ -762,7 +761,8 @@ qvi_bbuff_rmi_unpack_item(

void **dbuff = data.first;
*dbuff = calloc(*dsize, sizeof(byte_t));
if (!*dbuff) {
if (qvi_unlikely(!*dbuff)) {
*bytes_written = 0;
return QV_ERR_OOR;
}
memmove(*dbuff, buffpos, *dsize);
Expand All @@ -781,17 +781,17 @@ qvi_bbuff_rmi_unpack_item(
size_t *bytes_written
) {
int rc = qvi_hwloc_bitmap_calloc(cpuset);
if (rc != QV_SUCCESS) return rc;
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;

char *cpusets = (char *)buffpos;
char *const cpusets = (char *)buffpos;
// Protect against empty data.
if (strcmp(QV_BUFF_RMI_NULL_CPUSET, cpusets) != 0) {
rc = qvi_hwloc_bitmap_sscanf(*cpuset, cpusets);
if (rc != QV_SUCCESS) goto out;
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
}
*bytes_written = strlen(cpusets) + 1;
out:
if (rc != QV_SUCCESS) {
if (qvi_unlikely(rc != QV_SUCCESS)) {
qvi_hwloc_bitmap_delete(cpuset);
}
return rc;
Expand All @@ -810,8 +810,11 @@ qvi_bbuff_rmi_unpack_item(
int rc = qvi_bbuff_rmi_unpack_item(
&raw_cpuset, buffpos, bytes_written
);
if (rc != QV_SUCCESS) return rc;

if (qvi_unlikely(rc != QV_SUCCESS)) {
*bytes_written = 0;
return rc;
}
//
rc = bitmap.set(raw_cpuset);
qvi_hwloc_bitmap_delete(&raw_cpuset);
return rc;
Expand Down Expand Up @@ -844,17 +847,17 @@ qvi_bbuff_rmi_unpack_item(
int rc = qvi_bbuff_rmi_unpack_item(
&cpu.hints, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
buffpos += bw;
// Unpack bitmap.
rc = qvi_bbuff_rmi_unpack_item(
cpu.cpuset, buffpos, &bw
);
if (rc != QV_SUCCESS) goto out;
if (qvi_unlikely(rc != QV_SUCCESS)) goto out;
total_bw += bw;
out:
if (rc != QV_SUCCESS) {
if (qvi_unlikely(rc != QV_SUCCESS)) {
total_bw = 0;
}
*bytes_written = total_bw;
Expand Down
2 changes: 1 addition & 1 deletion src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ qvi_hwpool_s::release_devices(void)
}

int
qvi_hwpool_s::pack(
qvi_hwpool_s::packto(
qvi_bbuff_t *buff
) const {
// Pack the CPU.
Expand Down
4 changes: 2 additions & 2 deletions src/qvi-hwpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ struct qvi_hwpool_s {
int
release_devices(void);
/**
* Packs the instance into a bbuff.
* Packs the instance into the provided buffer.
*/
int
pack(
packto(
qvi_bbuff_t *buff
) const;
/**
Expand Down
24 changes: 12 additions & 12 deletions src/qvi-mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ struct qvi_mpi_comm_s {
int rc;
if (dup) {
rc = MPI_Comm_dup(comm, &mpi_comm);
if (rc != MPI_SUCCESS) throw qvi_runtime_error();
if (qvi_unlikely(rc != MPI_SUCCESS)) {
throw qvi_runtime_error();
}
}
else {
mpi_comm = comm;
}
rc = MPI_Comm_size(mpi_comm, &size);
if (rc != MPI_SUCCESS) throw qvi_runtime_error();
if (qvi_unlikely(rc != MPI_SUCCESS)) throw qvi_runtime_error();
rc = MPI_Comm_rank(mpi_comm, &rank);
if (rc != MPI_SUCCESS) throw qvi_runtime_error();
if (qvi_unlikely(rc != MPI_SUCCESS)) throw qvi_runtime_error();
}
/** Destructor. */
~qvi_mpi_comm_s(void) = default;
Expand Down Expand Up @@ -97,7 +99,7 @@ struct qvi_mpi_s {
// Marker used to differentiate between intrinsic and automatic IDs.
if (given_id == QVI_MPI_GROUP_NULL) {
const int rc = qvi_group_t::next_id(&gid);
if (rc != QV_SUCCESS) return rc;
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
}
group_tab.insert({gid, group});
return QV_SUCCESS;
Expand Down Expand Up @@ -130,7 +132,7 @@ mpi_comm_to_new_node_comm(
comm, MPI_COMM_TYPE_SHARED,
0, MPI_INFO_NULL, node_comm
);
if (rc != MPI_SUCCESS) {
if (qvi_unlikely(rc != MPI_SUCCESS)) {
qvi_log_error("MPI_Comm_split_type(MPI_COMM_TYPE_SHARED) failed");
*node_comm = MPI_COMM_NULL;
return QV_ERR_MPI;
Expand All @@ -156,7 +158,7 @@ qvi_mpi_group_comm_dup(
MPI_Comm *comm
) {
const int rc = MPI_Comm_dup(group->qvcomm.mpi_comm, comm);
if (rc != MPI_SUCCESS) return QV_ERR_MPI;
if (qvi_unlikely(rc != MPI_SUCCESS)) return QV_ERR_MPI;
return QV_SUCCESS;
}

Expand All @@ -171,7 +173,7 @@ create_intrinsic_comms(
// Create node communicator.
MPI_Comm node_comm = MPI_COMM_NULL;
const int rc = mpi_comm_to_new_node_comm(comm, &node_comm);
if (rc != QV_SUCCESS) return rc;
if (qvi_unlikely(rc != QV_SUCCESS)) return rc;
// MPI_COMM_SELF duplicate.
mpi->self_comm = qvi_mpi_comm_s(MPI_COMM_SELF, true);
// Node communicator, no duplicate necessary here: created above.
Expand Down Expand Up @@ -339,12 +341,12 @@ sleepy_node_barrier(
) {
MPI_Request request;
int rc = MPI_Ibarrier(node_comm, &request);
if (rc != MPI_SUCCESS) return QV_ERR_MPI;
if (qvi_unlikely(rc != MPI_SUCCESS)) return QV_ERR_MPI;

int done = 0;
do {
rc = MPI_Test(&request, &done, MPI_STATUS_IGNORE);
if (rc != MPI_SUCCESS) return QV_ERR_MPI;
if (qvi_unlikely(rc != MPI_SUCCESS)) return QV_ERR_MPI;
usleep(50000);
} while (!done);

Expand Down Expand Up @@ -411,9 +413,7 @@ qvi_mpi_group_gather_bbuffs(
}
// Root creates new buffers from data gathered from each participant.
if (group_id == root) {
// Zero initialize array of pointers to nullptr.
bbuffs = new qvi_bbuff_t *[group_size]();
// TODO(skg) Use dup.
bbuffs = new qvi_bbuff_t *[group_size];
byte_t *bytepos = allbytes.data();
for (int i = 0; i < group_size; ++i) {
rc = qvi_bbuff_new(&bbuffs[i]);
Expand Down
Loading
Loading