root/opal/mca/pmix/pmix4x/pmix/test/simple/simpdmodex.c

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

DEFINITIONS

This source file includes following definitions.
  1. opcbfunc
  2. valcbfunc
  3. 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.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/output.h"
  36 #include "src/util/printf.h"
  37 
  38 static uint32_t nprocs;
  39 static pmix_proc_t myproc;
  40 static uint32_t getcount = 0;
  41 
  42 #define PMIX_WAIT_FOR_COMPLETION(a)             \
  43     do {                                        \
  44         while ((a)) {                           \
  45             usleep(10);                         \
  46         }                                       \
  47     } while (0)
  48 
  49 static void opcbfunc(pmix_status_t status, void *cbdata)
  50 {
  51     bool *active = (bool*)cbdata;
  52 
  53     pmix_output(0, "%s:%d completed fence_nb", myproc.nspace, myproc.rank);
  54     *active = false;
  55 }
  56 
  57 static void valcbfunc(pmix_status_t status,
  58                       pmix_value_t *val, void *cbdata)
  59 {
  60     char *key = (char*)cbdata;
  61 
  62     if (PMIX_SUCCESS == status) {
  63         if (NULL != strstr(key, "local")) {
  64             if (PMIX_UINT64 != val->type) {
  65                 pmix_output(0, "%s:%d: PMIx_Get_nb Key %s returned wrong type: %d", myproc.nspace, myproc.rank, key, val->type);
  66                 goto done;
  67             }
  68             if (1234 != val->data.uint64) {
  69                 pmix_output(0, "%s:%d: PMIx_Get_nb Key %s returned wrong value: %d", myproc.nspace, myproc.rank, key, (int)val->data.uint64);
  70                 goto done;
  71             }
  72         } else if (NULL != strstr(key, "remote")) {
  73             if (PMIX_STRING != val->type) {
  74                 pmix_output(0, "%s:%d: PMIx_Get_nb Key %s returned wrong type: %d", myproc.nspace, myproc.rank, key, val->type);
  75                 goto done;
  76             }
  77             if (0 != strcmp(val->data.string, "1234")) {
  78                 pmix_output(0, "%s:%d: PMIx_Get_nb Key %s returned wrong value: %s", myproc.nspace, myproc.rank, key, val->data.string);
  79                 goto done;
  80             }
  81         } else {
  82             pmix_output(0, "%s:%d PMIx_Get_nb returned wrong key: %s", myproc.nspace, myproc.rank, key);
  83             goto done;
  84         }
  85         pmix_output(0, "%s:%d PMIx_Get_nb Key %s returned correctly", myproc.nspace, myproc.rank, key);
  86     } else {
  87         pmix_output(0, "%s:%d PMIx_Get_nb Key %s failed: %s", myproc.nspace, myproc.rank, key, PMIx_Error_string(status));
  88     }
  89  done:
  90     free(key);
  91     getcount++;
  92 }
  93 
  94 int main(int argc, char **argv)
  95 {
  96     int rc;
  97     pmix_value_t value;
  98     pmix_value_t *val = &value;
  99     char *tmp;
 100     pmix_proc_t proc;
 101     uint32_t n, num_gets;
 102     bool active;
 103     bool dofence = true;
 104 
 105     if (NULL != getenv("PMIX_SIMPDMODEX_ASYNC")) {
 106         dofence = false;
 107     }
 108 
 109     /* init us */
 110     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
 111         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %d", myproc.nspace, myproc.rank, rc);
 112         exit(0);
 113     }
 114     pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
 115 
 116     /* get our universe size */
 117     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 118     proc.rank = PMIX_RANK_WILDCARD;
 119     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
 120         pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", myproc.nspace, myproc.rank, rc);
 121         goto done;
 122     }
 123     nprocs = val->data.uint32;
 124     PMIX_VALUE_RELEASE(val);
 125     pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs);
 126 
 127     /* put a few values */
 128     (void)asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank);
 129     value.type = PMIX_UINT32;
 130     value.data.uint32 = 1234;
 131     if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) {
 132         pmix_output(0, "Client ns %s rank %d: PMIx_Store_internal failed: %d", myproc.nspace, myproc.rank, rc);
 133         goto done;
 134     }
 135 
 136     (void)asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank);
 137     value.type = PMIX_UINT64;
 138     value.data.uint64 = 1234;
 139     if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) {
 140         pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %d", myproc.nspace, myproc.rank, rc);
 141         goto done;
 142     }
 143 
 144     (void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank);
 145     value.type = PMIX_STRING;
 146     value.data.string = "1234";
 147     if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_GLOBAL, tmp, &value))) {
 148         pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %d", myproc.nspace, myproc.rank, rc);
 149         goto done;
 150     }
 151 
 152     /* introduce a delay by one rank so we can check what happens
 153      * if a "get" is received prior to data being provided */
 154     if (0 == myproc.rank) {
 155         sleep(2);
 156         pmix_output(0, "\n\n\nWOKE UP");
 157     }
 158 
 159     /* commit the data to the server */
 160     if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
 161         pmix_output(0, "Client ns %s rank %d: PMIx_Commit failed: %d", myproc.nspace, myproc.rank, rc);
 162         goto done;
 163     }
 164 
 165     if (dofence) {
 166         /* call fence_nb, but don't return any data */
 167         PMIX_PROC_CONSTRUCT(&proc);
 168         (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 169         proc.rank = PMIX_RANK_WILDCARD;
 170         active = true;
 171         if (PMIX_SUCCESS != (rc = PMIx_Fence_nb(&proc, 1, NULL, 0, opcbfunc, &active))) {
 172             pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
 173             goto done;
 174         }
 175     }
 176 
 177     /* get the committed data - ask for someone who doesn't exist as well */
 178     num_gets = 0;
 179     for (n=0; n < nprocs; n++) {
 180         (void)asprintf(&tmp, "%s-%d-local", myproc.nspace, n);
 181         proc.rank = n;
 182         if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp,
 183                                               NULL, 0, valcbfunc, tmp))) {
 184             pmix_output(0, "Client ns %s rank %d: PMIx_Get %s failed: %d", myproc.nspace, n, tmp, rc);
 185             goto done;
 186         }
 187         ++num_gets;
 188         (void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, n);
 189         if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp,
 190                                               NULL, 0, valcbfunc, tmp))) {
 191             pmix_output(0, "Client ns %s rank %d: PMIx_Get %s failed: %d", myproc.nspace, n, tmp, rc);
 192             goto done;
 193         }
 194         ++num_gets;
 195     }
 196 
 197     if (dofence) {
 198         /* wait for the first fence to finish */
 199         PMIX_WAIT_FOR_COMPLETION(active);
 200     }
 201 
 202     /* wait for all my "get" calls to complete */
 203     while (getcount < num_gets) {
 204         struct timespec ts;
 205         ts.tv_sec = 0;
 206         ts.tv_nsec = 100000;
 207         nanosleep(&ts, NULL);
 208     }
 209 
 210     /* call fence again so everyone waits before leaving */
 211     proc.rank = PMIX_RANK_WILDCARD;
 212     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 213         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
 214         goto done;
 215     }
 216 
 217  done:
 218     /* finalize us */
 219     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 220     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 221         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 222     } else {
 223         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 224     }
 225     fflush(stderr);
 226     return(0);
 227 }

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