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

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

DEFINITIONS

This source file includes following definitions.
  1. notification_fn
  2. errhandler_reg_callbk
  3. 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-2019 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 1
  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 #define SIMPIO_MSG_MAX   8192
  70 
  71 int main(int argc, char **argv)
  72 {
  73     pmix_status_t rc;
  74     volatile bool active;
  75     int msgsize;
  76     char msg[SIMPIO_MSG_MAX];
  77     pmix_proc_t proc;
  78     int cnt = 0;
  79 
  80     /* init us */
  81     if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
  82         pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %s",
  83                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
  84         exit(rc);
  85     }
  86     pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
  87 
  88     /* register our errhandler */
  89     active = true;
  90     PMIx_Register_event_handler(NULL, 0, NULL, 0,
  91                                 notification_fn, errhandler_reg_callbk, (void*)&active);
  92     while (active) {
  93         usleep(10);
  94     }
  95 
  96     /* if we are rank=0, read our stdin */
  97     if (0 == myproc.rank) {
  98         while (0 < (msgsize = read(0, msg, SIMPIO_MSG_MAX))) {
  99             cnt += msgsize;
 100             fprintf(stderr, "Rank %d: read %d bytes\n", myproc.rank, cnt);
 101         }
 102     }
 103 
 104     /* call fence to sync */
 105     PMIX_PROC_CONSTRUCT(&proc);
 106     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 107     proc.rank = PMIX_RANK_WILDCARD;
 108     if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
 109         pmix_output(0, "Client ns %s rank %d PMIx_Fence failed: %s",
 110                     myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 111     }
 112 
 113     /* finalize us */
 114     pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
 115     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 116         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %s\n",
 117                 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
 118     } else {
 119         fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 120     }
 121     fflush(stderr);
 122     return(rc);
 123 }

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