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 <stdbool.h>
  27 
  28 #define _GNU_SOURCE
  29 #include <stdio.h>
  30 
  31 #include <stdlib.h>
  32 #include <unistd.h>
  33 #include <time.h>
  34 
  35 #include <pmix.h>
  36 #include "examples.h"
  37 
  38 static uint32_t nprocs;
  39 static pmix_proc_t myproc;
  40 static uint32_t getcount = 0;
  41 
  42 static void opcbfunc(pmix_status_t status, void *cbdata)
  43 {
  44     mylock_t *lock = (mylock_t*)cbdata;
  45 
  46     fprintf(stderr, "%s:%d completed fence_nb\n", myproc.nspace, myproc.rank);
  47     lock->status = status;
  48     DEBUG_WAKEUP_THREAD(lock);
  49 }
  50 
  51 static void valcbfunc(pmix_status_t status,
  52                       pmix_value_t *val, void *cbdata)
  53 {
  54     char *key = (char*)cbdata;
  55 
  56     if (PMIX_SUCCESS == status) {
  57         if (NULL != strstr(key, "local")) {
  58             if (PMIX_UINT64 != val->type) {
  59                 fprintf(stderr, "%s:%d: PMIx_Get_nb Key %s returned wrong type: %d\n", myproc.nspace, myproc.rank, key, val->type);
  60                 goto done;
  61             }
  62             if (1234 != val->data.uint64) {
  63                 fprintf(stderr, "%s:%d: PMIx_Get_nb Key %s returned wrong value: %d\n", myproc.nspace, myproc.rank, key, (int)val->data.uint64);
  64                 goto done;
  65             }
  66         } else if (NULL != strstr(key, "remote")) {
  67             if (PMIX_STRING != val->type) {
  68                 fprintf(stderr, "%s:%d: PMIx_Get_nb Key %s returned wrong type: %d\n", myproc.nspace, myproc.rank, key, val->type);
  69                 goto done;
  70             }
  71             if (0 != strcmp(val->data.string, "1234")) {
  72                 fprintf(stderr, "%s:%d: PMIx_Get_nb Key %s returned wrong value: %s\n", myproc.nspace, myproc.rank, key, val->data.string);
  73                 goto done;
  74             }
  75         } else {
  76             fprintf(stderr, "%s:%d PMIx_Get_nb returned wrong key: %s\n", myproc.nspace, myproc.rank, key);
  77             goto done;
  78         }
  79         fprintf(stderr, "%s:%d PMIx_Get_nb Key %s returned correctly\n", myproc.nspace, myproc.rank, key);
  80     } else {
  81         fprintf(stderr, "%s:%d PMIx_Get_nb Key %s failed\n", myproc.nspace, myproc.rank, key);
  82     }
  83  done:
  84     free(key);
  85     getcount++;
  86 }
  87 
  88 int main(int argc, char **argv)
  89 {
  90     int rc;
  91     pmix_value_t value;
  92     pmix_value_t *val = &value;
  93     char *tmp;
  94     pmix_proc_t proc;
  95     uint32_t n, num_gets;
  96     mylock_t mylock;
  97 
  98     
  99     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
 100         fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %d\n", myproc.nspace, myproc.rank, rc);
 101         exit(0);
 102     }
 103     fprintf(stderr, "Client ns %s rank %d: Running\n", myproc.nspace, myproc.rank);
 104 
 105     
 106     PMIX_PROC_CONSTRUCT(&proc);
 107     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 108     proc.rank = PMIX_RANK_WILDCARD;
 109     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
 110         fprintf(stderr, "Client ns %s rank %d: PMIx_Get universe size failed: %d\n", myproc.nspace, myproc.rank, rc);
 111         goto done;
 112     }
 113     nprocs = val->data.uint32;
 114     PMIX_VALUE_RELEASE(val);
 115     fprintf(stderr, "Client %s:%d universe size %d\n", myproc.nspace, myproc.rank, nprocs);
 116 
 117     
 118     if (0 > asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank)) {
 119         exit(1);
 120     }
 121     value.type = PMIX_UINT32;
 122     value.data.uint32 = 1234;
 123     if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) {
 124         fprintf(stderr, "Client ns %s rank %d: PMIx_Store_internal failed: %d\n", myproc.nspace, myproc.rank, rc);
 125         goto done;
 126     }
 127     free(tmp);
 128 
 129     if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank)) {
 130         exit(1);
 131     }
 132     value.type = PMIX_UINT64;
 133     value.data.uint64 = 1234;
 134     if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) {
 135         fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace, myproc.rank, rc);
 136         goto done;
 137     }
 138     free(tmp);
 139 
 140     if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank)) {
 141         exit(1);
 142     }
 143     value.type = PMIX_STRING;
 144     value.data.string = "1234";
 145     if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) {
 146         fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace, myproc.rank, rc);
 147         goto done;
 148     }
 149     free(tmp);
 150 
 151     
 152 
 153 
 154     if (0 == myproc.rank) {
 155         sleep(2);
 156     }
 157 
 158     
 159     if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
 160         fprintf(stderr, "Client ns %s rank %d: PMIx_Commit failed: %d\n", myproc.nspace, myproc.rank, rc);
 161         goto done;
 162     }
 163 
 164     
 165     PMIX_PROC_CONSTRUCT(&proc);
 166     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 167     proc.rank = PMIX_RANK_WILDCARD;
 168     DEBUG_CONSTRUCT_LOCK(&mylock);
 169     if (PMIX_SUCCESS != (rc = PMIx_Fence_nb(&proc, 1, NULL, 0, opcbfunc, &mylock))) {
 170         fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank, rc);
 171         DEBUG_DESTRUCT_LOCK(&mylock);
 172         goto done;
 173     }
 174 
 175     
 176     num_gets = 0;
 177     for (n=0; n <= nprocs; n++) {
 178         if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, n)) {
 179             exit(1);
 180         }
 181         (void)strncpy(proc.nspace, tmp, PMIX_MAX_NSLEN);
 182         proc.rank = n;
 183         if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp,
 184                                               NULL, 0, valcbfunc, tmp))) {
 185             fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, n, tmp, rc);
 186             goto done;
 187         }
 188         ++num_gets;
 189         if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, n)) {
 190             exit(1);
 191         }
 192         (void)strncpy(proc.nspace, tmp, PMIX_MAX_NSLEN);
 193         if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp,
 194                                               NULL, 0, valcbfunc, tmp))) {
 195             fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, n, tmp, rc);
 196             goto done;
 197         }
 198         ++num_gets;
 199     }
 200 
 201     
 202     DEBUG_WAIT_THREAD(&mylock);
 203 
 204     
 205     while (getcount < num_gets) {
 206         struct timespec ts;
 207         ts.tv_sec = 0;
 208         ts.tv_nsec = 100000;
 209         nanosleep(&ts, NULL);
 210     }
 211 
 212     
 213     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 214     proc.rank = PMIX_RANK_WILDCARD;
 215     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 216         fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank, rc);
 217         goto done;
 218     }
 219 
 220  done:
 221     
 222     fprintf(stderr, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 223     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 224         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 225     } else {
 226         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 227     }
 228     fflush(stderr);
 229     return(0);
 230 }