root/opal/mca/pmix/pmix4x/pmix/test/simple/simppub.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-2017 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.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 int main(int argc, char **argv)
  40 {
  41     int rc;
  42     pmix_value_t value;
  43     pmix_value_t *val = &value;
  44     pmix_proc_t proc;
  45     uint32_t nprocs;
  46     pmix_info_t *info;
  47     pmix_pdata_t *pdata;
  48     pmix_proc_t myproc;
  49 
  50     /* init us */
  51     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
  52         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %d", myproc.nspace, myproc.rank, rc);
  53         exit(0);
  54     }
  55     pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
  56 
  57     /* get our universe size */
  58     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
  59     proc.rank = PMIX_RANK_WILDCARD;
  60     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
  61         pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", myproc.nspace, myproc.rank, rc);
  62         goto done;
  63     }
  64     nprocs = val->data.uint32;
  65     PMIX_VALUE_RELEASE(val);
  66     pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs);
  67 
  68     /* call fence to ensure the data is received */
  69     PMIX_PROC_CONSTRUCT(&proc);
  70     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
  71     proc.rank = PMIX_RANK_WILDCARD;
  72     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
  73         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
  74         goto done;
  75     }
  76 
  77     /* publish something */
  78     if (0 == myproc.rank) {
  79         PMIX_INFO_CREATE(info, 2);
  80         (void)strncpy(info[0].key, "FOOBAR", PMIX_MAX_KEYLEN);
  81         info[0].value.type = PMIX_UINT8;
  82         info[0].value.data.uint8 = 1;
  83         (void)strncpy(info[1].key, "PANDA", PMIX_MAX_KEYLEN);
  84         info[1].value.type = PMIX_SIZE;
  85         info[1].value.data.size = 123456;
  86         if (PMIX_SUCCESS != (rc = PMIx_Publish(info, 2))) {
  87             pmix_output(0, "Client ns %s rank %d: PMIx_Publish failed: %d", myproc.nspace, myproc.rank, rc);
  88             goto done;
  89         }
  90         PMIX_INFO_FREE(info, 2);
  91     }
  92 
  93     /* call fence again so all procs know the data
  94      * has been published */
  95     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
  96         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
  97         goto done;
  98     }
  99 
 100     /* lookup something */
 101     if (0 != myproc.rank) {
 102         PMIX_PDATA_CREATE(pdata, 1);
 103         (void)strncpy(pdata[0].key, "FOOBAR", PMIX_MAX_KEYLEN);
 104         if (PMIX_SUCCESS != (rc = PMIx_Lookup(pdata, 1, NULL, 0))) {
 105             pmix_output(0, "Client ns %s rank %d: PMIx_Lookup failed: %d", myproc.nspace, myproc.rank, rc);
 106             goto done;
 107         }
 108         /* check the return for value and source */
 109         if (0 != strncmp(myproc.nspace, pdata[0].proc.nspace, PMIX_MAX_NSLEN)) {
 110             pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong nspace: %s",
 111                         myproc.nspace, myproc.rank, pdata[0].proc.nspace);
 112             goto done;
 113         }
 114         if (0 != pdata[0].proc.rank) {
 115             pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong rank: %d",
 116                         myproc.nspace, myproc.rank, pdata[0].proc.rank);
 117             goto done;
 118         }
 119         if (PMIX_UINT8 != pdata[0].value.type) {
 120             pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong type: %d",
 121                         myproc.nspace, myproc.rank, pdata[0].value.type);
 122             goto done;
 123         }
 124         if (1 != pdata[0].value.data.uint8) {
 125             pmix_output(0, "Client ns %s rank %d: PMIx_Lookup returned wrong value: %d",
 126                         myproc.nspace, myproc.rank, (int)pdata[0].value.data.uint8);
 127             goto done;
 128         }
 129         PMIX_PDATA_FREE(pdata, 1);
 130         pmix_output(0, "PUBLISH-LOOKUP SUCCEEDED");
 131     }
 132 
 133     /* call fence again so rank 0 waits before leaving */
 134     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 135         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
 136         goto done;
 137     }
 138 
 139     if (0 == myproc.rank) {
 140         char **keys = NULL;
 141         pmix_argv_append_nosize(&keys, "FOOBAR");
 142         pmix_argv_append_nosize(&keys, "PANDA");
 143 
 144         if (PMIX_SUCCESS != (rc = PMIx_Unpublish(keys, NULL, 0))) {
 145             pmix_output(0, "Client ns %s rank %d: PMIx_Unpublish failed: %d", myproc.nspace, myproc.rank, rc);
 146             goto done;
 147         }
 148         pmix_output(0, "UNPUBLISH SUCCEEDED");
 149     }
 150 
 151     /* call fence again so everyone waits for rank 0 before leaving */
 152     proc.rank = PMIX_RANK_WILDCARD;
 153     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 154         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
 155         goto done;
 156     }
 157 
 158  done:
 159     /* finalize us */
 160     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 161     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 162         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 163     } else {
 164         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 165     }
 166     fflush(stderr);
 167     return(0);
 168 }

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