Skip to content

Commit

Permalink
memory reduction
Browse files Browse the repository at this point in the history
Signed-off-by: Howard Pritchard <[email protected]>
  • Loading branch information
hppritcha committed Aug 1, 2024
1 parent 23865b7 commit fbe5c47
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions ompi/communicator/comm_cid.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,38 +312,14 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
{
pmix_info_t *pinfo, *results = NULL;
size_t nresults;
opal_process_name_t *name_array, *rname_array, *tmp_name_array;
opal_process_name_t opal_proc_name;
bool cid_base_set = false;
char *tag = NULL;
size_t proc_count, rproc_count, cid_base = 0UL, ninfo;
size_t proc_count = 0, rproc_count = 0, cid_base = 0UL, ninfo;
int rc, leader_rank;
pmix_proc_t *procs;
void *grpinfo = NULL, *list = NULL;
pmix_data_array_t darray;
char tmp[PMIX_MAX_KEYLEN];

rc = ompi_group_to_proc_name_array (newcomm->c_local_group, &name_array, &proc_count);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
return rc;
}

if ( OMPI_COMM_IS_INTER (newcomm) ){
rc = ompi_group_to_proc_name_array (newcomm->c_remote_group, &rname_array, &rproc_count);
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
free (name_array);
return rc;
}
tmp_name_array = (opal_process_name_t *)realloc(name_array, (proc_count + rproc_count) * sizeof(opal_process_name_t));
if (NULL == tmp) {
free(name_array);
free(rname_array);
return OMPI_ERR_OUT_OF_RESOURCE ;
}
name_array = tmp_name_array;
memcpy(&name_array[proc_count], rname_array, rproc_count * sizeof(opal_process_name_t));
proc_count += rproc_count;
free(rname_array);
}

switch (mode) {
case OMPI_COMM_CID_GROUP_NEW:
Expand Down Expand Up @@ -404,13 +380,26 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
ninfo = darray.size;
PMIx_Info_list_release(grpinfo);

PMIX_PROC_CREATE(procs, proc_count);
proc_count = newcomm->c_local_group->grp_proc_count;
if ( OMPI_COMM_IS_INTER (newcomm) ){
rproc_count = newcomm->c_remote_group->grp_proc_count;
}

PMIX_PROC_CREATE(procs, proc_count + rproc_count);

for (size_t i = 0 ; i < proc_count; ++i) {
OPAL_PMIX_CONVERT_NAME(&procs[i],&name_array[i]);
opal_proc_name = ompi_group_get_proc_name(newcomm->c_local_group, i);
OPAL_PMIX_CONVERT_NAME(&procs[i],&opal_proc_name);
}
for (size_t i = 0; i < rproc_count; ++i) {
opal_proc_name = ompi_group_get_proc_name(newcomm->c_remote_group, i);
OPAL_PMIX_CONVERT_NAME(&procs[proc_count+i],&opal_proc_name);
}


OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "calling PMIx_Group_construct - tag %s size %ld ninfo %ld cid_base %ld\n", tag, proc_count, ninfo, cid_base));
rc = PMIx_Group_construct(tag, procs, proc_count, pinfo, ninfo, &results, &nresults);
OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "calling PMIx_Group_construct - tag %s size %ld ninfo %ld cid_base %ld\n",
tag, proc_count + rproc_count, ninfo, cid_base));
rc = PMIx_Group_construct(tag, procs, proc_count + rproc_count, pinfo, ninfo, &results, &nresults);
PMIX_DATA_ARRAY_DESTRUCT(&darray);
if(PMIX_SUCCESS != rc) {
char msg_string[1024];
Expand Down Expand Up @@ -453,7 +442,8 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
}
}

OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Group_construct - tag %s size %ld ninfo %ld cid_base %ld\n", tag, proc_count, ninfo, cid_base));
OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Group_construct - tag %s size %ld ninfo %ld cid_base %ld\n",
tag, proc_count + rproc_count, ninfo, cid_base));

/* destruct the group */
rc = PMIx_Group_destruct (tag, NULL, 0);
Expand Down Expand Up @@ -482,11 +472,6 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
procs = NULL;
}

if(NULL != name_array) {
free (name_array);
name_array = NULL;
}

return rc;
}

Expand Down

0 comments on commit fbe5c47

Please sign in to comment.