This source file includes following definitions.
- notification_fn
- op_callbk
- errhandler_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 #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
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
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
113 PMIx_Register_event_handler(code, 5, NULL, 0,
114 notification_fn, errhandler_reg_callbk, NULL);
115
116
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
126 if (4 < nprocs) {
127
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
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
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 }