diff --git a/orte/runtime/orte_globals.c b/orte/runtime/orte_globals.c index d0e29b26bf..1e16f06385 100644 --- a/orte/runtime/orte_globals.c +++ b/orte/runtime/orte_globals.c @@ -484,6 +484,38 @@ orte_job_t* orte_get_job_data_object(orte_jobid_t job) return (orte_job_t*)opal_pointer_array_get_item(orte_job_data, ljob); } +orte_vpid_t orte_get_lowest_vpid_alive(orte_jobid_t job) +{ + int i; + orte_job_t *jdata; + orte_proc_t *proc; + + if (NULL == (jdata = orte_get_job_data_object(job))) { + return ORTE_VPID_INVALID; + } + + if (ORTE_PROC_IS_DAEMON && + ORTE_PROC_MY_NAME->jobid == job && + NULL != orte_process_info.my_hnp_uri) { + /* if we were started by an HNP, then the lowest vpid + * is always 1 + */ + return 1; + } + + for (i=0; i < jdata->procs->size; i++) { + if (NULL == (proc = (orte_proc_t*)opal_pointer_array_get_item(jdata->procs, i))) { + continue; + } + if (proc->state == ORTE_PROC_STATE_RUNNING) { + /* must be lowest one alive */ + return proc->name.vpid; + } + } + /* only get here if no live proc found */ + return ORTE_VPID_INVALID; +} + int orte_global_comm(orte_process_name_t *recipient, opal_buffer_t *buf, orte_rml_tag_t tag, orte_default_cbfunc_t cbfunc) diff --git a/orte/runtime/orte_globals.h b/orte/runtime/orte_globals.h index 9335ff100d..543e530f43 100644 --- a/orte/runtime/orte_globals.h +++ b/orte/runtime/orte_globals.h @@ -578,6 +578,9 @@ ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_regex_node_t); */ ORTE_DECLSPEC orte_job_t* orte_get_job_data_object(orte_jobid_t job); +/* Find the lowest vpid alive in a given job */ +ORTE_DECLSPEC orte_vpid_t orte_get_lowest_vpid_alive(orte_jobid_t job); + /* global variables used by RTE - instanced in orte_globals.c */ ORTE_DECLSPEC extern bool orte_timing; ORTE_DECLSPEC extern FILE *orte_timing_output;