This source file includes following definitions.
- opcbfunc
- valcbfunc
- main
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  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     
 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     
 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     
 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     
 153 
 154     if (0 == myproc.rank) {
 155         sleep(2);
 156         pmix_output(0, "\n\n\nWOKE UP");
 157     }
 158 
 159     
 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         
 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     
 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         
 199         PMIX_WAIT_FOR_COMPLETION(active);
 200     }
 201 
 202     
 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     
 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     
 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 }