|
| 1 | +/* |
| 2 | + * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana |
| 3 | + * University Research and Technology |
| 4 | + * Corporation. All rights reserved. |
| 5 | + * Copyright (c) 2004-2011 The University of Tennessee and The University |
| 6 | + * of Tennessee Research Foundation. All rights |
| 7 | + * reserved. |
| 8 | + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, |
| 9 | + * University of Stuttgart. All rights reserved. |
| 10 | + * Copyright (c) 2004-2005 The Regents of the University of California. |
| 11 | + * All rights reserved. |
| 12 | + * Copyright (c) 2006-2013 Los Alamos National Security, LLC. |
| 13 | + * All rights reserved. |
| 14 | + * Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved. |
| 15 | + * Copyright (c) 2011 Oak Ridge National Labs. All rights reserved. |
| 16 | + * Copyright (c) 2013-2020 Intel, Inc. All rights reserved. |
| 17 | + * Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved. |
| 18 | + * Copyright (c) 2019 IBM Corporation. All rights reserved. |
| 19 | + * Copyright (c) 2021-2025 Nanook Consulting All rights reserved. |
| 20 | + * Copyright (c) 2022 ParTec AG. All rights reserved. |
| 21 | + * $COPYRIGHT$ |
| 22 | + * |
| 23 | + * Additional copyrights may follow |
| 24 | + * |
| 25 | + * $HEADER$ |
| 26 | + * |
| 27 | + */ |
| 28 | + |
| 29 | +#define _GNU_SOURCE |
| 30 | +#include <stdbool.h> |
| 31 | +#include <stdio.h> |
| 32 | +#include <stdlib.h> |
| 33 | +#include <time.h> |
| 34 | +#include <unistd.h> |
| 35 | + |
| 36 | +#include "examples.h" |
| 37 | +#include <pmix.h> |
| 38 | + |
| 39 | +int main(int argc, char **argv) |
| 40 | +{ |
| 41 | + pmix_proc_t myproc; |
| 42 | + pmix_status_t rc; |
| 43 | + pmix_value_t *val = NULL; |
| 44 | + pmix_proc_t proc; |
| 45 | + |
| 46 | + EXAMPLES_HIDE_UNUSED_PARAMS(argc, argv); |
| 47 | + |
| 48 | + if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) { |
| 49 | + if (PMIX_ERR_UNREACH == rc) { |
| 50 | + fprintf(stderr, "%s: Cannot operate as singleton\n", |
| 51 | + PMIx_Proc_string(&myproc)); |
| 52 | + } else { |
| 53 | + fprintf(stderr, "%s: PMIx_Init failed: %s\n", |
| 54 | + PMIx_Proc_string(&myproc), |
| 55 | + PMIx_Error_string(rc)); |
| 56 | + } |
| 57 | + exit(1); |
| 58 | + } |
| 59 | + fprintf(stderr, "%s: Running\n", PMIx_Proc_string(&myproc)); |
| 60 | + |
| 61 | + // get our rank |
| 62 | + PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_INVALID); |
| 63 | + rc = PMIx_Get(&proc, PMIX_RANK, NULL, 0, &val); |
| 64 | + if (PMIX_SUCCESS != rc) { |
| 65 | + fprintf(stderr, "%s: Get rank failed - %s\n", PMIx_Proc_string(&myproc), PMIx_Error_string(rc)); |
| 66 | + fflush(stderr); |
| 67 | + goto done; |
| 68 | + } |
| 69 | + if (val->data.rank != myproc.rank) { |
| 70 | + fprintf(stderr, "%s: Get rank returned wrong rank - %u instead of %u\n", |
| 71 | + PMIx_Proc_string(&myproc), val->data.rank, myproc.rank); |
| 72 | + fflush(stderr); |
| 73 | + goto done; |
| 74 | + } |
| 75 | + fprintf(stderr, "%s: Rank return correct\n", PMIx_Proc_string(&myproc)); |
| 76 | + PMIX_VALUE_RELEASE(val); |
| 77 | + |
| 78 | + // get our node ID |
| 79 | + rc = PMIx_Get(&myproc, PMIX_NODEID, NULL, 0, &val); |
| 80 | + if (PMIX_SUCCESS != rc) { |
| 81 | + fprintf(stderr, "%s: Get my nodeID failed - %s\n", PMIx_Proc_string(&myproc), PMIx_Error_string(rc)); |
| 82 | + fflush(stderr); |
| 83 | + goto done; |
| 84 | + } |
| 85 | + // rank=0 is on node 0, rank=1 on node 1 |
| 86 | + if (val->data.uint32 != myproc.rank) { |
| 87 | + fprintf(stderr, "%s: Get my nodeID returned wrong value - %u instead of %u\n", |
| 88 | + PMIx_Proc_string(&myproc), val->data.uint32, myproc.rank); |
| 89 | + fflush(stderr); |
| 90 | + goto done; |
| 91 | + } |
| 92 | + fprintf(stderr, "%s: NodeID return correct\n", PMIx_Proc_string(&myproc)); |
| 93 | + PMIX_VALUE_RELEASE(val); |
| 94 | + |
| 95 | + // get our node ID with rank=WILDCARD - should fail! |
| 96 | + PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_WILDCARD); |
| 97 | + rc = PMIx_Get(&proc, PMIX_NODEID, NULL, 0, &val); |
| 98 | + if (PMIX_SUCCESS == rc) { |
| 99 | + fprintf(stderr, "%s: Get my nodeID with WILDCARD rank incorrectly succeeded\n", |
| 100 | + PMIx_Proc_string(&myproc)); |
| 101 | + fflush(stderr); |
| 102 | + goto done; |
| 103 | + } |
| 104 | + fprintf(stderr, "%s: NodeID with WILDCARD rank correctly failed - %s\n", |
| 105 | + PMIx_Proc_string(&myproc), PMIx_Error_string(rc)); |
| 106 | + PMIX_VALUE_RELEASE(val); |
| 107 | + |
| 108 | + // get our peer's nodeID |
| 109 | + if (0 == myproc.rank) { |
| 110 | + proc.rank = 1; |
| 111 | + } else { |
| 112 | + proc.rank = 0; |
| 113 | + } |
| 114 | + rc = PMIx_Get(&proc, PMIX_NODEID, NULL, 0, &val); |
| 115 | + if (PMIX_SUCCESS != rc) { |
| 116 | + fprintf(stderr, "%s: Get peer's nodeID failed - %s\n", PMIx_Proc_string(&myproc), PMIx_Error_string(rc)); |
| 117 | + fflush(stderr); |
| 118 | + goto done; |
| 119 | + } |
| 120 | + // rank=0 is on node 0, rank=1 on node 1 |
| 121 | + if (val->data.uint32 != proc.rank) { |
| 122 | + fprintf(stderr, "%s: Get peer's nodeID returned wrong value - %u instead of %u\n", |
| 123 | + PMIx_Proc_string(&myproc), val->data.uint32, proc.rank); |
| 124 | + fflush(stderr); |
| 125 | + goto done; |
| 126 | + } |
| 127 | + fprintf(stderr, "%s: Peer's NodeID return correct\n", PMIx_Proc_string(&myproc)); |
| 128 | + PMIX_VALUE_RELEASE(val); |
| 129 | + |
| 130 | + // get our appnum |
| 131 | + rc = PMIx_Get(&myproc, PMIX_APPNUM, NULL, 0, &val); |
| 132 | + if (PMIX_SUCCESS != rc) { |
| 133 | + fprintf(stderr, "%s: Get my appnum failed - %s\n", PMIx_Proc_string(&myproc), PMIx_Error_string(rc)); |
| 134 | + fflush(stderr); |
| 135 | + goto done; |
| 136 | + } |
| 137 | + // rank=0 is on node 0, rank=1 on node 1 |
| 138 | + if (val->data.uint32 != myproc.rank) { |
| 139 | + fprintf(stderr, "%s: Get my appnum returned wrong value - %u instead of %u\n", |
| 140 | + PMIx_Proc_string(&myproc), val->data.uint32, myproc.rank); |
| 141 | + fflush(stderr); |
| 142 | + goto done; |
| 143 | + } |
| 144 | + fprintf(stderr, "%s: Appnum return correct\n", PMIx_Proc_string(&myproc)); |
| 145 | + PMIX_VALUE_RELEASE(val); |
| 146 | + |
| 147 | + // get appnum with WILDCARD - should fail! |
| 148 | + PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_WILDCARD); |
| 149 | + rc = PMIx_Get(&proc, PMIX_APPNUM, NULL, 0, &val); |
| 150 | + if (PMIX_SUCCESS == rc) { |
| 151 | + fprintf(stderr, "%s: Get appnum with WILDCARD incorrectly succeeded - returned %u\n", |
| 152 | + PMIx_Proc_string(&myproc), val->data.uint32); |
| 153 | + fflush(stderr); |
| 154 | + goto done; |
| 155 | + } |
| 156 | + fprintf(stderr, "%s: Appnum with WILDCARD rank correctly failed - %s\n", |
| 157 | + PMIx_Proc_string(&myproc), PMIx_Error_string(rc)); |
| 158 | + PMIX_VALUE_RELEASE(val); |
| 159 | + |
| 160 | + // get peer's appnum |
| 161 | + if (0 == myproc.rank) { |
| 162 | + proc.rank = 1; |
| 163 | + } else { |
| 164 | + proc.rank = 0; |
| 165 | + } |
| 166 | + rc = PMIx_Get(&proc, PMIX_APPNUM, NULL, 0, &val); |
| 167 | + if (PMIX_SUCCESS != rc) { |
| 168 | + fprintf(stderr, "%s: Get peer's appnum failed - %s\n", PMIx_Proc_string(&myproc), PMIx_Error_string(rc)); |
| 169 | + fflush(stderr); |
| 170 | + goto done; |
| 171 | + } |
| 172 | + // rank=0 is in appnum 0, rank=1 is in appnum 1 |
| 173 | + if (val->data.uint32 != proc.rank) { |
| 174 | + fprintf(stderr, "%s: Get peer's appnum returned wrong value - %u instead of %u\n", |
| 175 | + PMIx_Proc_string(&myproc), val->data.uint32, myproc.rank); |
| 176 | + fflush(stderr); |
| 177 | + goto done; |
| 178 | + } |
| 179 | + fprintf(stderr, "%s: Peer's Appnum return correct\n", PMIx_Proc_string(&myproc)); |
| 180 | + PMIX_VALUE_RELEASE(val); |
| 181 | + |
| 182 | +done: |
| 183 | + /* finalize us */ |
| 184 | + rc = PMIx_Finalize(NULL, 0); |
| 185 | + fflush(stderr); |
| 186 | + return (0); |
| 187 | +} |
0 commit comments