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 #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 3
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
70
71
72
73
74
75
76 static void model_callback(size_t evhdlr_registration_id,
77 pmix_status_t status,
78 const pmix_proc_t *source,
79 pmix_info_t info[], size_t ninfo,
80 pmix_info_t results[], size_t nresults,
81 pmix_event_notification_cbfunc_fn_t cbfunc,
82 void *cbdata)
83 {
84 size_t n;
85
86
87 fprintf(stderr, "%s:%d Model event handler called with status %d(%s)\n",
88 myproc.nspace, myproc.rank, status, PMIx_Error_string(status));
89 for (n=0; n < ninfo; n++) {
90 if (PMIX_STRING == info[n].value.type) {
91 fprintf(stderr, "%s:%d\t%s:\t%s\n",
92 myproc.nspace, myproc.rank,
93 info[n].key, info[n].value.data.string);
94 }
95 }
96
97
98
99
100 if (NULL != cbfunc) {
101 cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
102 }
103 }
104
105
106 static void model_registration_callback(pmix_status_t status,
107 size_t evhandler_ref,
108 void *cbdata)
109 {
110 volatile int *active = (volatile int*)cbdata;
111
112 fprintf(stderr, "simpclient EVENT HANDLER REGISTRATION RETURN STATUS %d, ref=%lu\n",
113 status, (unsigned long)evhandler_ref);
114 *active = false;
115 }
116
117 int main(int argc, char **argv)
118 {
119 int rc;
120 pmix_value_t value;
121 pmix_value_t *val = &value;
122 char *tmp;
123 pmix_proc_t proc;
124 uint32_t nprocs, n;
125 int cnt, j;
126 volatile bool active;
127 pmix_info_t info, *iptr;
128 size_t ninfo;
129 pmix_status_t code;
130
131
132 PMIX_INFO_CREATE(iptr, 2);
133 PMIX_INFO_LOAD(&iptr[0], PMIX_PROGRAMMING_MODEL, "TEST", PMIX_STRING);
134 PMIX_INFO_LOAD(&iptr[1], PMIX_MODEL_LIBRARY_NAME, "PMIX", PMIX_STRING);
135 if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, iptr, 2))) {
136 pmix_output(0, "Client ns %s rank %d: PMIx_Init failed: %s",
137 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
138 exit(rc);
139 }
140 PMIX_INFO_FREE(iptr, 2);
141 pmix_output(0, "Client ns %s rank %d: Running", myproc.nspace, myproc.rank);
142
143
144 (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
145 proc.rank = PMIX_RANK_WILDCARD;
146 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_JOB_SIZE, NULL, 0, &val))) {
147 pmix_output(0, "Client ns %s rank %d: PMIx_Get failed: %s",
148 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
149 exit(rc);
150 }
151 nprocs = val->data .uint32;
152 PMIX_VALUE_RELEASE(val);
153 pmix_output(0, "Client %s:%d universe size %d", myproc.nspace, myproc.rank, nprocs);
154
155
156 active = true;
157 ninfo = 1;
158 PMIX_INFO_CREATE(iptr, ninfo);
159 PMIX_INFO_LOAD(&iptr[0], PMIX_EVENT_HDLR_NAME, "SIMPCLIENT-MODEL", PMIX_STRING);
160 code = PMIX_MODEL_DECLARED;
161 PMIx_Register_event_handler(&code, 1, iptr, ninfo,
162 model_callback, model_registration_callback, (void*)&active);
163 while (active) {
164 usleep(10);
165 }
166 PMIX_INFO_FREE(iptr, ninfo);
167
168
169 active = true;
170 PMIx_Register_event_handler(NULL, 0, NULL, 0,
171 notification_fn, errhandler_reg_callbk, (void*)&active);
172 while (active) {
173 usleep(10);
174 }
175
176 memset(&info, 0, sizeof(pmix_info_t));
177 (void)strncpy(info.key, PMIX_COLLECT_DATA, PMIX_MAX_KEYLEN);
178 info.value.type = PMIX_UNDEF;
179 info.value.data.flag = 1;
180
181 for (cnt=0; cnt < MAXCNT; cnt++) {
182 pmix_output(0, "EXECUTING LOOP %d", cnt);
183 for (j=0; j < 10; j++) {
184 (void)asprintf(&tmp, "%s-%d-gasnet-%d-%d", myproc.nspace, myproc.rank, cnt, j);
185 value.type = PMIX_UINT64;
186 value.data.uint64 = 1234;
187 if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_GLOBAL, tmp, &value))) {
188 pmix_output(0, "Client ns %s rank %d: PMIx_Put failed: %s",
189 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
190 goto done;
191 }
192 free(tmp);
193 }
194
195 if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
196 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Commit failed: %s",
197 myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
198 goto done;
199 }
200
201
202 if (PMIX_SUCCESS != (rc = PMIx_Fence(NULL, 0, &info, 1))) {
203 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Fence failed: %s",
204 myproc.nspace, myproc.rank, cnt, PMIx_Error_string(rc));
205 goto done;
206 }
207
208
209 (void)strncpy(proc.nspace, myproc.nspace, PMIX_MAX_NSLEN);
210 proc.rank = PMIX_RANK_UNDEF;
211 for (j=0; j < 10; j++) {
212 for (n=0; n < nprocs; n++) {
213 (void)asprintf(&tmp, "%s-%d-gasnet-%d-%d", myproc.nspace, n, cnt, j);
214 if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
215 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s failed: %s",
216 myproc.nspace, myproc.rank, j, tmp, PMIx_Error_string(rc));
217 continue;
218 }
219 if (NULL == val) {
220 pmix_output(0, "Client ns %s rank %d: NULL value returned",
221 myproc.nspace, myproc.rank);
222 break;
223 }
224 if (PMIX_UINT64 != val->type) {
225 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);
226 PMIX_VALUE_RELEASE(val);
227 free(tmp);
228 continue;
229 }
230 if (1234 != val->data.uint64) {
231 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);
232 PMIX_VALUE_RELEASE(val);
233 free(tmp);
234 continue;
235 }
236 pmix_output(0, "Client ns %s rank %d cnt %d: PMIx_Get %s returned correct", myproc.nspace, myproc.rank, j, tmp);
237 PMIX_VALUE_RELEASE(val);
238 free(tmp);
239 }
240 }
241 }
242
243 done:
244
245 pmix_output(0, "Client ns %s rank %d: Finalizing", myproc.nspace, myproc.rank);
246 if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
247 fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %s\n",
248 myproc.nspace, myproc.rank, PMIx_Error_string(rc));
249 } else {
250 fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n", myproc.nspace, myproc.rank);
251 }
252 fflush(stderr);
253 return(rc);
254 }