Skip to content

Commit fbe5c47

Browse files
committed
memory reduction
Signed-off-by: Howard Pritchard <[email protected]>
1 parent 23865b7 commit fbe5c47

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

ompi/communicator/comm_cid.c

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -312,38 +312,14 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
312312
{
313313
pmix_info_t *pinfo, *results = NULL;
314314
size_t nresults;
315-
opal_process_name_t *name_array, *rname_array, *tmp_name_array;
315+
opal_process_name_t opal_proc_name;
316316
bool cid_base_set = false;
317317
char *tag = NULL;
318-
size_t proc_count, rproc_count, cid_base = 0UL, ninfo;
318+
size_t proc_count = 0, rproc_count = 0, cid_base = 0UL, ninfo;
319319
int rc, leader_rank;
320320
pmix_proc_t *procs;
321321
void *grpinfo = NULL, *list = NULL;
322322
pmix_data_array_t darray;
323-
char tmp[PMIX_MAX_KEYLEN];
324-
325-
rc = ompi_group_to_proc_name_array (newcomm->c_local_group, &name_array, &proc_count);
326-
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
327-
return rc;
328-
}
329-
330-
if ( OMPI_COMM_IS_INTER (newcomm) ){
331-
rc = ompi_group_to_proc_name_array (newcomm->c_remote_group, &rname_array, &rproc_count);
332-
if (OPAL_UNLIKELY(OMPI_SUCCESS != rc)) {
333-
free (name_array);
334-
return rc;
335-
}
336-
tmp_name_array = (opal_process_name_t *)realloc(name_array, (proc_count + rproc_count) * sizeof(opal_process_name_t));
337-
if (NULL == tmp) {
338-
free(name_array);
339-
free(rname_array);
340-
return OMPI_ERR_OUT_OF_RESOURCE ;
341-
}
342-
name_array = tmp_name_array;
343-
memcpy(&name_array[proc_count], rname_array, rproc_count * sizeof(opal_process_name_t));
344-
proc_count += rproc_count;
345-
free(rname_array);
346-
}
347323

348324
switch (mode) {
349325
case OMPI_COMM_CID_GROUP_NEW:
@@ -404,13 +380,26 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
404380
ninfo = darray.size;
405381
PMIx_Info_list_release(grpinfo);
406382

407-
PMIX_PROC_CREATE(procs, proc_count);
383+
proc_count = newcomm->c_local_group->grp_proc_count;
384+
if ( OMPI_COMM_IS_INTER (newcomm) ){
385+
rproc_count = newcomm->c_remote_group->grp_proc_count;
386+
}
387+
388+
PMIX_PROC_CREATE(procs, proc_count + rproc_count);
389+
408390
for (size_t i = 0 ; i < proc_count; ++i) {
409-
OPAL_PMIX_CONVERT_NAME(&procs[i],&name_array[i]);
391+
opal_proc_name = ompi_group_get_proc_name(newcomm->c_local_group, i);
392+
OPAL_PMIX_CONVERT_NAME(&procs[i],&opal_proc_name);
410393
}
394+
for (size_t i = 0; i < rproc_count; ++i) {
395+
opal_proc_name = ompi_group_get_proc_name(newcomm->c_remote_group, i);
396+
OPAL_PMIX_CONVERT_NAME(&procs[proc_count+i],&opal_proc_name);
397+
}
398+
411399

412-
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));
413-
rc = PMIx_Group_construct(tag, procs, proc_count, pinfo, ninfo, &results, &nresults);
400+
OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "calling PMIx_Group_construct - tag %s size %ld ninfo %ld cid_base %ld\n",
401+
tag, proc_count + rproc_count, ninfo, cid_base));
402+
rc = PMIx_Group_construct(tag, procs, proc_count + rproc_count, pinfo, ninfo, &results, &nresults);
414403
PMIX_DATA_ARRAY_DESTRUCT(&darray);
415404
if(PMIX_SUCCESS != rc) {
416405
char msg_string[1024];
@@ -453,7 +442,8 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
453442
}
454443
}
455444

456-
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));
445+
OPAL_OUTPUT_VERBOSE((10, ompi_comm_output, "PMIx_Group_construct - tag %s size %ld ninfo %ld cid_base %ld\n",
446+
tag, proc_count + rproc_count, ninfo, cid_base));
457447

458448
/* destruct the group */
459449
rc = PMIx_Group_destruct (tag, NULL, 0);
@@ -482,11 +472,6 @@ static int ompi_comm_ext_cid_new_block (ompi_communicator_t *newcomm, ompi_commu
482472
procs = NULL;
483473
}
484474

485-
if(NULL != name_array) {
486-
free (name_array);
487-
name_array = NULL;
488-
}
489-
490475
return rc;
491476
}
492477

0 commit comments

Comments
 (0)