1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2011 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2013 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2013-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
* Copyright (c) 2021-2025 Nanook Consulting All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#define _GNU_SOURCE
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "examples.h"
#include <pmix.h>
static pmix_proc_t myproc;
/* this is a callback function for the PMIx_Query
* API. The query will callback with a status indicating
* if the request could be fully satisfied, partially
* satisfied, or completely failed. The info parameter
* contains an array of the returned data, with the
* info->key field being the key that was provided in
* the query call. Thus, you can correlate the returned
* data in the info->value field to the requested key.
*
* Once we have dealt with the returned data, we must
* call the release_fn so that the PMIx library can
* cleanup */
static void cbfunc(pmix_status_t status, pmix_info_t *info, size_t ninfo, void *cbdata,
pmix_release_cbfunc_t release_fn, void *release_cbdata)
{
mylock_t *lock = (mylock_t *) cbdata;
size_t n;
char *tmp;
lock->status = status;
fprintf(stderr, "Query returned %d values status %s\n", (int) ninfo, PMIx_Error_string(status));
/* print out the returned keys and pmix_info_t structs */
for (n = 0; n < ninfo; n++) {
tmp = PMIx_Info_string(&info[n]);
fprintf(stderr, "%s\n", tmp);
free(tmp);
}
/* let the library release the data and cleanup from
* the operation */
if (NULL != release_fn) {
release_fn(release_cbdata);
}
/* release the block */
DEBUG_WAKEUP_THREAD(lock);
}
int main(int argc, char **argv)
{
pmix_status_t rc;
pid_t pid;
char hostname[1024];
pmix_value_t *val;
uint16_t localrank;
pmix_query_t query;
mylock_t mylock;
bool refresh = false;
bool singleton = false;
if (1 < argc) {
if (NULL != strstr(argv[1], "true")) {
refresh = true;
}
}
pid = getpid();
gethostname(hostname, 1024);
/* init us - note that the call to "init" includes the return of
* any job-related info provided by the RM. This includes any
* debugger flag instructing us to stop-in-init. If such a directive
* 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))) {
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))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Get local rank failed: %s\n", myproc.nspace,
myproc.rank, PMIx_Error_string(rc));
goto done;
}
localrank = val->data.uint16;
PMIX_VALUE_RELEASE(val);
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);
if (PMIX_SUCCESS != mylock.status) {
rc = mylock.status;
}
DEBUG_DESTRUCT_LOCK(&mylock);
#endif
}
done:
/* finalize us */
rc = PMIx_Finalize(NULL, 0);
if (PMIX_SUCCESS != rc) {
fprintf(stderr, "Finalize failed: %s\n", PMIx_Error_string(rc));
}
fflush(stderr);
return (rc);
}
|