File: test_replace.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 (140 lines) | stat: -rw-r--r-- 4,059 bytes parent folder | download | duplicates (7)
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
/*
 * Copyright (c) 2017      Mellanox Technologies, Inc.
 *                         All rights reserved.
 * Copyright (c) 2019      Intel, Inc.  All rights reserved.
 * Copyright (c) 2021-2022 Nanook Consulting  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 *
 */

#include "test_replace.h"

static void release_cb(pmix_status_t status, void *cbdata)
{
    int *ptr = (int *) cbdata;

    PMIX_HIDE_UNUSED_PARAMS(status);

    *ptr = 0;
}

static void get_cb(pmix_status_t status, pmix_value_t *kv, void *cbdata)
{
    get_cbdata *cb = (get_cbdata *) cbdata;
    if (PMIX_SUCCESS == status) {
        PMIx_Value_xfer(cb->kv, kv);
    }
    cb->in_progress = 0;
    cb->status = status;
}

static int key_is_replace(int key_idx)
{
    key_replace_t *item;

    PMIX_LIST_FOREACH (item, &key_replace, key_replace_t) {
        if (item->key_idx == key_idx)
            return 1;
    }
    return 0;
}

int test_replace(char *my_nspace, pmix_rank_t my_rank, test_params params)
{
    int key_idx = 0;
    int key_cnt = 0;
    char sval[PMIX_MAX_NSLEN];
    pmix_proc_t proc;
    pmix_status_t rc;
    key_replace_t *item;

    PMIX_CONSTRUCT(&key_replace, pmix_list_t);
    parse_replace(params.key_replace, 1, &key_cnt);

    for (key_idx = 0; key_idx < key_cnt; key_idx++) {
        memset(sval, 0, PMIX_MAX_NSLEN);
        sprintf(sval, "test_replace:%s:%d:%d", my_nspace, my_rank, key_idx);

        PUT(string, sval, PMIX_GLOBAL, 0, key_idx, 1);
        if (PMIX_SUCCESS != rc) {
            TEST_ERROR(("%s:%d: PMIx_Put failed: %d", my_nspace, my_rank, rc));
            PMIX_LIST_DESTRUCT(&key_replace);
            exit(rc);
        }
    }

    PMIX_PROC_CONSTRUCT(&proc);
    pmix_strncpy(proc.nspace, my_nspace, PMIX_MAX_NSLEN);
    proc.rank = PMIX_RANK_WILDCARD;

    /* Submit the data */
    if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
        TEST_ERROR(("%s:%d: PMIx_Commit failed: %d", my_nspace, my_rank, rc));
        PMIX_LIST_DESTRUCT(&key_replace);
        PMIX_PROC_DESTRUCT(&proc);
        exit(rc);
    }

    FENCE(1, 1, (&proc), 1);
    if (PMIX_SUCCESS != rc) {
        TEST_ERROR(("%s:%d: PMIx_Fence failed: %d", my_nspace, my_rank, rc));
        PMIX_LIST_DESTRUCT(&key_replace);
        PMIX_PROC_DESTRUCT(&proc);
        exit(rc);
    }

    PMIX_LIST_FOREACH (item, &key_replace, key_replace_t) {
        memset(sval, 0, PMIX_MAX_NSLEN);
        sprintf(sval, "test_replace:%s:%d:%d: replaced key", my_nspace, my_rank, item->key_idx);

        PUT(string, sval, PMIX_GLOBAL, 0, item->key_idx, 1);
        if (PMIX_SUCCESS != rc) {
            TEST_ERROR(("%s:%d: PMIx_Put failed: %d", my_nspace, my_rank, rc));
            PMIX_LIST_DESTRUCT(&key_replace);
            PMIX_PROC_DESTRUCT(&proc);
            exit(rc);
        }
    }

    /* Submit the data */
    if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
        TEST_ERROR(("%s:%d: PMIx_Commit failed: %d", my_nspace, my_rank, rc));
        PMIX_LIST_DESTRUCT(&key_replace);
        PMIX_PROC_DESTRUCT(&proc);
        exit(rc);
    }

    FENCE(1, 1, (&proc), 1);
    if (PMIX_SUCCESS != rc) {
        TEST_ERROR(("%s:%d: PMIx_Fence failed: %d", my_nspace, my_rank, rc));
        PMIX_LIST_DESTRUCT(&key_replace);
        PMIX_PROC_DESTRUCT(&proc);
        exit(rc);
    }

    for (key_idx = 0; key_idx < key_cnt; key_idx++) {
        memset(sval, 0, PMIX_MAX_NSLEN);

        if (key_is_replace(key_idx)) {
            sprintf(sval, "test_replace:%s:%d:%d: replaced key", my_nspace, my_rank, key_idx);
        } else {
            sprintf(sval, "test_replace:%s:%d:%d", my_nspace, my_rank, key_idx);
        }

        GET(string, sval, my_nspace, my_rank, 0, key_idx, 1, 1, 0);
        if (PMIX_SUCCESS != rc) {
            TEST_ERROR(("%s:%d: PMIx_Get of remote key on local proc", my_nspace, my_rank));
            PMIX_LIST_DESTRUCT(&key_replace);
            PMIX_PROC_DESTRUCT(&proc);
            exit(rc);
        }
    }

    PMIX_LIST_DESTRUCT(&key_replace);
    PMIX_PROC_DESTRUCT(&proc);
    return PMIX_SUCCESS;
}