This source file includes following definitions.
- notification_fn
- evhandler_reg_callbk
- main
   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 #define _GNU_SOURCE
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <unistd.h>
  30 #include <time.h>
  31 #include <pthread.h>
  32 
  33 #include <pmix_tool.h>
  34 #include "src/mca/base/base.h"
  35 #include "src/mca/pinstalldirs/base/base.h"
  36 #include "src/threads/threads.h"
  37 #include "src/util/cmd_line.h"
  38 #include "src/util/keyval_parse.h"
  39 #include "src/util/show_help.h"
  40 #include "src/runtime/pmix_rte.h"
  41 
  42 typedef struct {
  43     pmix_lock_t lock;
  44     pmix_status_t status;
  45 } mylock_t;
  46 
  47 static pmix_proc_t myproc;
  48 
  49 
  50 
  51 
  52 
  53 
  54 static void notification_fn(size_t evhdlr_registration_id,
  55                             pmix_status_t status,
  56                             const pmix_proc_t *source,
  57                             pmix_info_t info[], size_t ninfo,
  58                             pmix_info_t results[], size_t nresults,
  59                             pmix_event_notification_cbfunc_fn_t cbfunc,
  60                             void *cbdata)
  61 {
  62     
  63     if (NULL != cbfunc) {
  64         cbfunc(PMIX_EVENT_ACTION_COMPLETE, NULL, 0, NULL, NULL, cbdata);
  65     }
  66 }
  67 
  68 
  69 
  70 
  71 
  72 
  73 
  74 
  75 static void evhandler_reg_callbk(pmix_status_t status,
  76                                  size_t evhandler_ref,
  77                                  void *cbdata)
  78 {
  79     mylock_t *lock = (mylock_t*)cbdata;
  80 
  81     if (PMIX_SUCCESS != status) {
  82         fprintf(stderr, "Client %s:%d EVENT HANDLER REGISTRATION FAILED WITH STATUS %d, ref=%lu\n",
  83                    myproc.nspace, myproc.rank, status, (unsigned long)evhandler_ref);
  84     }
  85     lock->status = status;
  86     PMIX_WAKEUP_THREAD(&lock->lock);
  87 }
  88 
  89 
  90 
  91 
  92 typedef struct {
  93     bool help;
  94     bool verbose;
  95     pid_t pid;
  96     bool wait;
  97     int timeout;
  98 } pmix_plookup_globals_t;
  99 
 100 pmix_plookup_globals_t pmix_plookup_globals = {0};
 101 
 102 pmix_cmd_line_init_t cmd_line_opts[] = {
 103     { NULL,
 104       'h', NULL, "help",
 105       0,
 106       &pmix_plookup_globals.help, PMIX_CMD_LINE_TYPE_BOOL,
 107       "This help message" },
 108 
 109     { NULL,
 110       'v', NULL, "verbose",
 111       0,
 112       &pmix_plookup_globals.verbose, PMIX_CMD_LINE_TYPE_BOOL,
 113       "Be Verbose" },
 114 
 115     { NULL,
 116       'p', NULL, "pid",
 117       1,
 118       &pmix_plookup_globals.pid, PMIX_CMD_LINE_TYPE_INT,
 119       "Specify starter pid" },
 120 
 121     { NULL,
 122       'w', NULL, "wait",
 123       0,
 124       &pmix_plookup_globals.wait, PMIX_CMD_LINE_TYPE_BOOL,
 125       "Wait for data to be available" },
 126 
 127     { NULL,
 128       't', NULL, "timeout",
 129       0,
 130       &pmix_plookup_globals.timeout, PMIX_CMD_LINE_TYPE_INT,
 131       "Max number of seconds to wait for data to become available" },
 132 
 133     
 134     { NULL,
 135       '\0', NULL, NULL,
 136       0,
 137       NULL, PMIX_CMD_LINE_TYPE_NULL,
 138       NULL }
 139 };
 140 
 141 int main(int argc, char **argv)
 142 {
 143     pmix_status_t rc;
 144     pmix_info_t *info = NULL;
 145     size_t ninfo = 0, n;
 146     mylock_t mylock;
 147     pmix_cmd_line_t cmd_line;
 148     pmix_pdata_t *pdata = NULL;
 149     size_t ndata;
 150     int count;
 151     char **keys = NULL;
 152 
 153     
 154 
 155     signal(SIGPIPE, SIG_IGN);
 156 
 157     
 158     if (!pmix_output_init()) {
 159         return PMIX_ERROR;
 160     }
 161 
 162     
 163     if (PMIX_SUCCESS != (rc = pmix_mca_base_framework_open(&pmix_pinstalldirs_base_framework, 0))) {
 164         fprintf(stderr, "pmix_pinstalldirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of PMIX_SUCCESS)\n",
 165                 __FILE__, __LINE__, rc);
 166         return rc;
 167     }
 168 
 169     
 170     pmix_show_help_init();
 171 
 172     
 173     if (PMIX_SUCCESS != (rc = pmix_util_keyval_parse_init())) {
 174         fprintf(stderr, "pmix_util_keyval_parse_init failed with %d\n", rc);
 175         return PMIX_ERROR;
 176     }
 177 
 178     
 179     if (PMIX_SUCCESS != (rc = pmix_mca_base_var_init())) {
 180         fprintf(stderr, "pmix_mca_base_var_init failed with %d\n", rc);
 181         return PMIX_ERROR;
 182     }
 183 
 184     
 185     if (PMIX_SUCCESS != (rc = pmix_register_params())) {
 186         fprintf(stderr, "pmix_register_params failed with %d\n", rc);
 187         return PMIX_ERROR;
 188     }
 189 
 190     
 191     pmix_cmd_line_create(&cmd_line, cmd_line_opts);
 192 
 193     pmix_mca_base_open();
 194     pmix_mca_base_cmd_line_setup(&cmd_line);
 195     rc = pmix_cmd_line_parse(&cmd_line, false, false, argc, argv);
 196 
 197     if (PMIX_SUCCESS != rc) {
 198         if (PMIX_ERR_SILENT != rc) {
 199             fprintf(stderr, "%s: command line error (%s)\n", argv[0],
 200                     PMIx_Error_string(rc));
 201         }
 202         return rc;
 203     }
 204 
 205     if (pmix_plookup_globals.help) {
 206         char *str, *args = NULL;
 207         args = pmix_cmd_line_get_usage_msg(&cmd_line);
 208         str = pmix_show_help_string("help-plookup.txt", "usage", true,
 209                                     args);
 210         if (NULL != str) {
 211             printf("%s", str);
 212             free(str);
 213         }
 214         free(args);
 215         
 216         exit(0);
 217     }
 218 
 219     if (pmix_plookup_globals.wait) {
 220         ++ninfo;
 221         if (0 < pmix_plookup_globals.timeout) {
 222             ++ninfo;
 223         }
 224     }
 225 
 226     
 227     pmix_cmd_line_get_tail(&cmd_line, &count, &keys);
 228     if (0 == count) {
 229         
 230         fprintf(stderr, "%s: Must provide at least one key to lookup\n", argv[0]);
 231         exit(1);
 232     }
 233     ndata = count;
 234 
 235     
 236 
 237 
 238     
 239     PMIX_INFO_CREATE(info, 1);
 240     PMIX_INFO_LOAD(&info[0], PMIX_CONNECT_SYSTEM_FIRST, NULL, PMIX_BOOL);
 241     
 242     if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, info, 1))) {
 243         fprintf(stderr, "PMIx_tool_init failed: %d\n", rc);
 244         exit(rc);
 245     }
 246     PMIX_INFO_FREE(info, 1);
 247 
 248     
 249     PMIX_CONSTRUCT_LOCK(&mylock.lock);
 250     PMIx_Register_event_handler(NULL, 0, NULL, 0,
 251                                 notification_fn, evhandler_reg_callbk, (void*)&mylock);
 252     PMIX_WAIT_THREAD(&mylock.lock);
 253     if (PMIX_SUCCESS != mylock.status) {
 254         fprintf(stderr, "PMIx_Register_event_handler returned bad status: %d\n", rc);
 255         PMIX_DESTRUCT_LOCK(&mylock.lock);
 256         goto done;
 257     }
 258     PMIX_DESTRUCT_LOCK(&mylock.lock);
 259 
 260     
 261     if (0 < ninfo) {
 262         PMIX_INFO_CREATE(info, ninfo);
 263         PMIX_INFO_LOAD(&info[0], PMIX_WAIT, NULL, PMIX_BOOL);
 264         if (1 < ninfo) {
 265             PMIX_INFO_LOAD(&info[1], PMIX_TIMEOUT, &pmix_plookup_globals.timeout, PMIX_INT);
 266         }
 267     }
 268 
 269     
 270     PMIX_PDATA_CREATE(pdata, ndata);
 271     for (n=0; n < ndata; n++) {
 272         pmix_strncpy(pdata[n].key, keys[n], PMIX_MAX_KEYLEN);
 273     }
 274     
 275     rc = PMIx_Lookup(pdata, ndata, info, ninfo);
 276 
 277     if (PMIX_SUCCESS != rc) {
 278         fprintf(stderr, "PMIx_Lookup failed: %d\n", rc);
 279         goto done;
 280     }
 281 
 282     for (n=0; n < ndata; n++) {
 283         fprintf(stderr, "Key: %s\n", pdata[n].key);
 284     }
 285     PMIX_PDATA_FREE(pdata, ndata);
 286 
 287   done:
 288     PMIx_tool_finalize();
 289 
 290     return(rc);
 291 }