Skip to content

Commit a210f80

Browse files
committed
Cleanup ompi/dpm operations
Do some code cleanup in the connect/accept code. Ensure that the OMPI layer has access to the PMIx identifier for the process. Add macros for converting PMIx names to/from strings. Cleanup a few of the simple test programs. Add a little more info to a btl/tcp error message. Signed-off-by: Ralph Castain <rhc@pmix.org>
1 parent 2c0b9bd commit a210f80

File tree

9 files changed

+143
-163
lines changed

9 files changed

+143
-163
lines changed

ompi/dpm/dpm.c

Lines changed: 54 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
106106
pmix_proc_t *procs, pxproc;
107107
size_t nprocs, n;
108108
pmix_status_t pret;
109-
opal_namelist_t *nm;
110-
opal_jobid_t jobid;
109+
opal_proclist_t *plt;
111110

112111
ompi_communicator_t *newcomp=MPI_COMM_NULL;
113112
ompi_proc_t *proc;
@@ -131,24 +130,14 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
131130
* procs is used to complete construction of the intercommunicator. */
132131

133132
/* everyone constructs the list of members from their communicator */
133+
pname.jobid = OMPI_PROC_MY_NAME->jobid;
134+
pname.vpid = OPAL_VPID_WILDCARD;
134135
if (MPI_COMM_WORLD == comm) {
135-
pname.jobid = OMPI_PROC_MY_NAME->jobid;
136-
pname.vpid = OPAL_VPID_WILDCARD;
137-
rc = opal_convert_process_name_to_string(&nstring, &pname);
138-
if (OPAL_SUCCESS != rc) {
139-
return OMPI_ERROR;
140-
}
136+
PMIX_LOAD_PROCID(&pxproc, ompi_process_info.myprocid.nspace, PMIX_RANK_WILDCARD);
137+
OPAL_PMIX_CONVERT_PROCT_TO_STRING(&nstring, &pxproc);
141138
opal_argv_append_nosize(&members, nstring);
142139
free(nstring);
143-
/* have to add the number of procs in the job so the remote side
144-
* can correctly add the procs by computing their names, and our nspace
145-
* so they can update their records */
146-
nstring = opal_jobid_print(pname.jobid);
147-
if (NULL == nstring) {
148-
opal_argv_free(members);
149-
return OMPI_ERROR;
150-
}
151-
opal_argv_append_nosize(&members, nstring);
140+
/* add the number of procs in this job */
152141
(void)opal_asprintf(&nstring, "%d", size);
153142
opal_argv_append_nosize(&members, nstring);
154143
free(nstring);
@@ -176,22 +165,10 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
176165
} else {
177166
proc_name = proc_list[i]->super.proc_name;
178167
}
179-
rc = opal_convert_process_name_to_string(&nstring, &proc_name);
180-
if (OPAL_SUCCESS != rc) {
181-
if (!dense) {
182-
free(proc_list);
183-
proc_list = NULL;
184-
}
185-
return OMPI_ERROR;
186-
}
168+
OPAL_PMIX_CONVERT_NAME(&pxproc, &proc_name);
169+
OPAL_PMIX_CONVERT_PROCT_TO_STRING(&nstring, &pxproc);
187170
opal_argv_append_nosize(&members, nstring);
188171
free(nstring);
189-
nstring = opal_jobid_print(pname.jobid);
190-
if (OPAL_SUCCESS != rc) {
191-
opal_argv_free(members);
192-
return OMPI_ERROR;
193-
}
194-
opal_argv_append_nosize(&members, nstring);
195172
}
196173
if (!dense) {
197174
free(proc_list);
@@ -260,64 +237,18 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
260237
* starting with our own members */
261238
OBJ_CONSTRUCT(&mlist, opal_list_t);
262239
for (i=0; NULL != members[i]; i++) {
263-
nm = OBJ_NEW(opal_namelist_t);
264-
if (OPAL_SUCCESS != (rc = opal_convert_string_to_process_name(&nm->name, members[i]))) {
265-
OMPI_ERROR_LOG(rc);
266-
opal_argv_free(members);
267-
free(rport);
268-
OPAL_LIST_DESTRUCT(&mlist);
269-
goto exit;
270-
}
271-
/* step over the nspace */
272-
++i;
273-
if (NULL == members[i]) {
274-
/* this shouldn't happen and is an error */
275-
OMPI_ERROR_LOG(OMPI_ERR_BAD_PARAM);
276-
OPAL_LIST_DESTRUCT(&mlist);
277-
opal_argv_free(members);
278-
free(rport);
279-
rc = OMPI_ERR_BAD_PARAM;
280-
goto exit;
281-
}
282-
/* if the rank is wildcard, then we need to add all procs
283-
* in that job to the list */
284-
if (OPAL_VPID_WILDCARD == nm->name.vpid) {
285-
jobid = nm->name.jobid;
286-
OBJ_RELEASE(nm);
287-
for (k=0; k < size; k++) {
288-
nm = OBJ_NEW(opal_namelist_t);
289-
nm->name.jobid = jobid;
290-
nm->name.vpid = k;
291-
opal_list_append(&mlist, &nm->super);
292-
}
293-
/* now step over the size */
294-
if (NULL == members[i+1]) {
295-
/* this shouldn't happen and is an error */
296-
OMPI_ERROR_LOG(OMPI_ERR_BAD_PARAM);
297-
OPAL_LIST_DESTRUCT(&mlist);
298-
opal_argv_free(members);
299-
free(rport);
300-
rc = OMPI_ERR_BAD_PARAM;
301-
goto exit;
302-
}
240+
OPAL_PMIX_CONVERT_STRING_TO_PROCT(&pxproc, members[i]);
241+
plt = OBJ_NEW(opal_proclist_t);
242+
memcpy(&plt->procid, &pxproc, sizeof(pmix_proc_t));
243+
opal_list_append(&mlist, &plt->super);
244+
/* if the rank is wildcard, then we need to skip
245+
* the next position */
246+
if (PMIX_RANK_WILDCARD == pxproc.rank) {
303247
++i;
304-
} else {
305-
opal_list_append(&mlist, &nm->super);
306248
}
307249
}
308250
opal_argv_free(members);
309251
members = NULL;
310-
311-
/* convert the list of members to a pmix_proc_t array */
312-
nprocs = opal_list_get_size(&mlist);
313-
PMIX_PROC_CREATE(procs, nprocs);
314-
n = 0;
315-
OPAL_LIST_FOREACH(nm, &mlist, opal_namelist_t) {
316-
OPAL_PMIX_CONVERT_NAME(&procs[n], &nm->name);
317-
++n;
318-
}
319-
OPAL_LIST_DESTRUCT(&mlist);
320-
321252
/* rport contains a colon-delimited list
322253
* of process names for the remote procs - convert it
323254
* into an argv array */
@@ -330,29 +261,13 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
330261
OBJ_CONSTRUCT(&rlist, opal_list_t);
331262

332263
for (i=0; NULL != members[i]; i++) {
333-
nm = OBJ_NEW(opal_namelist_t);
334-
if (OPAL_SUCCESS != (rc = opal_convert_string_to_process_name(&nm->name, members[i]))) {
335-
OMPI_ERROR_LOG(rc);
336-
opal_argv_free(members);
337-
OPAL_LIST_DESTRUCT(&ilist);
338-
OPAL_LIST_DESTRUCT(&rlist);
339-
PMIX_PROC_FREE(procs, nprocs);
340-
goto exit;
341-
}
342-
/* next entry is the nspace - register it */
343-
++i;
344-
if (NULL == members[i]) {
345-
OMPI_ERROR_LOG(OMPI_ERR_NOT_SUPPORTED);
346-
opal_argv_free(members);
347-
OPAL_LIST_DESTRUCT(&ilist);
348-
OPAL_LIST_DESTRUCT(&rlist);
349-
PMIX_PROC_FREE(procs, nprocs);
350-
goto exit;
351-
}
352-
if (OPAL_VPID_WILDCARD == nm->name.vpid) {
353-
jobid = nm->name.jobid;
354-
OBJ_RELEASE(nm);
355-
/* if the vpid is wildcard, then we are including all ranks
264+
OPAL_PMIX_CONVERT_STRING_TO_PROCT(&pxproc, members[i]);
265+
plt = OBJ_NEW(opal_proclist_t);
266+
memcpy(&plt->procid, &pxproc, sizeof(pmix_proc_t));
267+
opal_list_append(&mlist, &plt->super);
268+
269+
if (PMIX_RANK_WILDCARD == pxproc.rank) {
270+
/* if the rank is wildcard, then we are including all ranks
356271
* of that job, and the next entry in members should be the
357272
* number of procs in the job */
358273
if (NULL == members[i+1]) {
@@ -361,19 +276,25 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
361276
opal_argv_free(members);
362277
OPAL_LIST_DESTRUCT(&ilist);
363278
OPAL_LIST_DESTRUCT(&rlist);
279+
OPAL_LIST_DESTRUCT(&mlist);
364280
rc = OMPI_ERR_BAD_PARAM;
365-
PMIX_PROC_FREE(procs, nprocs);
366281
goto exit;
367282
}
368283
rsize = strtoul(members[i+1], NULL, 10);
369284
++i;
370285
for (k=0; k < rsize; k++) {
371-
nm = OBJ_NEW(opal_namelist_t);
372-
nm->name.jobid = jobid;
373-
nm->name.vpid = k;
374-
opal_list_append(&mlist, &nm->super);
286+
pxproc.rank = k;
287+
OPAL_PMIX_CONVERT_PROCT(rc, &pname, &pxproc);
288+
if (OPAL_SUCCESS != rc) {
289+
OMPI_ERROR_LOG(rc);
290+
opal_argv_free(members);
291+
OPAL_LIST_DESTRUCT(&ilist);
292+
OPAL_LIST_DESTRUCT(&rlist);
293+
OPAL_LIST_DESTRUCT(&mlist);
294+
goto exit;
295+
}
375296
/* see if this needs to be added to our ompi_proc_t array */
376-
proc = ompi_proc_find_and_add(&nm->name, &isnew);
297+
proc = ompi_proc_find_and_add(&pname, &isnew);
377298
if (isnew) {
378299
cd = OBJ_NEW(ompi_dpm_proct_caddy_t);
379300
cd->p = proc;
@@ -385,9 +306,17 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
385306
opal_list_append(&rlist, &cd->super);
386307
}
387308
} else {
388-
opal_list_append(&mlist, &nm->super);
309+
OPAL_PMIX_CONVERT_PROCT(rc, &pname, &pxproc);
310+
if (OPAL_SUCCESS != rc) {
311+
OMPI_ERROR_LOG(rc);
312+
opal_argv_free(members);
313+
OPAL_LIST_DESTRUCT(&ilist);
314+
OPAL_LIST_DESTRUCT(&rlist);
315+
OPAL_LIST_DESTRUCT(&mlist);
316+
goto exit;
317+
}
389318
/* see if this needs to be added to our ompi_proc_t array */
390-
proc = ompi_proc_find_and_add(&nm->name, &isnew);
319+
proc = ompi_proc_find_and_add(&pname, &isnew);
391320
if (isnew) {
392321
cd = OBJ_NEW(ompi_dpm_proct_caddy_t);
393322
cd->p = proc;
@@ -401,6 +330,16 @@ int ompi_dpm_connect_accept(ompi_communicator_t *comm, int root,
401330
}
402331
opal_argv_free(members);
403332

333+
/* convert the list of members to a pmix_proc_t array */
334+
nprocs = opal_list_get_size(&mlist);
335+
PMIX_PROC_CREATE(procs, nprocs);
336+
n = 0;
337+
OPAL_LIST_FOREACH(plt, &mlist, opal_proclist_t) {
338+
memcpy(&procs[n], &plt->procid, sizeof(pmix_proc_t));
339+
++n;
340+
}
341+
OPAL_LIST_DESTRUCT(&mlist);
342+
404343
/* tell the host RTE to connect us - this will download
405344
* all known data for the nspace's of participating procs
406345
* so that add_procs will not result in a slew of lookups */

ompi/runtime/ompi_rte.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ opal_process_name_t pmix_name_invalid = {UINT32_MAX, UINT32_MAX};
6262
hwloc_cpuset_t ompi_proc_applied_binding = NULL;
6363
pmix_process_info_t pmix_process_info = {
6464
.my_name = {OPAL_JOBID_INVALID, OPAL_VPID_INVALID},
65+
.myprocid = {{0}, PMIX_RANK_INVALID},
6566
.nodename = NULL,
6667
.pid = 0,
6768
.top_session_dir = NULL,
@@ -84,8 +85,6 @@ pmix_process_info_t pmix_process_info = {
8485
bool pmix_proc_is_bound = false;
8586
bool ompi_singleton = false;
8687

87-
static pmix_proc_t myprocid;
88-
8988
static int _setup_top_session_dir(char **sdir);
9089
static int _setup_job_session_dir(char **sdir);
9190
static int _setup_proc_session_dir(char **sdir);
@@ -550,7 +549,7 @@ int ompi_rte_init(int *pargc, char ***pargv)
550549
opal_pmix_setup_nspace_tracker();
551550

552551
/* initialize the selected module */
553-
if (!PMIx_Initialized() && (PMIX_SUCCESS != (ret = PMIx_Init(&myprocid, NULL, 0)))) {
552+
if (!PMIx_Initialized() && (PMIX_SUCCESS != (ret = PMIx_Init(&pmix_process_info.myprocid, NULL, 0)))) {
554553
/* if we get PMIX_ERR_UNREACH indicating that we cannot reach the
555554
* server, then we assume we are operating as a singleton */
556555
if (PMIX_ERR_UNREACH == ret) {
@@ -565,7 +564,7 @@ int ompi_rte_init(int *pargc, char ***pargv)
565564
}
566565

567566
/* setup the process name fields - also registers the new nspace */
568-
OPAL_PMIX_CONVERT_PROCT(rc, &pname, &myprocid);
567+
OPAL_PMIX_CONVERT_PROCT(rc, &pname, &pmix_process_info.myprocid);
569568
if (OPAL_SUCCESS != rc) {
570569
return rc;
571570
}

ompi/runtime/ompi_rte.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ typedef uint16_t ompi_local_rank_t;
245245

246246
typedef struct {
247247
opal_process_name_t my_name;
248+
pmix_proc_t myprocid;
248249
char *nodename;
249250
pid_t pid;
250251
char *top_session_dir;

opal/mca/btl/tcp/btl_tcp_endpoint.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,19 @@ mca_btl_tcp_endpoint_send_blocking(mca_btl_base_endpoint_t* btl_endpoint,
398398
* Send the globally unique identifier for this process to a endpoint on
399399
* a newly connected socket.
400400
*/
401-
static int
401+
static int
402402
mca_btl_tcp_endpoint_send_connect_ack(mca_btl_base_endpoint_t* btl_endpoint)
403403
{
404404
opal_process_name_t guid = opal_proc_local_get()->proc_name;
405405
OPAL_PROCESS_NAME_HTON(guid);
406-
406+
407407
mca_btl_tcp_endpoint_hs_msg_t hs_msg;
408408
opal_string_copy(hs_msg.magic_id, mca_btl_tcp_magic_id_string,
409409
sizeof(hs_msg.magic_id));
410410
hs_msg.guid = guid;
411-
412-
if(sizeof(hs_msg) !=
413-
mca_btl_tcp_endpoint_send_blocking(btl_endpoint,
411+
412+
if(sizeof(hs_msg) !=
413+
mca_btl_tcp_endpoint_send_blocking(btl_endpoint,
414414
&hs_msg, sizeof(hs_msg))) {
415415
opal_show_help("help-mpi-btl-tcp.txt", "client handshake fail",
416416
true, opal_process_info.nodename,
@@ -649,8 +649,8 @@ static int mca_btl_tcp_endpoint_recv_connect_ack(mca_btl_base_endpoint_t* btl_en
649649
* to be able to exchange the opal_process_name_t over the network.
650650
*/
651651
if (0 != opal_compare_proc(btl_proc->proc_opal->proc_name, guid)) {
652-
BTL_ERROR(("received unexpected process identifier %s",
653-
OPAL_NAME_PRINT(guid)));
652+
BTL_ERROR(("received unexpected process identifier: got %s expected %s",
653+
OPAL_NAME_PRINT(guid), OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name)));
654654
btl_endpoint->endpoint_state = MCA_BTL_TCP_FAILED;
655655
mca_btl_tcp_endpoint_close(btl_endpoint);
656656
return OPAL_ERR_UNREACH;
@@ -758,9 +758,9 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo
758758
mca_btl_tcp_proc_tosocks(btl_endpoint->endpoint_addr, &endpoint_addr);
759759

760760
/* Bind the socket to one of the addresses associated with
761-
* this btl module. This sets the source IP to one of the
762-
* addresses shared in modex, so that the destination rank
763-
* can properly pair btl modules, even in cases where Linux
761+
* this btl module. This sets the source IP to one of the
762+
* addresses shared in modex, so that the destination rank
763+
* can properly pair btl modules, even in cases where Linux
764764
* might do something unexpected with routing */
765765
if (endpoint_addr.ss_family == AF_INET) {
766766
assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr);
@@ -965,7 +965,7 @@ static void mca_btl_tcp_endpoint_recv_handler(int sd, short flags, void* user)
965965
the magic string ID failed). recv_connect_ack already cleaned
966966
up the socket. */
967967
/* If we get OPAL_ERROR, the other end closed the connection
968-
* because it has initiated a symetrical connexion on its end.
968+
* because it has initiated a symetrical connexion on its end.
969969
* recv_connect_ack already cleaned up the socket. */
970970
}
971971
else {

opal/mca/pmix/base/pmix_base_fns.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,28 @@ int opal_pmix_convert_nspace(opal_jobid_t *jobid, pmix_nspace_t nspace)
137137
return OPAL_SUCCESS;
138138
}
139139
if (NULL != strstr(nspace, "JOBID_WILDCARD")) {
140-
*jobid = OPAL_JOBID_WILDCARD;
140+
if (NULL != jobid) {
141+
*jobid = OPAL_JOBID_WILDCARD;
142+
}
141143
return OPAL_SUCCESS;
142144
}
143145
if (NULL != strstr(nspace, "JOBID_INVALID")) {
144-
*jobid = OPAL_JOBID_INVALID;
146+
if (NULL != jobid) {
147+
*jobid = OPAL_JOBID_INVALID;
148+
}
145149
return OPAL_SUCCESS;
146150
}
147151

148-
/* cycle across our list of known jobids */
152+
/* cycle across our list of known nspace's */
149153
OPAL_LIST_FOREACH(nptr, &localnspaces, opal_nptr_t) {
150154
if (PMIX_CHECK_NSPACE(nspace, nptr->nspace)) {
151-
*jobid = nptr->jobid;
155+
if (NULL != jobid) {
156+
*jobid = nptr->jobid;
157+
}
152158
return OPAL_SUCCESS;
153159
}
154160
}
161+
155162
/* if we get here, we don't know this nspace */
156163
/* find the "." at the end that indicates the child job */
157164
if (NULL != (p = strrchr(nspace, '.'))) {
@@ -167,7 +174,9 @@ int opal_pmix_convert_nspace(opal_jobid_t *jobid, pmix_nspace_t nspace)
167174
/* now compress to 16-bits */
168175
jobfam = (uint16_t)(((0x0000ffff & (0xffff0000 & hash32) >> 16)) ^ (0x0000ffff & hash32));
169176
jid = (0xffff0000 & ((uint32_t)jobfam << 16)) | (0x0000ffff & localjob);
170-
*jobid = jid;
177+
if (NULL != jobid) {
178+
*jobid = jid;
179+
}
171180
/* save this jobid/nspace pair */
172181
nptr = OBJ_NEW(opal_nptr_t);
173182
nptr->jobid = jid;
@@ -956,3 +965,7 @@ static void infoitdecon(opal_info_item_t *p)
956965
OBJ_CLASS_INSTANCE(opal_info_item_t,
957966
opal_list_item_t,
958967
infoitmcon, infoitdecon);
968+
969+
OBJ_CLASS_INSTANCE(opal_proclist_t,
970+
opal_list_item_t,
971+
NULL, NULL);

0 commit comments

Comments
 (0)