Skip to content

Commit 7f458b5

Browse files
committed
Update the dmodex example
Signed-off-by: Ralph Castain <[email protected]>
1 parent 518dc6a commit 7f458b5

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

examples/dmodex.c

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
1818
* Copyright (c) 2019-2022 IBM Corporation. All rights reserved.
1919
* Copyright (c) 2021-2022 Nanook Consulting All rights reserved.
20-
* Copyright (c) 2022 Triad National Security, LLC. All rights reserved.
2120
* $COPYRIGHT$
2221
*
2322
* Additional copyrights may follow
@@ -26,15 +25,13 @@
2625
*
2726
*/
2827

29-
#include "examples.h"
30-
#include "src/include/pmix_config.h"
31-
#include "../include/pmix.h"
32-
33-
3428
#include <stdio.h>
3529
#include <stdlib.h>
3630
#include <time.h>
3731
#include <unistd.h>
32+
#include <pmix.h>
33+
34+
#include "examples.h"
3835

3936
static uint32_t nprocs;
4037
static pmix_proc_t myproc;
@@ -51,6 +48,8 @@ int main(int argc, char **argv)
5148
char **peers;
5249
pmix_rank_t *locals = NULL;
5350
uint8_t j;
51+
pmix_info_t timeout;
52+
int tlimit = 10;
5453

5554
EXAMPLES_HIDE_UNUSED_PARAMS(argc, argv);
5655

@@ -60,7 +59,6 @@ int main(int argc, char **argv)
6059
rc);
6160
exit(0);
6261
}
63-
fprintf(stderr, "Client ns %s rank %d: Running\n", myproc.nspace, myproc.rank);
6462

6563
/* get our job size */
6664
PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_WILDCARD);
@@ -71,7 +69,10 @@ int main(int argc, char **argv)
7169
}
7270
nprocs = val->data.uint32;
7371
PMIX_VALUE_RELEASE(val);
74-
fprintf(stderr, "Client %s:%d job size %d\n", myproc.nspace, myproc.rank, nprocs);
72+
73+
if(0 == myproc.rank) {
74+
fprintf(stderr, "Client ns %s rank %d: Running. World size %d\n", myproc.nspace, myproc.rank, nprocs);
75+
}
7576

7677
/* put a few values */
7778
(void) snprintf(tmp, 1024, "%s-%d-internal", myproc.nspace, myproc.rank);
@@ -144,9 +145,14 @@ int main(int argc, char **argv)
144145
PMIX_ARGV_FREE(peers);
145146

146147
PMIX_LOAD_NSPACE(proc.nspace, myproc.nspace);
148+
PMIX_INFO_LOAD(&timeout, PMIX_TIMEOUT, &tlimit, PMIX_INT);
147149
/* get the committed data - ask for someone who doesn't exist as well */
148150
for (n = 0; n < nprocs; n++) {
149-
if (all_local) {
151+
if (n == myproc.rank) {
152+
/* local peers doesn't include us, so check for
153+
* ourselves separately */
154+
local = true;
155+
} else if (all_local) {
150156
local = true;
151157
} else {
152158
local = false;
@@ -161,70 +167,64 @@ int main(int argc, char **argv)
161167
proc.rank = n;
162168
if (local) {
163169
(void)snprintf(tmp, 1024, "%s-%d-local", proc.nspace, n);
164-
if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
165-
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, n,
166-
tmp, rc);
170+
if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, &timeout, 1, &val))) {
171+
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %s\n", myproc.nspace, myproc.rank,
172+
tmp, PMIx_Error_string(rc));
167173
goto done;
168174
}
169175
if (PMIX_UINT64 != val->type) {
170-
fprintf(stderr, "%s:%d: PMIx_Get Key %s returned wrong type: %d\n", myproc.nspace,
171-
myproc.rank, tmp, val->type);
176+
fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong type: %s\n", myproc.nspace,
177+
myproc.rank, tmp, PMIx_Data_type_string(val->type));
172178
PMIX_VALUE_RELEASE(val);
173179
goto done;
174180
}
175181
if (1234 != val->data.uint64) {
176-
fprintf(stderr, "%s:%d: PMIx_Get Key %s returned wrong value: %d\n", myproc.nspace,
182+
fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong value: %d\n", myproc.nspace,
177183
myproc.rank, tmp, (int) val->data.uint64);
178184
PMIX_VALUE_RELEASE(val);
179185
goto done;
180186
}
181-
fprintf(stderr, "%s:%d Local value for %s:%d successfully retrieved\n", myproc.nspace,
182-
myproc.rank, proc.nspace, proc.rank);
183187
PMIX_VALUE_RELEASE(val);
184188
} else {
185189
(void)snprintf(tmp, 1024, "%s-%d-remote", myproc.nspace, n);
186-
if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) {
187-
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, n,
188-
tmp, rc);
190+
if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, &timeout, 1, &val))) {
191+
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %s\n", myproc.nspace, myproc.rank,
192+
tmp, PMIx_Error_string(rc));
189193
goto done;
190194
}
191195
if (PMIX_STRING != val->type) {
192-
fprintf(stderr, "%s:%d: PMIx_Get Key %s returned wrong type: %d\n", myproc.nspace,
193-
myproc.rank, tmp, val->type);
196+
fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong type: %s\n", myproc.nspace,
197+
myproc.rank, tmp, PMIx_Data_type_string(val->type));
194198
PMIX_VALUE_RELEASE(val);
195199
goto done;
196200
}
197201
if (0 != strcmp(val->data.string, "1234")) {
198-
fprintf(stderr, "%s:%d: PMIx_Get Key %s returned wrong value: %s\n", myproc.nspace,
202+
fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong value: %s\n", myproc.nspace,
199203
myproc.rank, tmp, val->data.string);
200204
PMIX_VALUE_RELEASE(val);
201205
goto done;
202206
}
203-
fprintf(stderr, "%s:%d Remote value for %s:%d successfully retrieved\n", myproc.nspace,
204-
myproc.rank, proc.nspace, proc.rank);
205207
PMIX_VALUE_RELEASE(val);
206208
}
207209
/* if this isn't us, then get the ghex key */
208210
if (n != myproc.rank) {
209-
if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, "ghex", NULL, 0, &val))) {
210-
fprintf(stderr, "Client ns %s rank %d: PMIx_Get ghex failed: %d\n", myproc.nspace,
211-
n, rc);
211+
if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, "ghex", &timeout, 1, &val))) {
212+
fprintf(stderr, "Client ns %s rank %d: PMIx_Get ghex failed: %s\n", myproc.nspace,
213+
myproc.rank, PMIx_Error_string(rc));
212214
goto done;
213215
}
214216
if (PMIX_BYTE_OBJECT != val->type) {
215-
fprintf(stderr, "%s:%d: PMIx_Get ghex returned wrong type: %d\n", myproc.nspace,
216-
myproc.rank, val->type);
217+
fprintf(stderr, "%s:%d: PMIx_Get ghex failed - returned wrong type: %s\n", myproc.nspace,
218+
myproc.rank, PMIx_Data_type_string(val->type));
217219
PMIX_VALUE_RELEASE(val);
218220
goto done;
219221
}
220222
if (128 != val->data.bo.size) {
221-
fprintf(stderr, "%s:%d: PMIx_Get ghex returned wrong size: %d\n", myproc.nspace,
223+
fprintf(stderr, "%s:%d: PMIx_Get ghex failed - returned wrong size: %d\n", myproc.nspace,
222224
myproc.rank, (int) val->data.bo.size);
223225
PMIX_VALUE_RELEASE(val);
224226
goto done;
225227
}
226-
fprintf(stderr, "%s:%d Ghex for %s:%d successfully retrieved\n", myproc.nspace,
227-
myproc.rank, proc.nspace, proc.rank);
228228
PMIX_VALUE_RELEASE(val);
229229
}
230230
}
@@ -236,16 +236,17 @@ int main(int argc, char **argv)
236236
if (PMIX_SUCCESS != (rc = PMIx_Fence(NULL, 0, NULL, 0))) {
237237
fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank,
238238
rc);
239-
goto done;
239+
exit(1);
240240
}
241241

242-
fprintf(stderr, "Client ns %s rank %d: Finalizing\n", myproc.nspace, myproc.rank);
243242
if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
244243
fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace,
245244
myproc.rank, rc);
246245
} else {
247-
fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n",
248-
myproc.nspace, myproc.rank);
246+
if(0 == myproc.rank) {
247+
fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n",
248+
myproc.nspace, myproc.rank);
249+
}
249250
}
250251
fflush(stderr);
251252
return (0);

0 commit comments

Comments
 (0)