root/opal/mca/pmix/pmix4x/pmix/test/simple/simpft.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-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/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     pmix_output(0, "Client %s:%d NOTIFIED with status %d", myproc.nspace, myproc.rank, status);
  51     if (NULL != cbfunc) {
  52         cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
  53     }
  54     completed = true;
  55 }
  56 
  57 static void op_callbk(pmix_status_t status,
  58                       void *cbdata)
  59 {
  60     pmix_output(0, "CLIENT: OP CALLBACK CALLED WITH STATUS %d", status);
  61 }
  62 
  63 static void errhandler_reg_callbk (pmix_status_t status,
  64                                    size_t errhandler_ref,
  65                                    void *cbdata)
  66 {
  67     pmix_output(0, "Client: ERRHANDLER REGISTRATION CALLBACK CALLED WITH STATUS %d, ref=%lu",
  68                 status, (unsigned long)errhandler_ref);
  69 }
  70 
  71 int main(int argc, char **argv)
  72 {
  73     int rc;
  74     pmix_value_t value;
  75     pmix_value_t *val = &value;
  76     pmix_proc_t proc;
  77     uint32_t nprocs;
  78 
  79     /* init us */
  80     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
  81         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %d", myproc.nspace, myproc.rank, rc);
  82         exit(0);
  83     }
  84     pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
  85 
  86     /* get our universe size */
  87     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
  88     proc.rank = PMIX_RANK_WILDCARD;
  89     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
  90         pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %d", myproc.nspace, myproc.rank, rc);
  91         goto done;
  92     }
  93     nprocs = val->data.uint32;
  94     PMIX_VALUE_RELEASE(val);
  95     pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs);
  96     completed = false;
  97 
  98     /* register our errhandler */
  99     PMIx_Register_event_handler(NULL, 0, NULL, 0,
 100                                 notification_fn, errhandler_reg_callbk, NULL);
 101 
 102     /* call fence to sync */
 103     PMIX_PROC_CONSTRUCT(&proc);
 104     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 105     proc.rank = PMIX_RANK_WILDCARD;
 106     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 107         pmix_output(0, "Client ns %s rank %d: PMIx_Fence failed: %d", myproc.nspace, myproc.rank, rc);
 108         goto done;
 109     }
 110 
 111     /* rank=0 calls abort */
 112     if (0 == myproc.rank) {
 113         PMIx_Abort(PMIX_ERR_OUT_OF_RESOURCE, "Eat rocks",
 114                    &proc, 1);
 115         pmix_output(0, "Client ns %s rank %d: Abort called", myproc.nspace, myproc.rank);
 116     } else {
 117     /* everyone simply waits */
 118         while (!completed) {
 119             struct timespec ts;
 120             ts.tv_sec = 0;
 121             ts.tv_nsec = 100000;
 122             nanosleep(&ts, NULL);
 123         }
 124     }
 125 
 126  done:
 127     /* finalize us */
 128     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 129     PMIx_Deregister_event_handler(1, op_callbk, NULL);
 130 
 131     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 132         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 133     } else {
 134         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 135     }
 136     fflush(stderr);
 137     return(0);
 138 }

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