File: dmodex.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (259 lines) | stat: -rw-r--r-- 10,079 bytes parent folder | download | duplicates (5)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2011 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2006-2013 Los Alamos National Security, LLC.
 *                         All rights reserved.
 * Copyright (c) 2009-2012 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2011      Oak Ridge National Labs.  All rights reserved.
 * Copyright (c) 2013-2020 Intel, Inc.  All rights reserved.
 * Copyright (c) 2015      Mellanox Technologies, Inc.  All rights reserved.
 * Copyright (c) 2019-2022 IBM Corporation.  All rights reserved.
 * Copyright (c) 2021-2023 Nanook Consulting.  All rights reserved.
 * Copyright (c) 2023      Triad National Security, LLC. All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <pmix.h>

#include "examples.h"

static uint32_t nprocs;
static pmix_proc_t myproc;

int main(int argc, char **argv)
{
    int rc, np;
    pmix_value_t value;
    pmix_value_t *val = NULL;
    char tmp[1024];
    pmix_proc_t proc;
    uint32_t n, k, nlocal;
    bool local, all_local = false;
    char **peers;
    pmix_rank_t *locals = NULL;
    uint8_t j;
    pmix_info_t timeout;
    int tlimit = 240;

    EXAMPLES_HIDE_UNUSED_PARAMS(argc, argv);

    /* init us */
    if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %d\n", myproc.nspace, myproc.rank,
                rc);
        exit(EXIT_FAILURE);
    }

    /* get our job size */
    PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_WILDCARD);
    if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_JOB_SIZE, NULL, 0, &val))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Get job size failed: %s\n", myproc.nspace,
                myproc.rank, PMIx_Error_string(rc));
        goto done;
    }
    nprocs = val->data.uint32;
    PMIX_VALUE_RELEASE(val);

    if(0 == myproc.rank) {
        fprintf(stderr, "Client ns %s rank %d: Running. World size %d\n", myproc.nspace, myproc.rank, nprocs);
    }

    /* put a few values */
    (void) snprintf(tmp, 1024, "%s-%d-internal", myproc.nspace, myproc.rank);
    value.type = PMIX_UINT32;
    value.data.uint32 = 1234;
    if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Store_internal failed: %d\n", myproc.nspace,
                myproc.rank, rc);
        goto done;
    }

    (void) snprintf(tmp, 1024, "%s-%d-local", myproc.nspace, myproc.rank);
    value.type = PMIX_UINT64;
    value.data.uint64 = 1234;
    if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace,
                myproc.rank, rc);
        goto done;
    }

    (void) snprintf(tmp, 1024, "%s-%d-remote", myproc.nspace, myproc.rank);
    value.type = PMIX_STRING;
    value.data.string = "1234";
    if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_GLOBAL, tmp, &value))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace,
                myproc.rank, rc);
        goto done;
    }

    value.type = PMIX_BYTE_OBJECT;
    value.data.bo.bytes = (char *) malloc(128);
    for (j = 0; j < 128; j++) {
        value.data.bo.bytes[j] = j;
    }
    value.data.bo.size = 128;
    if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_GLOBAL, "ghex", &value))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Put ghex failed: %d\n", myproc.nspace,
                myproc.rank, rc);
        PMIX_VALUE_DESTRUCT(&value);
        goto done;
    }
    PMIX_VALUE_DESTRUCT(&value);

    /* commit the data to the server */
    if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Commit failed: %d\n", myproc.nspace,
                myproc.rank, rc);
        goto done;
    }

    /* get a list of our local peers */
    if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, PMIX_LOCAL_PEERS, NULL, 0, &val))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Get local peers failed: %s\n", myproc.nspace,
                myproc.rank, PMIx_Error_string(rc));
        goto done;
    }
    /* split the returned string to get the rank of each local peer */
    peers = PMIX_ARGV_SPLIT_COMPAT(val->data.string, ',');
    PMIX_VALUE_RELEASE(val);
    nlocal = PMIX_ARGV_COUNT_COMPAT(peers);
    if (nprocs == nlocal) {
        all_local = true;
    } else {
        all_local = false;
        locals = (pmix_rank_t *) malloc(PMIX_ARGV_COUNT_COMPAT(peers) * sizeof(pmix_rank_t));
        for (n = 0; NULL != peers[n]; n++) {
            locals[n] = strtoul(peers[n], NULL, 10);
        }
    }
    PMIX_ARGV_FREE(peers);

    np = snprintf(proc.nspace, PMIX_MAX_NSLEN, "%s",  myproc.nspace);
    if (np >= PMIX_MAX_NSLEN) {
        fprintf(stderr, "Client ns %s rank %d: snprintf failed\n", myproc.nspace, myproc.rank);
        exit(EXIT_FAILURE);
    }

    PMIX_INFO_LOAD(&timeout, PMIX_TIMEOUT, &tlimit, PMIX_INT);
    /* get the committed data - ask for someone who doesn't exist as well */
    for (n = 0; n < nprocs; n++) {
        if (n == myproc.rank) {
            /* local peers doesn't include us, so check for
             * ourselves separately */
            local = true;
        } else if (all_local) {
            local = true;
        } else {
            local = false;
            /* see if this proc is local to us */
            for (k = 0; k < nlocal; k++) {
                if (n == locals[k]) {
                    local = true;
                    break;
                }
            }
        }
        proc.rank = n;
        if (local) {
            (void)snprintf(tmp, 1024, "%s-%d-local", proc.nspace, n);
            if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, &timeout, 1, &val))) {
                fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %s\n", myproc.nspace, myproc.rank,
                        tmp, PMIx_Error_string(rc));
                goto done;
            }
            if (PMIX_UINT64 != val->type) {
                fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong type: %s\n", myproc.nspace,
                        myproc.rank, tmp, PMIx_Data_type_string(val->type));
                PMIX_VALUE_RELEASE(val);
                goto done;
            }
            if (1234 != val->data.uint64) {
                fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong value: %d\n", myproc.nspace,
                        myproc.rank, tmp, (int) val->data.uint64);
                PMIX_VALUE_RELEASE(val);
                goto done;
            }
            PMIX_VALUE_RELEASE(val);
        } else {
            (void)snprintf(tmp, 1024, "%s-%d-remote", myproc.nspace, n);
            if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, tmp, &timeout, 1, &val))) {
                fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %s\n", myproc.nspace, myproc.rank,
                        tmp, PMIx_Error_string(rc));
                goto done;
            }
            if (PMIX_STRING != val->type) {
                fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong type: %s\n", myproc.nspace,
                        myproc.rank, tmp, PMIx_Data_type_string(val->type));
                PMIX_VALUE_RELEASE(val);
                goto done;
            }
            if (0 != strcmp(val->data.string, "1234")) {
                fprintf(stderr, "%s:%d: PMIx_Get Key %s failed - returned wrong value: %s\n", myproc.nspace,
                        myproc.rank, tmp, val->data.string);
                PMIX_VALUE_RELEASE(val);
                goto done;
            }
            PMIX_VALUE_RELEASE(val);
        }
        /* if this isn't us, then get the ghex key */
        if (n != myproc.rank) {
            if (PMIX_SUCCESS != (rc = PMIx_Get(&proc, "ghex", &timeout, 1, &val))) {
                fprintf(stderr, "Client ns %s rank %d: PMIx_Get ghex failed: %s\n", myproc.nspace,
                        myproc.rank, PMIx_Error_string(rc));
                goto done;
            }
            if (PMIX_BYTE_OBJECT != val->type) {
                fprintf(stderr, "%s:%d: PMIx_Get ghex failed - returned wrong type: %s\n", myproc.nspace,
                        myproc.rank, PMIx_Data_type_string(val->type));
                PMIX_VALUE_RELEASE(val);
                goto done;
            }
            if (128 != val->data.bo.size) {
                fprintf(stderr, "%s:%d: PMIx_Get ghex failed - returned wrong size: %d\n", myproc.nspace,
                        myproc.rank, (int) val->data.bo.size);
                PMIX_VALUE_RELEASE(val);
                goto done;
            }
            PMIX_VALUE_RELEASE(val);
        }
    }

done:
    /* finalize us */

    /* call fence so everyone waits before leaving */
    if (PMIX_SUCCESS != (rc = PMIx_Fence(NULL, 0, NULL, 0))) {
        fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank,
                rc);
        exit(EXIT_FAILURE);
    }

    if (PMIX_SUCCESS != (rc = PMIx_Finalize(NULL, 0))) {
        fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace,
                myproc.rank, rc);
    } else {
        if(0 == myproc.rank) {
            fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize successfully completed\n",
                    myproc.nspace, myproc.rank);
        }
    }
    fflush(stderr);
    return (EXIT_SUCCESS);
}