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

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

DEFINITIONS

This source file includes following definitions.
  1. notification_fn
  2. errhandler_reg_callbk
  3. model_callback
  4. model_registration_callback
  5. 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 /******    FUNCTIONS TESTED    ****/
  27 /*
  28  * PMIx_Init
  29  * PMIx_Get
  30  * PMIx_Register_event_handler
  31  * PMIx_Store_internal
  32  * PMIx_Put
  33  * PMIx_Commit
  34  * PMIx_Fence
  35  * PMIx_Finalize
  36  */
  37 
  38 #include <src/include/pmix_config.h>
  39 #include <pmix.h>
  40 
  41 #include <stdio.h>
  42 #include <stdlib.h>
  43 #include <unistd.h>
  44 #include <time.h>
  45 
  46 #include "src/class/pmix_object.h"
  47 #include "src/util/output.h"
  48 #include "src/util/printf.h"
  49 
  50 #define MAXCNT 1
  51 
  52 static volatile bool completed = false;
  53 static pmix_proc_t myproc;
  54 
  55 static void notification_fn(size_t evhdlr_registration_id,
  56                             pmix_status_t status,
  57                             const pmix_proc_t *source,
  58                             pmix_info_t info[], size_t ninfo,
  59                             pmix_info_t results[], size_t nresults,
  60                             pmix_event_notification_cbfunc_fn_t cbfunc,
  61                             void *cbdata)
  62 {
  63     if (NULL != cbfunc) {
  64         cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
  65     }
  66     completed = true;
  67 }
  68 
  69 static void errhandler_reg_callbk(pmix_status_t status,
  70                                   size_t errhandler_ref,
  71                                   void *cbdata)
  72 {
  73     volatile bool *active = (volatile bool*)cbdata;
  74 
  75     *active = false;
  76 }
  77 
  78 /* this is an event notification function that we explicitly request
  79  * be called when the PMIX_MODEL_DECLARED notification is issued.
  80  * We could catch it in the general event notification function and test
  81  * the status to see if the status matched, but it often is simpler
  82  * to declare a use-specific notification callback point. In this case,
  83  * we are asking to know whenever a model is declared as a means
  84  * of testing server self-notification */
  85 static void model_callback(size_t evhdlr_registration_id,
  86                            pmix_status_t status,
  87                            const pmix_proc_t *source,
  88                            pmix_info_t info[], size_t ninfo,
  89                            pmix_info_t results[], size_t nresults,
  90                            pmix_event_notification_cbfunc_fn_t cbfunc,
  91                            void *cbdata)
  92 {
  93     /* we must NOT tell the event handler state machine that we
  94      * are the last step as that will prevent it from notifying
  95      * anyone else that might be listening for declarations */
  96     if (NULL != cbfunc) {
  97         cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
  98     }
  99 }
 100 
 101 /* event handler registration is done asynchronously */
 102 static void model_registration_callback(pmix_status_t status,
 103                                         size_t evhandler_ref,
 104                                         void *cbdata)
 105 {
 106     volatile int *active = (volatile int*)cbdata;
 107 
 108     *active = false;
 109 }
 110 
 111 int main(int argc, char **argv)
 112 {
 113     int rc;
 114     pmix_value_t value;
 115     pmix_value_t *val = &value;
 116     char *tmp;
 117     pmix_proc_t proc;
 118     uint32_t nprocs, n;
 119     int cnt, j;
 120     volatile bool active;
 121     pmix_info_t *iptr;
 122     size_t ninfo;
 123     pmix_status_t code;
 124 
 125     /* init us and declare we are a test programming model */
 126     PMIX_INFO_CREATE(iptr, 2);
 127     PMIX_INFO_LOAD(&iptr[0], PMIX_PROGRAMMING_MODEL, "TEST", PMIX_STRING);
 128     PMIX_INFO_LOAD(&iptr[1], PMIX_MODEL_LIBRARY_NAME, "PMIX", PMIX_STRING);
 129     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, iptr, 2))) {
 130         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %s",
 131                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 132         exit(rc);
 133     }
 134     PMIX_INFO_FREE(iptr, 2);
 135 
 136     /* test something */
 137     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 138     proc.rank = PMIX_RANK_WILDCARD;
 139     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_JOB_SIZE, NULL, 0, &val))) {
 140         pmix_output(0, "Client ns %s rank %d: PMIx_Get failed: %s",
 141                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 142         exit(rc);
 143     }
 144     PMIX_VALUE_RELEASE(val);
 145 
 146     /* register a handler specifically for when models declare */
 147     active = true;
 148     ninfo = 1;
 149     PMIX_INFO_CREATE(iptr, ninfo);
 150     PMIX_INFO_LOAD(&iptr[0], PMIX_EVENT_HDLR_NAME, "SIMPCLIENT-MODEL", PMIX_STRING);
 151     code = PMIX_MODEL_DECLARED;
 152     PMIx_Register_event_handler(&code, 1, iptr, ninfo,
 153                                 model_callback, model_registration_callback, (void*)&active);
 154     while (active) {
 155         usleep(10);
 156     }
 157     PMIX_INFO_FREE(iptr, ninfo);
 158 
 159     /* register our errhandler */
 160     active = true;
 161     PMIx_Register_event_handler(NULL, 0, NULL, 0,
 162                                 notification_fn, errhandler_reg_callbk, (void*)&active);
 163     while (active) {
 164         usleep(10);
 165     }
 166 
 167     /* get our universe size */
 168     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 169     proc.rank = PMIX_RANK_WILDCARD;
 170     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
 171         pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %s",
 172                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 173         goto done;
 174     }
 175     nprocs = val->data.uint32;
 176     PMIX_VALUE_RELEASE(val);
 177 
 178     /* put a few values */
 179     (void)asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank);
 180     value.type = PMIX_UINT32;
 181     value.data.uint32 = 1234;
 182     if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) {
 183         pmix_output(0, "Client ns %s rank %d: PMIx_Store_internal failed: %s",
 184                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 185         goto done;
 186     }
 187 
 188     for (cnt=0; cnt < MAXCNT; cnt++) {
 189         (void)asprintf(&tmp, "%s-%d-local-%d", myproc.nspace, myproc.rank, cnt);
 190         value.type = PMIX_UINT64;
 191         value.data.uint64 = 1234;
 192         if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) {
 193             pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %s",
 194                         myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 195             goto done;
 196         }
 197 
 198         (void)asprintf(&tmp, "%s-%d-remote-%d", myproc.nspace, myproc.rank, cnt);
 199         value.type = PMIX_STRING;
 200         value.data.string = "1234";
 201         if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) {
 202             pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %s",
 203                         myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 204             goto done;
 205         }
 206 
 207         if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
 208             pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Commit failed: %s",
 209                         myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
 210             goto done;
 211         }
 212 
 213         /* call fence to ensure the data is received */
 214         PMIX_PROC_CONSTRUCT(&proc);
 215         (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 216         proc.rank = PMIX_RANK_WILDCARD;
 217         if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 218             pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Fence failed: %s",
 219                         myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
 220             goto done;
 221         }
 222 
 223         /* check the returned data */
 224         (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 225         for (j=0; j <= cnt; j++) {
 226             for (n=0; n < nprocs; n++) {
 227                 proc.rank = n;
 228                 (void)asprintf(&tmp, "%s-%d-local-%d", myproc.nspace, n, j);
 229                 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
 230                     pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s failed: %s",
 231                                 myproc.nspace, myproc.rank, j, tmp, PMIx_Error_string(rc));
 232                     continue;
 233                 }
 234                 if (NULL == val) {
 235                     pmix_output(0, "Client ns %s rank %d: NULL value returned",
 236                                 myproc.nspace, myproc.rank);
 237                     break;
 238                 }
 239                 if (PMIX_UINT64 != val->type) {
 240                     pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned wrong type: %d", myproc.nspace, myproc.rank, j, tmp, val->type);
 241                     PMIX_VALUE_RELEASE(val);
 242                     free(tmp);
 243                     continue;
 244                 }
 245                 if (1234 != val->data.uint64) {
 246                     pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned wrong value: %d", myproc.nspace, myproc.rank, j, tmp, (int)val->data.uint64);
 247                     PMIX_VALUE_RELEASE(val);
 248                     free(tmp);
 249                     continue;
 250                 }
 251                 PMIX_VALUE_RELEASE(val);
 252                 free(tmp);
 253 
 254                 if (n != myproc.rank) {
 255                     (void)asprintf(&tmp, "%s-%d-remote-%d", proc.nspace, n, j);
 256                     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
 257                         /* this data should _not_ be found as we are on the same node
 258                          * and the data was "put" with a PMIX_REMOTE scope */
 259                         continue;
 260                     }
 261                     pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned remote data for a local proc",
 262                                 myproc.nspace, myproc.rank, j, tmp);
 263                     PMIX_VALUE_RELEASE(val);
 264                     free(tmp);
 265                 }
 266             }
 267         }
 268     }
 269 
 270     /* now get the data blob for myself */
 271     if (PMIX_SUCCESS == (rc = PMIx_Get(&myproc, NULL, NULL, 0, &val))) {
 272         if (PMIX_DATA_ARRAY != val->type) {
 273             pmix_output(0, "Client ns %s rank %d did not return an array for its internal modex blob",
 274                         myproc.nspace, myproc.rank);
 275             PMIX_VALUE_RELEASE(val);
 276         } else if (PMIX_INFO != val->data.darray->type) {
 277             pmix_output(0, "Client ns %s rank %d returned an internal modex array of type %s instead of PMIX_INFO",
 278                         myproc.nspace, myproc.rank, PMIx_Data_type_string(val->data.darray->type));
 279             PMIX_VALUE_RELEASE(val);
 280         } else if (0 == val->data.darray->size) {
 281             pmix_output(0, "Client ns %s rank %d returned an internal modex array of zero length",
 282                         myproc.nspace, myproc.rank);
 283             PMIX_VALUE_RELEASE(val);
 284         } else {
 285             PMIX_VALUE_RELEASE(val);
 286         }
 287     } else {
 288         pmix_output(0, "Client ns %s rank %d internal modex blob FAILED with error %s(%d)",
 289                     myproc.nspace, myproc.rank, PMIx_Error_string(rc), rc);
 290     }
 291 
 292  done:
 293     /* finalize us */
 294     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 295         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %s\n",
 296                 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 297     }
 298     fflush(stderr);
 299     return(rc);
 300 }

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