root/opal/mca/pmix/pmix4x/pmix/examples/tool.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cbfunc
  2. main

   1 /*
   2  * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2006-2013 Los Alamos National Security, LLC.
  13  *                         All rights reserved.
  14  * Copyright (c) 2009-2012 Cisco Systems, Inc.  All rights reserved.
  15  * Copyright (c) 2011      Oak Ridge National Labs.  All rights reserved.
  16  * Copyright (c) 2013-2019 Intel, Inc.  All rights reserved.
  17  * Copyright (c) 2015      Mellanox Technologies, Inc.  All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  *
  24  */
  25 
  26 #include <stdio.h>
  27 #include <stdlib.h>
  28 #include <unistd.h>
  29 #include <time.h>
  30 
  31 #include <pmix_tool.h>
  32 #include "examples.h"
  33 
  34 static void cbfunc(pmix_status_t status,
  35                    pmix_info_t *info, size_t ninfo,
  36                    void *cbdata,
  37                    pmix_release_cbfunc_t release_fn,
  38                    void *release_cbdata)
  39 {
  40     myquery_data_t *mq = (myquery_data_t*)cbdata;
  41     size_t n;
  42 
  43     mq->lock.status = status;
  44 
  45     /* save the returned info - it will be
  46      * released in the release_fn */
  47     if (0 < ninfo) {
  48         PMIX_INFO_CREATE(mq->info, ninfo);
  49         mq->ninfo = ninfo;
  50         for (n=0; n < ninfo; n++) {
  51             PMIX_INFO_XFER(&mq->info[n], &info[n]);
  52         }
  53     }
  54 
  55     /* let the library release the data */
  56     if (NULL != release_fn) {
  57         release_fn(release_cbdata);
  58     }
  59 
  60     /* release the block */
  61     DEBUG_WAKEUP_THREAD(&mq->lock);
  62 }
  63 
  64 int main(int argc, char **argv)
  65 {
  66     pmix_status_t rc;
  67     pmix_proc_t myproc;
  68     pmix_query_t *query;
  69     size_t nq, ninfo = 0, n, m;
  70     myquery_data_t mydata;
  71     pmix_info_t *info = NULL, *iptr;
  72     char *server_uri = NULL;
  73     char *nspace = NULL;
  74     char *nodename = NULL;
  75     pmix_data_array_t *darray, *dptr;
  76     bool geturi = false;
  77     char hostname[1024];
  78 
  79     gethostname(hostname, 1024);
  80     for (n=1; n < (size_t)argc; n++) {
  81         if (0 == strcmp("-u", argv[n]) || 0 == strcmp("--url", argv[n])) {
  82             if (NULL == argv[n+1]) {
  83                 fprintf(stderr, "Must provide URI argument to %s option\n", argv[n]);
  84                 exit(1);
  85             }
  86             server_uri = argv[n+1];
  87         } else if (0 == strcmp("-nspace", argv[n]) || 0 == strcmp("--nspace", argv[n])) {
  88             if (NULL == argv[n+1]) {
  89                 fprintf(stderr, "Must provide nspace argument to %s option\n", argv[n]);
  90                 exit(1);
  91             }
  92             nspace = argv[n+1];
  93         } else if (0 == strcmp("-uri", argv[n]) || 0 == strcmp("--uri", argv[n])) {
  94             /* retrieve the PMIx server's uri from the indicated node */
  95             nodename = argv[n+1];
  96             geturi = true;
  97         }
  98     }
  99 
 100     if (NULL != server_uri) {
 101         ninfo = 1;
 102         PMIX_INFO_CREATE(info, ninfo);
 103         PMIX_INFO_LOAD(&info[0], PMIX_SERVER_URI, server_uri, PMIX_STRING);
 104         fprintf(stderr, "Connecting to %s\n", server_uri);
 105     }
 106 
 107     /* init us */
 108     if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, info, ninfo))) {
 109         fprintf(stderr, "PMIx_tool_init failed: %d\n", rc);
 110         exit(rc);
 111     }
 112     if (NULL != info) {
 113         PMIX_INFO_FREE(info, ninfo);
 114     }
 115 
 116     if (geturi) {
 117         nq = 1;
 118         PMIX_QUERY_CREATE(query, nq);
 119         PMIX_ARGV_APPEND(rc, query[0].keys, PMIX_SERVER_URI);
 120         if (NULL != nodename) {
 121             PMIX_QUERY_QUALIFIERS_CREATE(&query[0], 1);
 122             PMIX_INFO_LOAD(&query[0].qualifiers[0], PMIX_HOSTNAME, nodename, PMIX_STRING);
 123         }
 124         DEBUG_CONSTRUCT_MYQUERY(&mydata);
 125         if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb(query, nq, cbfunc, (void*)&mydata))) {
 126             fprintf(stderr, "Client ns %s rank %d: PMIx_Query_info failed: %d\n", myproc.nspace, myproc.rank, rc);
 127             goto done;
 128         }
 129         DEBUG_WAIT_THREAD(&mydata.lock);
 130         /* find the response */
 131         if (PMIX_SUCCESS == mydata.lock.status) {
 132             /* should be in the first key */
 133             if (PMIX_CHECK_KEY(&mydata.info[0], PMIX_SERVER_URI)) {
 134                 fprintf(stderr, "PMIx server URI for node %s: %s\n",
 135                         (NULL == nodename) ? hostname : nodename,
 136                         mydata.info[0].value.data.string);
 137             } else {
 138                 fprintf(stderr, "Query returned wrong info key at first posn: %s\n", mydata.info[0].key);
 139             }
 140         } else {
 141             fprintf(stderr, "Query returned error: %s\n", PMIx_Error_string(mydata.lock.status));
 142         }
 143         DEBUG_DESTRUCT_MYQUERY(&mydata);
 144         goto done;
 145     }
 146 
 147     if (NULL == nspace) {
 148         /* query the list of active nspaces */
 149         nq = 1;
 150         PMIX_QUERY_CREATE(query, nq);
 151         PMIX_ARGV_APPEND(rc, query[0].keys, PMIX_QUERY_NAMESPACE_INFO);
 152         DEBUG_CONSTRUCT_MYQUERY(&mydata);
 153         if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb(query, nq, cbfunc, (void*)&mydata))) {
 154             fprintf(stderr, "Client ns %s rank %d: PMIx_Query_info failed: %d\n", myproc.nspace, myproc.rank, rc);
 155             goto done;
 156         }
 157         DEBUG_WAIT_THREAD(&mydata.lock);
 158         /* find the response */
 159         if (PMIX_SUCCESS == mydata.lock.status) {
 160             /* should be in the first key */
 161             if (PMIX_CHECK_KEY(&mydata.info[0], PMIX_QUERY_NAMESPACE_INFO)) {
 162                 darray = mydata.info[0].value.data.darray;
 163                 fprintf(stderr, "ACTIVE NSPACES:\n");
 164                 if (NULL == darray || 0 == darray->size || NULL == darray->array) {
 165                     fprintf(stderr, "\tNone\n");
 166                 } else {
 167                     info = (pmix_info_t*)darray->array;
 168                     if (NULL == info) {
 169                         fprintf(stderr, "Error\n");
 170                     } else {
 171                         for (n=0; n < darray->size; n++) {
 172                             dptr = info[n].value.data.darray;
 173                             if (NULL == dptr || 0 == dptr->size || NULL == dptr->array) {
 174                                 fprintf(stderr, "Error in array %s\n", (NULL == dptr) ? "NULL" : "NON-NULL");
 175                                 break;
 176                             }
 177                             iptr = (pmix_info_t*)dptr->array;
 178                             for (m=0; m < dptr->size; m++) {
 179                                 fprintf(stderr, "\t%s", iptr[m].value.data.string);
 180                             }
 181                             fprintf(stderr, "\n");
 182                         }
 183                     }
 184                 }
 185             } else {
 186                 fprintf(stderr, "Query returned wrong info key at first posn: %s\n", mydata.info[0].key);
 187             }
 188         } else {
 189             fprintf(stderr, "Query returned error: %s\n", PMIx_Error_string(mydata.lock.status));
 190         }
 191         DEBUG_DESTRUCT_MYQUERY(&mydata);
 192     } else {
 193         nq = 1;
 194         PMIX_QUERY_CREATE(query, nq);
 195         PMIX_ARGV_APPEND(rc, query[0].keys, PMIX_JOB_SIZE);
 196         PMIX_INFO_CREATE(query[0].qualifiers, 1);
 197         query[0].nqual = 1;
 198         PMIX_INFO_LOAD(&query[0].qualifiers[0], PMIX_NSPACE, nspace, PMIX_STRING);
 199         DEBUG_CONSTRUCT_MYQUERY(&mydata);
 200         if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb(query, nq, cbfunc, (void*)&mydata))) {
 201             fprintf(stderr, "Client ns %s rank %d: PMIx_Query_info failed: %d\n", myproc.nspace, myproc.rank, rc);
 202             goto done;
 203         }
 204         DEBUG_WAIT_THREAD(&mydata.lock);
 205         /* find the response */
 206         if (PMIX_SUCCESS == mydata.lock.status) {
 207             /* should be in the first key */
 208             if (PMIX_CHECK_KEY(&mydata.info[0], PMIX_JOB_SIZE)) {
 209                 fprintf(stderr, "JOB SIZE FOR NSPACE %s: %lu\n", nspace, (unsigned long)mydata.info[0].value.data.uint32);
 210             } else {
 211                 fprintf(stderr, "Query returned wrong info key at first posn: %s\n", mydata.info[0].key);
 212             }
 213         } else {
 214             fprintf(stderr, "Query returned error: %s\n", PMIx_Error_string(mydata.lock.status));
 215         }
 216         DEBUG_DESTRUCT_MYQUERY(&mydata);
 217     }
 218 
 219  done:
 220     /* finalize us */
 221     PMIx_Finalize(NULL, 0);
 222     return(rc);
 223 }

/* [<][>][^][v][top][bottom][index][help] */