Skip to content

Commit

Permalink
Allow example to run as singleton
Browse files Browse the repository at this point in the history
Useful to have a simple PMIx singleton test case

Signed-off-by: Ralph Castain <[email protected]>
  • Loading branch information
rhc54 committed Aug 18, 2022
1 parent 5ea3328 commit e68b7b4
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions examples/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int main(int argc, char **argv)
pmix_query_t query;
mylock_t mylock;
bool refresh = false;
bool singleton = false;

if (1 < argc) {
if (NULL != strstr(argv[1], "true")) {
Expand All @@ -113,9 +114,14 @@ int main(int argc, char **argv)
* is included, then the process will be stopped in this call until
* the "debugger release" notification arrives */
if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %s\n", myproc.nspace, myproc.rank,
PMIx_Error_string(rc));
exit(0);
if (PMIX_ERR_UNREACH == rc) {
/* we are operating as a singleton */
singleton = true;
} else {
fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %s\n", myproc.nspace, myproc.rank,
PMIx_Error_string(rc));
exit(0);
}
}
/* get our local rank */
if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, PMIX_LOCAL_RANK, NULL, 0, &val))) {
Expand All @@ -126,29 +132,32 @@ int main(int argc, char **argv)
localrank = val->data.uint16;
PMIX_VALUE_RELEASE(val);

fprintf(stderr, "Client ns %s rank %d pid %lu: Running on host %s localrank %d\n",
myproc.nspace, myproc.rank, (unsigned long) pid, hostname, (int) localrank);
fprintf(stderr, "Client ns %s rank %d pid %lu: Running on host %s%slocalrank %d\n",
myproc.nspace, myproc.rank, (unsigned long) pid, hostname,
singleton ? " as singleton " : " ", (int) localrank);

if (!singleton) {
#if PMIX_VERSION_MAJOR >= 4
PMIX_QUERY_CONSTRUCT(&query);
PMIX_ARGV_APPEND(rc, query.keys, PMIX_QUERY_NUM_PSETS);
PMIX_ARGV_APPEND(rc, query.keys, PMIX_QUERY_PSET_NAMES);
if (refresh) {
PMIX_INFO_CREATE(query.qualifiers, 1);
query.nqual = 1;
PMIX_INFO_LOAD(&query.qualifiers[0], PMIX_QUERY_REFRESH_CACHE, &refresh, PMIX_BOOL);
}
/* setup the caddy to retrieve the data */
DEBUG_CONSTRUCT_LOCK(&mylock);
/* execute the query */
if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb(&query, 1, cbfunc, (void *) &mylock))) {
fprintf(stderr, "PMIx_Query_info failed: %d\n", rc);
goto done;
}
DEBUG_WAIT_THREAD(&mylock);
DEBUG_DESTRUCT_LOCK(&mylock);
PMIX_QUERY_CONSTRUCT(&query);
PMIX_ARGV_APPEND(rc, query.keys, PMIX_QUERY_NUM_PSETS);
PMIX_ARGV_APPEND(rc, query.keys, PMIX_QUERY_PSET_NAMES);
if (refresh) {
PMIX_INFO_CREATE(query.qualifiers, 1);
query.nqual = 1;
PMIX_INFO_LOAD(&query.qualifiers[0], PMIX_QUERY_REFRESH_CACHE, &refresh, PMIX_BOOL);
}
/* setup the caddy to retrieve the data */
DEBUG_CONSTRUCT_LOCK(&mylock);
/* execute the query */
if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb(&query, 1, cbfunc, (void *) &mylock))) {
fprintf(stderr, "PMIx_Query_info failed: %d\n", rc);
goto done;
}
DEBUG_WAIT_THREAD(&mylock);
DEBUG_DESTRUCT_LOCK(&mylock);

#endif
}

done:
/* finalize us */
Expand Down

0 comments on commit e68b7b4

Please sign in to comment.