File: test_spawn.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 (85 lines) | stat: -rw-r--r-- 2,382 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
/*
 * Copyright (c) 2015-2020 Intel, Inc.  All rights reserved.
 * Copyright (c) 2015      Mellanox Technologies, Inc.
 *                         All rights reserved.
 * Copyright (c) 2021      Nanook Consulting.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 *
 */

#include "test_spawn.h"
#include <time.h>

typedef struct {
    int in_progress;
    pmix_nspace_t nspace;
} spawn_cbdata;

static void spawn_cb(pmix_status_t status, char nspace[], void *cbdata)
{
    spawn_cbdata *cb = (spawn_cbdata *) cbdata;

    PMIX_HIDE_UNUSED_PARAMS(status);

    PMIX_LOAD_NSPACE(cb->nspace, nspace);
    cb->in_progress = 0;
}

static int test_spawn_common(char *my_nspace, int my_rank, int blocking)
{
    int rc;
    pmix_app_t *apps;
    size_t napps;
    pmix_nspace_t nspace;

    PMIX_HIDE_UNUSED_PARAMS(my_nspace, my_rank);

    memset(nspace, 0, PMIX_MAX_NSLEN + 1);
    napps = 1;
    PMIX_APP_CREATE(apps, napps);
    apps[0].cmd = strdup("foo"); // need SOMETHING we intend to spawn!
    if (blocking) {
        if (PMIX_SUCCESS != (rc = PMIx_Spawn(NULL, 0, apps, napps, nspace))) {
            PMIX_APP_FREE(apps, napps);
            exit(rc);
        }
    } else {
        spawn_cbdata cbdata;
        cbdata.in_progress = 1;
        memset(cbdata.nspace, 0, PMIX_MAX_NSLEN + 1);
        rc = PMIx_Spawn_nb(NULL, 0, apps, napps, spawn_cb, (void *) &cbdata);
        if (PMIX_SUCCESS != rc) {
            PMIX_APP_FREE(apps, napps);
            exit(rc);
        }
        PMIX_WAIT_FOR_COMPLETION(cbdata.in_progress);
        PMIX_LOAD_NSPACE(nspace, cbdata.nspace);
    }
    PMIX_APP_FREE(apps, napps);
    if (!PMIX_CHECK_NSPACE(nspace, "foobar")) {
        exit(PMIX_ERROR);
    }
    return rc;
}

int test_spawn(char *my_nspace, int my_rank)
{
    int rc;
    rc = test_spawn_common(my_nspace, my_rank, 1);
    if (PMIX_SUCCESS != rc) {
        TEST_ERROR(("%s:%d: Spawn blocking test failed.", my_nspace, my_rank));
        exit(rc);
    }
    TEST_VERBOSE(("%s:%d: Spawn blocking test succeeded.", my_nspace, my_rank));
    rc = test_spawn_common(my_nspace, my_rank, 0);
    if (PMIX_SUCCESS != rc) {
        TEST_ERROR(("%s:%d: Spawn non-blocking test failed.", my_nspace, my_rank));
        exit(rc);
    }
    TEST_VERBOSE(("%s:%d: Spawn non-blocking test succeeded.", my_nspace, my_rank));
    return PMIX_SUCCESS;
}