root/opal/mca/pmix/pmix4x/pmix/test/simple/simplegacy.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-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/output.h"
  36 #include "src/util/printf.h"
  37 
  38 #define MAXCNT 3
  39 
  40 static volatile bool completed = false;
  41 static pmix_proc_t myproc;
  42 
  43 static void notification_fn(size_t evhdlr_registration_id,
  44                             pmix_status_t status,
  45                             const pmix_proc_t *source,
  46                             pmix_info_t info[], size_t ninfo,
  47                             pmix_info_t results[], size_t nresults,
  48                             pmix_event_notification_cbfunc_fn_t cbfunc,
  49                             void *cbdata)
  50 {
  51     pmix_output(0, "Client %s:%d NOTIFIED with status %s", myproc.nspace, myproc.rank, PMIx_Error_string(status));
  52     if (NULL != cbfunc) {
  53         cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
  54     }
  55     completed = true;
  56 }
  57 
  58 static void errhandler_reg_callbk(pmix_status_t status,
  59                                   size_t errhandler_ref,
  60                                   void *cbdata)
  61 {
  62     volatile bool *active = (volatile bool*)cbdata;
  63 
  64     pmix_output(0, "Client: ERRHANDLER REGISTRATION CALLBACK CALLED WITH STATUS %d, ref=%lu",
  65                 status, (unsigned long)errhandler_ref);
  66     *active = false;
  67 }
  68 
  69 /* this is an event notification function that we explicitly request
  70  * be called when the PMIX_MODEL_DECLARED notification is issued.
  71  * We could catch it in the general event notification function and test
  72  * the status to see if the status matched, but it often is simpler
  73  * to declare a use-specific notification callback point. In this case,
  74  * we are asking to know whenever a model is declared as a means
  75  * of testing server self-notification */
  76 static void model_callback(size_t evhdlr_registration_id,
  77                            pmix_status_t status,
  78                            const pmix_proc_t *source,
  79                            pmix_info_t info[], size_t ninfo,
  80                            pmix_info_t results[], size_t nresults,
  81                            pmix_event_notification_cbfunc_fn_t cbfunc,
  82                            void *cbdata)
  83 {
  84     size_t n;
  85 
  86     /* just let us know it was received */
  87     fprintf(stderr, "%s:%d Model event handler called with status %d(%s)\n",
  88             myproc.nspace, myproc.rank, status, PMIx_Error_string(status));
  89     for (n=0; n < ninfo; n++) {
  90         if (PMIX_STRING == info[n].value.type) {
  91             fprintf(stderr, "%s:%d\t%s:\t%s\n",
  92                     myproc.nspace, myproc.rank,
  93                     info[n].key, info[n].value.data.string);
  94         }
  95     }
  96 
  97     /* we must NOT tell the event handler state machine that we
  98      * are the last step as that will prevent it from notifying
  99      * anyone else that might be listening for declarations */
 100     if (NULL != cbfunc) {
 101         cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
 102     }
 103 }
 104 
 105 /* event handler registration is done asynchronously */
 106 static void model_registration_callback(pmix_status_t status,
 107                                         size_t evhandler_ref,
 108                                         void *cbdata)
 109 {
 110     volatile int *active = (volatile int*)cbdata;
 111 
 112     fprintf(stderr, "simpclient EVENT HANDLER REGISTRATION RETURN STATUS %d, ref=%lu\n",
 113                status, (unsigned long)evhandler_ref);
 114     *active = false;
 115 }
 116 
 117 int main(int argc, char **argv)
 118 {
 119     int rc;
 120     pmix_value_t value;
 121     pmix_value_t *val = &value;
 122     char *tmp;
 123     pmix_proc_t proc;
 124     uint32_t nprocs, n;
 125     int cnt, j;
 126     volatile bool active;
 127     pmix_info_t info, *iptr;
 128     size_t ninfo;
 129     pmix_status_t code;
 130 
 131     /* init us and declare we are a test programming model */
 132     PMIX_INFO_CREATE(iptr, 2);
 133     PMIX_INFO_LOAD(&iptr[0], PMIX_PROGRAMMING_MODEL, "TEST", PMIX_STRING);
 134     PMIX_INFO_LOAD(&iptr[1], PMIX_MODEL_LIBRARY_NAME, "PMIX", PMIX_STRING);
 135     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, iptr, 2))) {
 136         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %s",
 137                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 138         exit(rc);
 139     }
 140     PMIX_INFO_FREE(iptr, 2);
 141     pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
 142 
 143     /* test something */
 144     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 145     proc.rank = PMIX_RANK_WILDCARD;
 146     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_JOB_SIZE, NULL, 0, &val))) {
 147         pmix_output(0, "Client ns %s rank %d: PMIx_Get failed: %s",
 148                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 149         exit(rc);
 150     }
 151     nprocs = val->data .uint32;
 152     PMIX_VALUE_RELEASE(val);
 153     pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs);
 154 
 155     /* register a handler specifically for when models declare */
 156     active = true;
 157     ninfo = 1;
 158     PMIX_INFO_CREATE(iptr, ninfo);
 159     PMIX_INFO_LOAD(&iptr[0], PMIX_EVENT_HDLR_NAME, "SIMPCLIENT-MODEL", PMIX_STRING);
 160     code = PMIX_MODEL_DECLARED;
 161     PMIx_Register_event_handler(&code, 1, iptr, ninfo,
 162                                 model_callback, model_registration_callback, (void*)&active);
 163     while (active) {
 164         usleep(10);
 165     }
 166     PMIX_INFO_FREE(iptr, ninfo);
 167 
 168     /* register our errhandler */
 169     active = true;
 170     PMIx_Register_event_handler(NULL, 0, NULL, 0,
 171                                 notification_fn, errhandler_reg_callbk, (void*)&active);
 172     while (active) {
 173         usleep(10);
 174     }
 175 
 176     memset(&info, 0, sizeof(pmix_info_t));
 177     (void)strncpy(info.key, PMIX_COLLECT_DATA, PMIX_MAX_KEYLEN);
 178     info.value.type = PMIX_UNDEF;
 179     info.value.data.flag = 1;
 180 
 181     for (cnt=0; cnt < MAXCNT; cnt++) {
 182         pmix_output(0, "EXECUTING LOOP %d", cnt);
 183         for (j=0; j < 10; j++) {
 184             (void)asprintf(&tmp, "%s-%d-gasnet-%d-%d", myproc.nspace, myproc.rank, cnt, j);
 185             value.type = PMIX_UINT64;
 186             value.data.uint64 = 1234;
 187             if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_GLOBAL, tmp, &value))) {
 188                 pmix_output(0, "Client ns %s rank %d: PMIx_Put failed: %s",
 189                             myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 190                 goto done;
 191             }
 192             free(tmp);
 193         }
 194 
 195         if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
 196             pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Commit failed: %s",
 197                         myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
 198             goto done;
 199         }
 200 
 201         /* call fence to ensure the data is received */
 202         if (PMIX_SUCCESS != (rc = PMIx_Fence(NULL, 0, &info, 1))) {
 203             pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Fence failed: %s",
 204                         myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
 205             goto done;
 206         }
 207 
 208         /* check the returned data */
 209         (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 210         proc.rank = PMIX_RANK_UNDEF;
 211         for (j=0; j < 10; j++) {
 212             for (n=0; n < nprocs; n++) {
 213                 (void)asprintf(&tmp, "%s-%d-gasnet-%d-%d", myproc.nspace, n, cnt, j);
 214                 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
 215                     pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s failed: %s",
 216                                 myproc.nspace, myproc.rank, j, tmp, PMIx_Error_string(rc));
 217                     continue;
 218                 }
 219                 if (NULL == val) {
 220                     pmix_output(0, "Client ns %s rank %d: NULL value returned",
 221                                 myproc.nspace, myproc.rank);
 222                     break;
 223                 }
 224                 if (PMIX_UINT64 != val->type) {
 225                     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);
 226                     PMIX_VALUE_RELEASE(val);
 227                     free(tmp);
 228                     continue;
 229                 }
 230                 if (1234 != val->data.uint64) {
 231                     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);
 232                     PMIX_VALUE_RELEASE(val);
 233                     free(tmp);
 234                     continue;
 235                 }
 236                 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned correct", myproc.nspace, myproc.rank, j, tmp);
 237                 PMIX_VALUE_RELEASE(val);
 238                 free(tmp);
 239             }
 240         }
 241     }
 242 
 243   done:
 244     /* finalize us */
 245     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 246     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 247         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %s\n",
 248                 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 249     } else {
 250         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 251     }
 252     fflush(stderr);
 253     return(rc);
 254 }

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