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

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

DEFINITIONS

This source file includes following definitions.
  1. notification_fn
  2. op_callbk
  3. errhandler_reg_callbk
  4. 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/argv.h"
  36 #include "src/util/output.h"
  37 #include "src/util/printf.h"
  38 
  39 static pmix_proc_t myproc;
  40 static bool completed;
  41 
  42 static void notification_fn(size_t evhdlr_registration_id,
  43                             pmix_status_t status,
  44                             const pmix_proc_t *source,
  45                             pmix_info_t info[], size_t ninfo,
  46                             pmix_info_t results[], size_t nresults,
  47                             pmix_event_notification_cbfunc_fn_t cbfunc,
  48                             void *cbdata)
  49 {
  50     size_t n;
  51 
  52     pmix_output(0, "Client %s:%d NOTIFIED with status %d source %s:%d and %d info",
  53                 myproc.nspace, myproc.rank, status, source->nspace, source->rank, (int)ninfo);
  54     for (n=0; n < ninfo; n++) {
  55         if (0 == strncmp(info[n].key, PMIX_PROCID, PMIX_MAX_KEYLEN) &&
  56             PMIX_PROC == info[n].value.type) {
  57             pmix_output(0, "[%s:%d] added proc: %s:%d", myproc.nspace, myproc.rank,
  58                         info[n].value.data.proc->nspace, info[n].value.data.proc->rank);
  59         } else {
  60             pmix_output(0, "[%s:%d] key: %s", myproc.nspace, myproc.rank, info[n].key);
  61         }
  62     }
  63     if (NULL != cbfunc) {
  64         cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
  65     }
  66     completed = true;
  67 }
  68 
  69 static void op_callbk(pmix_status_t status,
  70                       void *cbdata)
  71 {
  72     pmix_output(0, "CLIENT: OP CALLBACK CALLED WITH STATUS %d", status);
  73 }
  74 
  75 static void errhandler_reg_callbk (pmix_status_t status,
  76                                    size_t errhandler_ref,
  77                                    void *cbdata)
  78 {
  79     pmix_output(0, "Client: ERRHANDLER REGISTRATION CALLBACK CALLED WITH STATUS %d, ref=%lu",
  80                 status, (unsigned long)errhandler_ref);
  81 }
  82 
  83 int main(int argc, char **argv)
  84 {
  85     int rc;
  86     pmix_value_t value;
  87     pmix_value_t *val = &value;
  88     pmix_proc_t proc;
  89     uint32_t nprocs;
  90     pmix_status_t code[5] = {PMIX_ERR_PROC_ABORTING, PMIX_ERR_PROC_ABORTED,
  91                              PMIX_ERR_PROC_REQUESTED_ABORT, PMIX_ERR_JOB_TERMINATED,
  92                              PMIX_ERR_UNREACH};
  93     /* init us */
  94     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
  95         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %d", myproc.nspace, myproc.rank, rc);
  96         exit(0);
  97     }
  98     pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
  99 
 100     /* get our universe size */
 101     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 102     proc.rank = PMIX_RANK_WILDCARD;
 103     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
 104         pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", myproc.nspace, myproc.rank, rc);
 105         goto done;
 106     }
 107     nprocs = val->data.uint32;
 108     PMIX_VALUE_RELEASE(val);
 109     pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs);
 110     completed = false;
 111 
 112     /* register our errhandler */
 113     PMIx_Register_event_handler(code, 5, NULL, 0,
 114                                 notification_fn, errhandler_reg_callbk, NULL);
 115 
 116     /* call fence to sync */
 117     PMIX_PROC_CONSTRUCT(&proc);
 118     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 119     proc.rank = PMIX_RANK_WILDCARD;
 120     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 121         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
 122         goto done;
 123     }
 124 
 125     /* rank=0 dies */
 126     if (4 < nprocs) {
 127         /* have one exit */
 128         if (0 == myproc.rank) {
 129             pmix_output(0, "Client ns %s rank %d: bye-bye!", myproc.nspace, myproc.rank);
 130             exit(1);
 131         } else if (1 == myproc.rank) {
 132             usleep(500000);
 133             pmix_output(0, "Client ns %s rank %d: bye-bye!", myproc.nspace, myproc.rank);
 134             exit(1);
 135         }
 136     } else if (0 == myproc.rank) {
 137         pmix_output(0, "Client ns %s rank %d: bye-bye!", myproc.nspace, myproc.rank);
 138         exit(1);
 139     }
 140     /* everyone simply waits */
 141     while (!completed) {
 142         struct timespec ts;
 143         ts.tv_sec = 0;
 144         ts.tv_nsec = 100000;
 145         nanosleep(&ts, NULL);
 146     }
 147 
 148  done:
 149     /* finalize us */
 150     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 151     PMIx_Deregister_event_handler(1, op_callbk, NULL);
 152 
 153     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 154         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 155     } else {
 156         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 157     }
 158     fflush(stderr);
 159     return(0);
 160 }

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