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

Fix defects found in Coverity Scan for MPICH-CH4 #6745

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/include/mpir_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ MPL_STATIC_INLINE_PREFIX int MPIR_GPU_query_pointer_attr(const void *ptr, MPL_po
} else {
attr->type = MPL_GPU_POINTER_UNREGISTERED_HOST;
attr->device = MPL_GPU_DEVICE_INVALID;
attr->device_attr = 0;
}

fn_exit:
Expand Down
17 changes: 8 additions & 9 deletions src/mpi/coll/algorithms/treealgo/treeutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ int MPII_Treeutil_tree_kary_init_topo_aware(int rank, int nranks, int k0, int k1
utarray_new(ct->children, &ut_int_icd, MPL_MEM_COLL);
ct->num_children = 0;

MPIR_Assert(nranks >= 0);

if (nranks == 0)
goto fn_exit;

lrank = (rank + (nranks - root)) % nranks;

ct->parent = (lrank == 0) ? -1 : (((lrank + k1 - k0 - 1) / k1) + root) % nranks;
Expand Down Expand Up @@ -291,7 +286,8 @@ int MPII_Treeutil_tree_knomial_2_init(int rank, int nranks, int k, int root,
for (i = k - 1; i >= 1; i--) {
child = MPL_setdigit(k, lrank, j, i);
if (child < nranks)
tree_add_child(ct, (child + root) % nranks);
mpi_errno = tree_add_child(ct, (child + root) % nranks);
MPIR_ERR_CHECK(mpi_errno);
}
}
}
Expand Down Expand Up @@ -757,8 +753,9 @@ int MPII_Treeutil_tree_topology_aware_k_init(MPIR_Comm * comm, int k, int root,
/* rank level - build a tree on the ranks */
/* Do an allgather to know the current num_children on each rank */
MPIR_Errflag_t errflag = MPIR_ERR_NONE;
MPIR_Allgather_impl(&(ct->num_children), 1, MPI_INT, num_childrens, 1, MPI_INT,
comm, errflag);
mpi_errno =
MPIR_Allgather_impl(&(ct->num_children), 1, MPI_INT, num_childrens, 1, MPI_INT,
comm, errflag);
if (mpi_errno) {
goto fn_fail;
}
Expand Down Expand Up @@ -1064,6 +1061,7 @@ static int init_root_switch(const UT_array * hierarchy, heap_vector * minHeaps,
for (int sw_idx = 0; sw_idx < utarray_len(&gr_level->child_idxs); sw_idx++) {
int sw_child_idx = tree_ut_int_elt(&gr_level->child_idxs, sw_idx);
sw_level = tree_ut_hierarchy_eltptr(&hierarchy[0], sw_child_idx);
MPIR_Assert(sw_level != NULL);
if (sw_level->has_root) {
*root_gr_sorted_idx = wr_level->root_sorted_idx;
*root_sw_sorted_idx = gr_level->root_sorted_idx;
Expand Down Expand Up @@ -1214,7 +1212,8 @@ int MPII_Treeutil_tree_topology_wave_init(MPIR_Comm * comm, int k, int root, boo
/* free memory */
for (dim = 0; dim <= MPIR_Process.coords_dims - 1; ++dim)
utarray_done(&hierarchy[dim]);
utarray_free(unv_set);
if (unv_set != NULL)
utarray_free(unv_set);
for (int i = 0; i < minHeaps.total; i++)
deleteMinHeap(&minHeaps.heap[i]);
heap_vector_free(&minHeaps);
Expand Down
25 changes: 14 additions & 11 deletions src/util/mpir_pmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,40 +856,44 @@ static void free_pmi_keyvals(INFO_TYPE ** kv, int size, int *counts)
static int parse_coord_file(const char *filename)
{
int mpi_errno = MPI_SUCCESS;
int i, j, rank;
int i, j, rank, coords_dims;
FILE *coords_file;
int fields_scanned;

coords_file = fopen(filename, "r");
MPIR_ERR_CHKANDJUMP1(NULL == coords_file, mpi_errno, MPI_ERR_FILE,
"**filenoexist", "**filenoexist %s", filename);

/* Skip the first line */
fields_scanned = fscanf(coords_file, "%*[^\n]\n");
MPIR_Process.coords_dims = 0;
int fields_scanned = fscanf(coords_file, "%*[^\n]\n");
MPIR_ERR_CHKANDSTMT2(0 != fields_scanned, mpi_errno, MPI_ERR_FILE, goto fn_fail_read,
"**read_file", "**read_file %s %s", filename, strerror(errno));
coords_dims = 0;
fields_scanned = fscanf(coords_file, "%d:", &rank);
MPIR_ERR_CHKANDSTMT2(1 != fields_scanned, mpi_errno, MPI_ERR_FILE, goto fn_fail_read,
"**read_file", "**read_file %s %s", filename, strerror(errno));
while (!feof(coords_file)) {
int temp = 0;
if (fscanf(coords_file, "%d", &temp) == 1)
++MPIR_Process.coords_dims;
++coords_dims;
else
break;
if (fgetc(coords_file) == '\n')
break;
}

MPIR_Assert(MPIR_Process.coords_dims == 3);
MPIR_Assert(coords_dims == 3);
MPIR_Process.coords_dims = coords_dims;
rewind(coords_file);
/* Skip the first line */
fields_scanned = fscanf(coords_file, "%*[^\n]\n");
MPIR_ERR_CHKANDSTMT2(0 != fields_scanned, mpi_errno, MPI_ERR_FILE, goto fn_fail_read,
"**read_file", "**read_file %s %s", filename, strerror(errno));

if (MPIR_Process.coords == NULL) {
MPIR_Process.coords =
MPL_malloc(MPIR_Process.coords_dims * sizeof(int) * MPIR_Process.size, MPL_MEM_COLL);
MPL_malloc(coords_dims * sizeof(int) * MPIR_Process.size, MPL_MEM_COLL);
}
memset(MPIR_Process.coords, -1, MPIR_Process.coords_dims * sizeof(int) * MPIR_Process.size);
memset(MPIR_Process.coords, -1, coords_dims * sizeof(int) * MPIR_Process.size);

for (i = 0; i < MPIR_Process.size; ++i) {
fields_scanned = fscanf(coords_file, "%d:", &rank);
Expand All @@ -901,12 +905,11 @@ static int parse_coord_file(const char *filename)
rank, MPIR_Process.size);
continue;
}
for (j = 0; j < MPIR_Process.coords_dims; ++j) {
for (j = 0; j < coords_dims; ++j) {
/* MPIR_Process.coords stores the coords in this order: port number, switch_id, group_id */
fields_scanned =
fscanf(coords_file, "%d",
&MPIR_Process.coords[rank * MPIR_Process.coords_dims +
MPIR_Process.coords_dims - 1 - j]);
&MPIR_Process.coords[rank * coords_dims + coords_dims - 1 - j]);
MPIR_ERR_CHKANDSTMT2(1 != fields_scanned, mpi_errno, MPI_ERR_FILE, goto fn_fail_read,
"**read_file", "**read_file %s %s", filename, strerror(errno));
}
Expand Down
15 changes: 7 additions & 8 deletions src/util/mpir_pmix.inc
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,16 @@ static int pmix_init(int *has_parent, int *rank, int *size, int *appnum)
MPIR_Assert(pvalue->data.uint32 <= INT_MAX); /* overflow check */
*appnum = (int) pvalue->data.uint32;
PMIX_VALUE_RELEASE(pvalue);
pmix_value_t value;
pmix_value_t *val = &value;

for (int i = 0; i < *size; i++) {
pmix_proc.rank = i;
pmi_errno = PMIx_Get(&pmix_proc, PMIX_FABRIC_COORDINATES, NULL, 0, &val);
pmi_errno = PMIx_Get(&pmix_proc, PMIX_FABRIC_COORDINATES, NULL, 0, &pvalue);
if (pmi_errno != PMIX_SUCCESS) {
MPIR_Process.coords = NULL;
break;
}
MPIR_Assert(val->data.coord->dims <= INT_MAX);
MPIR_Process.coords_dims = (int) val->data.coord->dims;
MPIR_Assert(pvalue->data.coord->dims <= INT_MAX);
MPIR_Process.coords_dims = (int) pvalue->data.coord->dims;
MPIR_Assert(MPIR_Process.coords_dims == 3);

if (i == 0) {
Expand All @@ -118,13 +116,14 @@ static int pmix_init(int *has_parent, int *rank, int *size, int *appnum)
MPIR_ERR_CHKANDJUMP(!MPIR_Process.coords, mpi_errno, MPI_ERR_OTHER, "**nomem");
}

if (PMIX_COORD == val->type) {
if (PMIX_COORD == pvalue->type) {
for (int j = 0; j < MPIR_Process.coords_dims; j++) {
/* MPIR_Process.coords stores the coords in this order: port number, switch_id, group_id */
/* MPIR_Process.coords is in this order: port number, switch_id, group_id */
MPIR_Process.coords[i * MPIR_Process.coords_dims + j] =
val->data.coord->coord[MPIR_Process.coords_dims - 1 - j];
pvalue->data.coord->coord[MPIR_Process.coords_dims - 1 - j];
}
}
PMIX_VALUE_RELEASE(pvalue);
}

fn_exit:
Expand Down