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

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

DEFINITIONS

This source file includes following definitions.
  1. 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 <stdbool.h>
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <unistd.h>
  30 #include <time.h>
  31 
  32 #include <pmix.h>
  33 
  34 int main(int argc, char **argv)
  35 {
  36     pmix_proc_t myproc;
  37     int rc;
  38     pmix_value_t value;
  39     pmix_value_t *val = &value;
  40     pmix_proc_t proc;
  41     uint32_t nprocs;
  42     pmix_info_t *info;
  43     pmix_pdata_t *pdata;
  44     size_t n;
  45 
  46     /* init us */
  47     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
  48         fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %d\n", myproc.nspace, myproc.rank, rc);
  49         exit(0);
  50     }
  51     fprintf(stderr, "Client ns %s rank %d: Running\n", myproc.nspace, myproc.rank);
  52 
  53     /* get our universe size */
  54     PMIX_PROC_CONSTRUCT(&proc);
  55     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
  56     proc.rank = PMIX_RANK_WILDCARD;
  57     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
  58         fprintf(stderr, "Client ns %s rank %d: PMIx_Get universe size failed: %d\n", myproc.nspace, myproc.rank, rc);
  59         goto done;
  60     }
  61     nprocs = val->data.uint32;
  62     PMIX_VALUE_RELEASE(val);
  63     fprintf(stderr, "Client %s:%d universe size %d\n", myproc.nspace, myproc.rank, nprocs);
  64 
  65     /* publish something */
  66     if (0 == myproc.rank) {
  67         fprintf(stderr, "%s:%d publishing two keys\n", myproc.nspace, myproc.rank);
  68         PMIX_INFO_CREATE(info, 2);
  69         (void)strncpy(info[0].key, "FOOBAR", PMIX_MAX_KEYLEN);
  70         info[0].value.type = PMIX_UINT8;
  71         info[0].value.data.uint8 = 1;
  72         (void)strncpy(info[1].key, "PANDA", PMIX_MAX_KEYLEN);
  73         info[1].value.type = PMIX_SIZE;
  74         info[1].value.data.size = 123456;
  75         if (PMIX_SUCCESS != (rc = PMIx_Publish(info, 2))) {
  76             fprintf(stderr, "Client ns %s rank %d: PMIx_Publish failed: %d\n", myproc.nspace, myproc.rank, rc);
  77             goto done;
  78         }
  79         fprintf(stderr, "%s:%d publish complete\n", myproc.nspace, myproc.rank);
  80         PMIX_INFO_FREE(info, 2);
  81     }
  82 
  83     /* lookup something */
  84     if (0 != myproc.rank) {
  85         PMIX_PDATA_CREATE(pdata, 2);
  86         fprintf(stderr, "%s:%d looking up key FOOBAR\n", myproc.nspace, myproc.rank);
  87         (void)strncpy(pdata[0].key, "FOOBAR", PMIX_MAX_KEYLEN);
  88         (void)strncpy(pdata[1].key, "PANDA", PMIX_MAX_KEYLEN);
  89         PMIX_INFO_CREATE(info, 1);
  90         rc = 0;
  91         PMIX_INFO_LOAD(&info[0], PMIX_WAIT, &rc, PMIX_INT);
  92         if (PMIX_SUCCESS != (rc = PMIx_Lookup(pdata, 2, info, 1))) {
  93             fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup failed: %d\n", myproc.nspace, myproc.rank, rc);
  94             goto done;
  95         }
  96         PMIX_INFO_FREE(info, 1);
  97         /* check the return for value and source */
  98         for (n=0; n < 2; n++) {
  99             if (0 != strncmp(myproc.nspace, pdata[n].proc.nspace, PMIX_MAX_NSLEN)) {
 100                 fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong nspace: %s\n",
 101                             myproc.nspace, myproc.rank, pdata[n].proc.nspace);
 102                 goto done;
 103             }
 104             if (0 != pdata[n].proc.rank) {
 105                 fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong rank: %d\n",
 106                             myproc.nspace, myproc.rank, pdata[n].proc.rank);
 107                 goto done;
 108             }
 109         }
 110         if (PMIX_UINT8 != pdata[0].value.type) {
 111             fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong type: %d\n",
 112                         myproc.nspace, myproc.rank, pdata[0].value.type);
 113             goto done;
 114         }
 115         if (1 != pdata[0].value.data.uint8) {
 116             fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong value: %d\n",
 117                         myproc.nspace, myproc.rank, (int)pdata[0].value.data.uint8);
 118             goto done;
 119         }
 120         if (PMIX_SIZE != pdata[1].value.type) {
 121             fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong type: %d\n",
 122                         myproc.nspace, myproc.rank, pdata[1].value.type);
 123             goto done;
 124         }
 125         if (123456 != pdata[1].value.data.size) {
 126             fprintf(stderr, "Client ns %s rank %d: PMIx_Lookup returned wrong value: %d\n",
 127                         myproc.nspace, myproc.rank, (int)pdata[1].value.data.size);
 128             goto done;
 129         }
 130         PMIX_PDATA_FREE(pdata, 2);
 131         fprintf(stderr, "PUBLISH-LOOKUP SUCCEEDED\n");
 132     }
 133 
 134     /* call fence so rank 0 waits before leaving */
 135     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 136         fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank, rc);
 137         goto done;
 138     }
 139 
 140     if (0 == myproc.rank) {
 141         char **keys;
 142         keys = (char**)malloc(3 * sizeof(char*));
 143         keys[0] = "FOOBAR";
 144         keys[1] = "PANDA";
 145         keys[2] = NULL;
 146 
 147         fprintf(stderr, "%s:%d unpublishing two keys\n", myproc.nspace, myproc.rank);
 148         if (PMIX_SUCCESS != (rc = PMIx_Unpublish(keys, NULL, 0))) {
 149             fprintf(stderr, "Client ns %s rank %d: PMIx_Unpublish failed: %d\n", myproc.nspace, myproc.rank, rc);
 150             free(keys);
 151             goto done;
 152         }
 153         free(keys);
 154         fprintf(stderr, "UNPUBLISH SUCCEEDED\n");
 155     }
 156 
 157     /* call fence again so everyone waits for rank 0 before leaving */
 158     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 159         fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank, rc);
 160         goto done;
 161     }
 162 
 163  done:
 164     /* finalize us */
 165     fprintf(stderr, "Client ns %s rank %d: Finalizing\n", myproc.nspace, myproc.rank);
 166     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 167         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 168     } else {
 169         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 170     }
 171     fflush(stderr);
 172     return(0);
 173 }

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