Skip to content

Commit c4ed8c3

Browse files
committed
Add new client example
Test fetch of PMIX_RANK, PMIX_NODEID, and PMIX_APPNUM Signed-off-by: Ralph Castain <[email protected]>
1 parent bbee0e8 commit c4ed8c3

File tree

4 files changed

+195
-3
lines changed

4 files changed

+195
-3
lines changed

.github/workflows/pmix_mpi4py.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ jobs:
163163
- name: Test mpi4py (np=5)
164164
run: mpiexec -n 5 python test/main.py -v -f
165165
if: ${{ true }}
166-
timeout-minutes: 5
166+
timeout-minutes: 10
167167

168168
- name: Test mpi4py.run
169169
run: python demo/test-run/test_run.py -v
170170
if: ${{ true }}
171-
timeout-minutes: 5
171+
timeout-minutes: 10

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ examples/alloc
7777
examples/client
7878
examples/client2
7979
examples/client3
80+
examples/client4
8081
examples/debugger
8182
examples/debuggerd
8283
examples/dmodex

examples/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_builddir)/src/include -I$(top_buildd
2727
noinst_PROGRAMS = client client2 dmodex dynamic fault pub pubi \
2828
tool debugger debuggerd alloc jctrl group group_dmodex asyncgroup \
2929
hello nodeinfo abi_no_init abi_with_init group_lcl_cid pset log \
30-
group_bootstrap client3 launcher spawn_group resolve multi_nspace_group \
30+
group_bootstrap client3 client4 launcher spawn_group resolve multi_nspace_group \
3131
pub2 toolqry simple_resolve pubstress
3232

3333
if !WANT_HIDDEN
@@ -48,6 +48,10 @@ client3_SOURCES = client3.c examples.h
4848
client3_LDFLAGS = $(PMIX_PKG_CONFIG_LDFLAGS)
4949
client3_LDADD = $(top_builddir)/src/libpmix.la
5050

51+
client4_SOURCES = client4.c examples.h
52+
client4_LDFLAGS = $(PMIX_PKG_CONFIG_LDFLAGS)
53+
client4_LDADD = $(top_builddir)/src/libpmix.la
54+
5155
debugger_SOURCES = debugger.c examples.h
5256
debugger_LDFLAGS = $(PMIX_PKG_CONFIG_LDFLAGS)
5357
debugger_LDADD = $(top_builddir)/src/libpmix.la

examples/client4.c

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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

Comments
 (0)