This source file includes following definitions.
- notification_fn
- errhandler_reg_callbk
- model_callback
- model_registration_callback
- 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
27
28
29
30
31
32
33
34
35
36
37
38 #include <src/include/pmix_config.h>
39 #include <pmix.h>
40
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <time.h>
45
46 #include "src/class/pmix_object.h"
47 #include "src/util/output.h"
48 #include "src/util/printf.h"
49
50 #define MAXCNT 1
51
52 static volatile bool completed = false;
53 static pmix_proc_t myproc;
54
55 static void notification_fn(size_t evhdlr_registration_id,
56 pmix_status_t status,
57 const pmix_proc_t *source,
58 pmix_info_t info[], size_t ninfo,
59 pmix_info_t results[], size_t nresults,
60 pmix_event_notification_cbfunc_fn_t cbfunc,
61 void *cbdata)
62 {
63 if (NULL != cbfunc) {
64 cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
65 }
66 completed = true;
67 }
68
69 static void errhandler_reg_callbk(pmix_status_t status,
70 size_t errhandler_ref,
71 void *cbdata)
72 {
73 volatile bool *active = (volatile bool*)cbdata;
74
75 *active = false;
76 }
77
78
79
80
81
82
83
84
85 static void model_callback(size_t evhdlr_registration_id,
86 pmix_status_t status,
87 const pmix_proc_t *source,
88 pmix_info_t info[], size_t ninfo,
89 pmix_info_t results[], size_t nresults,
90 pmix_event_notification_cbfunc_fn_t cbfunc,
91 void *cbdata)
92 {
93
94
95
96 if (NULL != cbfunc) {
97 cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
98 }
99 }
100
101
102 static void model_registration_callback(pmix_status_t status,
103 size_t evhandler_ref,
104 void *cbdata)
105 {
106 volatile int *active = (volatile int*)cbdata;
107
108 *active = false;
109 }
110
111 int main(int argc, char **argv)
112 {
113 int rc;
114 pmix_value_t value;
115 pmix_value_t *val = &value;
116 char *tmp;
117 pmix_proc_t proc;
118 uint32_t nprocs, n;
119 int cnt, j;
120 volatile bool active;
121 pmix_info_t *iptr;
122 size_t ninfo;
123 pmix_status_t code;
124
125
126 PMIX_INFO_CREATE(iptr, 2);
127 PMIX_INFO_LOAD(&iptr[0], PMIX_PROGRAMMING_MODEL, "TEST", PMIX_STRING);
128 PMIX_INFO_LOAD(&iptr[1], PMIX_MODEL_LIBRARY_NAME, "PMIX", PMIX_STRING);
129 if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, iptr, 2))) {
130 pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %s",
131 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
132 exit(rc);
133 }
134 PMIX_INFO_FREE(iptr, 2);
135
136
137 (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
138 proc.rank = PMIX_RANK_WILDCARD;
139 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_JOB_SIZE, NULL, 0, &val))) {
140 pmix_output(0, "Client ns %s rank %d: PMIx_Get failed: %s",
141 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
142 exit(rc);
143 }
144 PMIX_VALUE_RELEASE(val);
145
146
147 active = true;
148 ninfo = 1;
149 PMIX_INFO_CREATE(iptr, ninfo);
150 PMIX_INFO_LOAD(&iptr[0], PMIX_EVENT_HDLR_NAME, "SIMPCLIENT-MODEL", PMIX_STRING);
151 code = PMIX_MODEL_DECLARED;
152 PMIx_Register_event_handler(&code, 1, iptr, ninfo,
153 model_callback, model_registration_callback, (void*)&active);
154 while (active) {
155 usleep(10);
156 }
157 PMIX_INFO_FREE(iptr, ninfo);
158
159
160 active = true;
161 PMIx_Register_event_handler(NULL, 0, NULL, 0,
162 notification_fn, errhandler_reg_callbk, (void*)&active);
163 while (active) {
164 usleep(10);
165 }
166
167
168 (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
169 proc.rank = PMIX_RANK_WILDCARD;
170 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_UNIV_SIZE, NULL, 0, &val))) {
171 pmix_output(0, "Client ns %s rank %d: PMIx_Get universe size failed: %s",
172 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
173 goto done;
174 }
175 nprocs = val->data.uint32;
176 PMIX_VALUE_RELEASE(val);
177
178
179 (void)asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank);
180 value.type = PMIX_UINT32;
181 value.data.uint32 = 1234;
182 if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) {
183 pmix_output(0, "Client ns %s rank %d: PMIx_Store_internal failed: %s",
184 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
185 goto done;
186 }
187
188 for (cnt=0; cnt < MAXCNT; cnt++) {
189 (void)asprintf(&tmp, "%s-%d-local-%d", myproc.nspace, myproc.rank, cnt);
190 value.type = PMIX_UINT64;
191 value.data.uint64 = 1234;
192 if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) {
193 pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %s",
194 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
195 goto done;
196 }
197
198 (void)asprintf(&tmp, "%s-%d-remote-%d", myproc.nspace, myproc.rank, cnt);
199 value.type = PMIX_STRING;
200 value.data.string = "1234";
201 if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) {
202 pmix_output(0, "Client ns %s rank %d: PMIx_Put internal failed: %s",
203 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
204 goto done;
205 }
206
207 if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
208 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Commit failed: %s",
209 myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
210 goto done;
211 }
212
213
214 PMIX_PROC_CONSTRUCT(&proc);
215 (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
216 proc.rank = PMIX_RANK_WILDCARD;
217 if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, NULL, 0))) {
218 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Fence failed: %s",
219 myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
220 goto done;
221 }
222
223
224 (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
225 for (j=0; j <= cnt; j++) {
226 for (n=0; n < nprocs; n++) {
227 proc.rank = n;
228 (void)asprintf(&tmp, "%s-%d-local-%d", myproc.nspace, n, j);
229 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
230 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s failed: %s",
231 myproc.nspace, myproc.rank, j, tmp, PMIx_Error_string(rc));
232 continue;
233 }
234 if (NULL == val) {
235 pmix_output(0, "Client ns %s rank %d: NULL value returned",
236 myproc.nspace, myproc.rank);
237 break;
238 }
239 if (PMIX_UINT64 != val->type) {
240 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned wrong type: %d", myproc.nspace, myproc.rank, j, tmp, val->type);
241 PMIX_VALUE_RELEASE(val);
242 free(tmp);
243 continue;
244 }
245 if (1234 != val->data.uint64) {
246 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned wrong value: %d", myproc.nspace, myproc.rank, j, tmp, (int)val->data.uint64);
247 PMIX_VALUE_RELEASE(val);
248 free(tmp);
249 continue;
250 }
251 PMIX_VALUE_RELEASE(val);
252 free(tmp);
253
254 if (n != myproc.rank) {
255 (void)asprintf(&tmp, "%s-%d-remote-%d", proc.nspace, n, j);
256 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
257
258
259 continue;
260 }
261 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned remote data for a local proc",
262 myproc.nspace, myproc.rank, j, tmp);
263 PMIX_VALUE_RELEASE(val);
264 free(tmp);
265 }
266 }
267 }
268 }
269
270
271 if (PMIX_SUCCESS == (rc = PMIx_Get(&myproc, NULL, NULL, 0, &val))) {
272 if (PMIX_DATA_ARRAY != val->type) {
273 pmix_output(0, "Client ns %s rank %d did not return an array for its internal modex blob",
274 myproc.nspace, myproc.rank);
275 PMIX_VALUE_RELEASE(val);
276 } else if (PMIX_INFO != val->data.darray->type) {
277 pmix_output(0, "Client ns %s rank %d returned an internal modex array of type %s instead of PMIX_INFO",
278 myproc.nspace, myproc.rank, PMIx_Data_type_string(val->data.darray->type));
279 PMIX_VALUE_RELEASE(val);
280 } else if (0 == val->data.darray->size) {
281 pmix_output(0, "Client ns %s rank %d returned an internal modex array of zero length",
282 myproc.nspace, myproc.rank);
283 PMIX_VALUE_RELEASE(val);
284 } else {
285 PMIX_VALUE_RELEASE(val);
286 }
287 } else {
288 pmix_output(0, "Client ns %s rank %d internal modex blob FAILED with error %s(%d)",
289 myproc.nspace, myproc.rank, PMIx_Error_string(rc), rc);
290 }
291
292 done:
293
294 if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
295 fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %s\n",
296 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
297 }
298 fflush(stderr);
299 return(rc);
300 }