|
16 | 16 | * Copyright (c) 2013-2020 Intel, Inc. All rights reserved.
|
17 | 17 | * Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
|
18 | 18 | * Copyright (c) 2019 IBM Corporation. All rights reserved.
|
19 |
| - * Copyright (c) 2021 Nanook Consulting. All rights reserved. |
| 19 | + * Copyright (c) 2021-2022 Nanook Consulting. All rights reserved. |
20 | 20 | * $COPYRIGHT$
|
21 | 21 | *
|
22 | 22 | * Additional copyrights may follow
|
@@ -125,14 +125,17 @@ int main(int argc, char **argv)
|
125 | 125 | pmix_value_t *val = NULL;
|
126 | 126 | char *tmp;
|
127 | 127 | pmix_proc_t proc;
|
128 |
| - uint32_t nprocs, n; |
| 128 | + uint32_t nprocs, n, k, nlocal; |
| 129 | + bool local, all_local = false;; |
129 | 130 | pmix_info_t *info;
|
130 | 131 | bool flag;
|
131 | 132 | mylock_t mylock;
|
132 | 133 | myrel_t myrel;
|
133 | 134 | pmix_status_t dbg = PMIX_ERR_DEBUGGER_RELEASE;
|
134 | 135 | pid_t pid;
|
135 | 136 | pmix_topology_t mytopo;
|
| 137 | + char **peers; |
| 138 | + pmix_rank_t *locals = NULL; |
136 | 139 |
|
137 | 140 | EXAMPLES_HIDE_UNUSED_PARAMS(argc, argv);
|
138 | 141 |
|
@@ -295,62 +298,99 @@ int main(int argc, char **argv)
|
295 | 298 | }
|
296 | 299 | PMIX_INFO_FREE(info, 1);
|
297 | 300 |
|
| 301 | + /* get a list of our local peers */ |
| 302 | + if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_LOCAL_PEERS, NULL, 0, &val))) { |
| 303 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get local peers failed: %s\n", myproc.nspace, |
| 304 | + myproc.rank, PMIx_Error_string(rc)); |
| 305 | + goto done; |
| 306 | + } |
| 307 | + /* split the returned string to get the rank of each local peer */ |
| 308 | + peers = pmix_argv_split(val->data.string, ','); |
| 309 | + PMIX_VALUE_RELEASE(val); |
| 310 | + nlocal = pmix_argv_count(peers); |
| 311 | + if (nprocs == nlocal) { |
| 312 | + all_local = true; |
| 313 | + } else { |
| 314 | + all_local = false; |
| 315 | + locals = (pmix_rank_t *) malloc(pmix_argv_count(peers) * sizeof(pmix_rank_t)); |
| 316 | + for (n = 0; NULL != peers[n]; n++) { |
| 317 | + locals[n] = strtoul(peers[n], NULL, 10); |
| 318 | + } |
| 319 | + } |
| 320 | + PMIX_ARGV_FREE(peers); |
| 321 | + |
298 | 322 | /* check the returned data */
|
299 | 323 | for (n = 0; n < nprocs; n++) {
|
300 |
| - if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank)) { |
301 |
| - exit(1); |
302 |
| - } |
303 |
| - if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, tmp, NULL, 0, &val))) { |
304 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, |
305 |
| - myproc.rank, tmp, rc); |
306 |
| - free(tmp); |
307 |
| - goto done; |
308 |
| - } |
309 |
| - if (PMIX_UINT64 != val->type) { |
310 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n", |
311 |
| - myproc.nspace, myproc.rank, tmp, val->type); |
312 |
| - PMIX_VALUE_RELEASE(val); |
313 |
| - free(tmp); |
314 |
| - goto done; |
315 |
| - } |
316 |
| - if (1234 != val->data.uint64) { |
317 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %d\n", |
318 |
| - myproc.nspace, myproc.rank, tmp, (int) val->data.uint64); |
319 |
| - PMIX_VALUE_RELEASE(val); |
320 |
| - free(tmp); |
321 |
| - goto done; |
322 |
| - } |
323 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned correct\n", myproc.nspace, |
324 |
| - myproc.rank, tmp); |
325 |
| - PMIX_VALUE_RELEASE(val); |
326 |
| - free(tmp); |
327 |
| - if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank)) { |
328 |
| - exit(1); |
| 324 | + if (all_local) { |
| 325 | + local = true; |
| 326 | + } else { |
| 327 | + local = false; |
| 328 | + /* see if this proc is local to us */ |
| 329 | + for (k = 0; k < nlocal; k++) { |
| 330 | + if (n == locals[k]) { |
| 331 | + local = true; |
| 332 | + break; |
| 333 | + } |
| 334 | + } |
329 | 335 | }
|
330 |
| - if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, tmp, NULL, 0, &val))) { |
331 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, |
332 |
| - myproc.rank, tmp, rc); |
333 |
| - free(tmp); |
334 |
| - goto done; |
335 |
| - } |
336 |
| - if (PMIX_STRING != val->type) { |
337 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n", |
338 |
| - myproc.nspace, myproc.rank, tmp, val->type); |
| 336 | + proc.rank = n; |
| 337 | + if (local) { |
| 338 | + if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, proc.rank)) { |
| 339 | + exit(1); |
| 340 | + } |
| 341 | + if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) { |
| 342 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, |
| 343 | + myproc.rank, tmp, rc); |
| 344 | + free(tmp); |
| 345 | + goto done; |
| 346 | + } |
| 347 | + if (PMIX_UINT64 != val->type) { |
| 348 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n", |
| 349 | + myproc.nspace, myproc.rank, tmp, val->type); |
| 350 | + PMIX_VALUE_RELEASE(val); |
| 351 | + free(tmp); |
| 352 | + goto done; |
| 353 | + } |
| 354 | + if (1234 != val->data.uint64) { |
| 355 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %d\n", |
| 356 | + myproc.nspace, myproc.rank, tmp, (int) val->data.uint64); |
| 357 | + PMIX_VALUE_RELEASE(val); |
| 358 | + free(tmp); |
| 359 | + goto done; |
| 360 | + } |
| 361 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned correct\n", myproc.nspace, |
| 362 | + myproc.rank, tmp); |
339 | 363 | PMIX_VALUE_RELEASE(val);
|
340 | 364 | free(tmp);
|
341 |
| - goto done; |
342 |
| - } |
343 |
| - if (0 != strcmp(val->data.string, "1234")) { |
344 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %s\n", |
345 |
| - myproc.nspace, myproc.rank, tmp, val->data.string); |
| 365 | + } else { |
| 366 | + if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, proc.rank)) { |
| 367 | + exit(1); |
| 368 | + } |
| 369 | + if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, NULL, 0, &val))) { |
| 370 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, |
| 371 | + myproc.rank, tmp, rc); |
| 372 | + free(tmp); |
| 373 | + goto done; |
| 374 | + } |
| 375 | + if (PMIX_STRING != val->type) { |
| 376 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong type: %d\n", |
| 377 | + myproc.nspace, myproc.rank, tmp, val->type); |
| 378 | + PMIX_VALUE_RELEASE(val); |
| 379 | + free(tmp); |
| 380 | + goto done; |
| 381 | + } |
| 382 | + if (0 != strcmp(val->data.string, "1234")) { |
| 383 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned wrong value: %s\n", |
| 384 | + myproc.nspace, myproc.rank, tmp, val->data.string); |
| 385 | + PMIX_VALUE_RELEASE(val); |
| 386 | + free(tmp); |
| 387 | + goto done; |
| 388 | + } |
| 389 | + fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned correct\n", myproc.nspace, |
| 390 | + myproc.rank, tmp); |
346 | 391 | PMIX_VALUE_RELEASE(val);
|
347 | 392 | free(tmp);
|
348 |
| - goto done; |
349 | 393 | }
|
350 |
| - fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned correct\n", myproc.nspace, |
351 |
| - myproc.rank, tmp); |
352 |
| - PMIX_VALUE_RELEASE(val); |
353 |
| - free(tmp); |
354 | 394 | }
|
355 | 395 |
|
356 | 396 | done:
|
|
0 commit comments