This source file includes following definitions.
- cbfunc
- notification_fn
- evhandler_reg_callbk
- main
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 
  24 
  25 
  26 #define _GNU_SOURCE
  27 #include <stdbool.h>
  28 #include <stdio.h>
  29 #include <stdlib.h>
  30 #include <unistd.h>
  31 #include <time.h>
  32 
  33 #include <pmix_tool.h>
  34 
  35 
  36 
  37 typedef struct {
  38     volatile bool active;
  39     pmix_info_t *info;
  40     size_t ninfo;
  41 } myquery_data_t;
  42 
  43 
  44 static pmix_proc_t myproc;
  45 
  46 
  47 
  48 
  49 
  50 
  51 
  52 
  53 
  54 
  55 
  56 
  57 
  58 static void cbfunc(pmix_status_t status,
  59                    pmix_info_t *info, size_t ninfo,
  60                    void *cbdata,
  61                    pmix_release_cbfunc_t release_fn,
  62                    void *release_cbdata)
  63 {
  64     myquery_data_t *mq = (myquery_data_t*)cbdata;
  65     size_t n;
  66 
  67     
  68 
  69     if (0 < ninfo) {
  70         PMIX_INFO_CREATE(mq->info, ninfo);
  71         mq->ninfo = ninfo;
  72         for (n=0; n < ninfo; n++) {
  73             fprintf(stderr, "Transferring %s\n", info[n].key);
  74             PMIX_INFO_XFER(&mq->info[n], &info[n]);
  75         }
  76     }
  77 
  78     
  79     if (NULL != release_fn) {
  80         release_fn(release_cbdata);
  81     }
  82 
  83     
  84     mq->active = false;
  85 }
  86 
  87 
  88 
  89 
  90 
  91 static void notification_fn(size_t evhdlr_registration_id,
  92                             pmix_status_t status,
  93                             const pmix_proc_t *source,
  94                             pmix_info_t info[], size_t ninfo,
  95                             pmix_info_t results[], size_t nresults,
  96                             pmix_event_notification_cbfunc_fn_t cbfunc,
  97                             void *cbdata)
  98 {
  99     if (NULL != cbfunc) {
 100         cbfunc(PMIX_EVENT_ACTION_COMPLETE, NULL, 0, NULL, NULL, cbdata);
 101     }
 102 }
 103 
 104 
 105 
 106 
 107 
 108 
 109 
 110 
 111 static void evhandler_reg_callbk(pmix_status_t status,
 112                                  size_t evhandler_ref,
 113                                  void *cbdata)
 114 {
 115     volatile int *active = (volatile int*)cbdata;
 116 
 117     if (PMIX_SUCCESS != status) {
 118         fprintf(stderr, "Client %s:%d EVENT HANDLER REGISTRATION FAILED WITH STATUS %d, ref=%lu\n",
 119                    myproc.nspace, myproc.rank, status, (unsigned long)evhandler_ref);
 120     }
 121     *active = status;
 122 }
 123 
 124 int main(int argc, char **argv)
 125 {
 126     pmix_status_t rc;
 127     pmix_value_t *val;
 128     pmix_proc_t proc;
 129     pmix_info_t *info;
 130     size_t ninfo;
 131     volatile int active;
 132     pmix_query_t *query;
 133     size_t nq, n;
 134     myquery_data_t myquery_data;
 135 
 136 fprintf(stderr, "I AM HERE\n");
 137 fflush(stderr);
 138     sleep(10);
 139     exit(0);
 140 
 141     
 142 
 143     if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, NULL, 0))) {
 144         fprintf(stderr, "Debugger daemon ns %s rank %d: PMIx_tool_init failed: %d\n", myproc.nspace, myproc.rank, rc);
 145         exit(0);
 146     }
 147     fprintf(stderr, "Debugger daemon ns %s rank %d: Running\n", myproc.nspace, myproc.rank);
 148 
 149 
 150     
 151     active = -1;
 152     PMIx_Register_event_handler(NULL, 0, NULL, 0,
 153                                 notification_fn, evhandler_reg_callbk, (void*)&active);
 154     while (-1 == active) {
 155         usleep(10);
 156     }
 157     if (0 != active) {
 158         exit(active);
 159     }
 160 
 161     
 162     (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
 163     proc.rank = PMIX_RANK_WILDCARD;
 164     if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_DEBUG_JOB, NULL, 0, &val))) {
 165         fprintf(stderr, "[%s:%d] Failed to get job being debugged - error %d\n", myproc.nspace, myproc.rank, rc);
 166         goto done;
 167     }
 168     if (NULL == val) {
 169         fprintf(stderr, "Got NULL return\n");
 170         goto done;
 171     }
 172     fprintf(stderr, "[%s:%d] Debugging %s\n", myproc.nspace, myproc.rank, val->data.string);
 173 
 174     
 175 
 176 
 177 
 178     nq = 1;
 179     PMIX_QUERY_CREATE(query, nq);
 180     PMIX_ARGV_APPEND(rc, query[0].keys, PMIX_QUERY_LOCAL_PROC_TABLE);
 181     query[0].nqual = 1;
 182     PMIX_INFO_CREATE(query[0].qualifiers, 1);
 183     PMIX_INFO_LOAD(&query[0].qualifiers[0], PMIX_NSPACE, val->data.string, PMIX_STRING);  
 184     
 185     myquery_data.info = NULL;
 186     myquery_data.ninfo = 0;
 187     myquery_data.active = true;
 188     
 189     if (PMIX_SUCCESS != (rc = PMIx_Query_info_nb(query, nq, cbfunc, (void*)&myquery_data))) {
 190         fprintf(stderr, "PMIx_Query_info failed: %d\n", rc);
 191         goto done;
 192     }
 193     while (myquery_data.active) {
 194         usleep(10);
 195     }
 196     fprintf(stderr, "[%s:%d] Local proctable received\n", myproc.nspace, myproc.rank);
 197 
 198 
 199     
 200 
 201 
 202 
 203     (void)strncpy(proc.nspace, val->data.string, PMIX_MAX_NSLEN);
 204     proc.rank = PMIX_RANK_WILDCARD;
 205     
 206     ninfo = 1;
 207     PMIX_INFO_CREATE(info, ninfo);
 208     PMIX_INFO_LOAD(&info[0], PMIX_EVENT_CUSTOM_RANGE, &proc, PMIX_PROC);  
 209     fprintf(stderr, "[%s:%u] Sending release\n", myproc.nspace, myproc.rank);
 210     PMIx_Notify_event(PMIX_ERR_DEBUGGER_RELEASE,
 211                       NULL, PMIX_RANGE_LOCAL,
 212                       info, ninfo, NULL, NULL);
 213 
 214     
 215     n = 0;
 216     fprintf(stderr, "[%s:%u] Hanging around awhile, doing debugger magic\n", myproc.nspace, myproc.rank);
 217     while (n < 5) {
 218         usleep(1000);
 219         ++n;
 220     }
 221 
 222   done:
 223     
 224     fprintf(stderr, "Debugger daemon ns %s rank %d: Finalizing\n", myproc.nspace, myproc.rank);
 225     if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
 226         fprintf(stderr, "Debugger daemon ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace, myproc.rank, rc);
 227     } else {
 228         fprintf(stderr, "Debugger daemon ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
 229     }
 230     fflush(stderr);
 231     return(0);
 232 }