root/opal/mca/pmix/pmix4x/pmix/test/simple/simptool.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-2018 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 <src/include/pmix_config.h>
  27 #include <pmix_tool.h>
  28 
  29 #include <stdio.h>
  30 #include <stdlib.h>
  31 #include <unistd.h>
  32 #include <time.h>
  33 
  34 #include "src/class/pmix_object.h"
  35 #include "src/util/argv.h"
  36 #include "src/util/output.h"
  37 #include "src/util/printf.h"
  38 
  39 static pmix_proc_t myproc;
  40 
  41 static void cbfunc(pmix_status_t status,
  42                    pmix_info_t *info, size_t ninfo,
  43                    void *cbdata,
  44                    pmix_release_cbfunc_t release_fn,
  45                    void *release_cbdata)
  46 {
  47     volatile bool *active = (volatile bool*)cbdata;
  48 
  49     if (0 != strncmp(info[0].key, "foobar", PMIX_MAX_KEYLEN)) {
  50         pmix_output(0, "Client ns %s rank %d: PMIx_Query_info[0] key wrong: %s vs foobar",
  51                     myproc.nspace, myproc.rank, info[0].key);
  52     }
  53     if (0 != strncmp(info[1].key, "spastic", PMIX_MAX_KEYLEN)) {
  54         pmix_output(0, "Client ns %s rank %d: PMIx_Query_info[1] key wrong: %s vs spastic",
  55                     myproc.nspace, myproc.rank, info[1].key);
  56     }
  57     if (PMIX_STRING != info[0].value.type) {
  58         pmix_output(0, "Client ns %s rank %d: PMIx_Query_info key[0] wrong type: %d vs %d",
  59                     myproc.nspace, myproc.rank, info[0].value.type, PMIX_STRING);
  60     }
  61     if (PMIX_STRING != info[1].value.type) {
  62         pmix_output(0, "Client ns %s rank %d: PMIx_Query_info key[1] wrong type: %d vs %d",
  63                     myproc.nspace, myproc.rank, info[1].value.type, PMIX_STRING);
  64     }
  65     if (0 != strcmp(info[0].value.data.string, "0")) {
  66         pmix_output(0, "Client ns %s rank %d: PMIx_Query_info key[0] wrong value: %s vs 0",
  67                     myproc.nspace, myproc.rank, info[1].value.data.string);
  68     }
  69     if (0 != strcmp(info[1].value.data.string, "1")) {
  70         pmix_output(0, "Client ns %s rank %d: PMIx_Query_info key[1] wrong value: %s vs 1",
  71                     myproc.nspace, myproc.rank, info[1].value.data.string);
  72     }
  73 
  74     if (NULL != release_fn) {
  75         release_fn(release_cbdata);
  76     }
  77     *active = false;
  78 }
  79 
  80 int main(int argc, char **argv)
  81 {
  82     pmix_status_t rc;
  83     pmix_query_t *query;
  84     size_t nq;
  85     volatile bool active;
  86     /* init us */
  87     if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, NULL, 0))) {
  88         fprintf(stderr, "PMIx_tool_init failed: %d\n", rc);
  89         exit(rc);
  90     }
  91     pmix_output(0, "Tool ns %s rank %d: Running", myproc.nspace, myproc.rank);
  92 
  93     /* query something */
  94     nq = 2;
  95     PMIX_QUERY_CREATE(query, nq);
  96     pmix_argv_append_nosize(&query[0].keys, "foobar");
  97     pmix_argv_append_nosize(&query[1].keys, "spastic");
  98     pmix_argv_append_nosize(&query[1].keys, PMIX_SERVER_URI);
  99     active = true;
 100     if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb(query, nq, cbfunc, (void*)&active))) {
 101         pmix_output(0, "Client ns %s rank %d: PMIx_Query_info failed: %d", myproc.nspace, myproc.rank, rc);
 102         goto done;
 103     }
 104     while(active) {
 105         usleep(10);
 106     }
 107  done:
 108     /* finalize us */
 109     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 110     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 111         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 112     } else {
 113         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 114     }
 115     fflush(stderr);
 116     return(rc);
 117 }

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