File: spawn_multiple.c

package info (click to toggle)
prrte 3.0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,128 kB
  • sloc: ansic: 80,431; sh: 4,289; perl: 3,195; makefile: 1,829; lex: 352; python: 239
file content (51 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (2)
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

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

#include <pmix.h>

int main(int argc, char* argv[])
{
    pmix_proc_t myproc;
    char hostname[1024];
    pid_t pid;
    pmix_value_t *val = NULL;
    pmix_app_t apps[2];
    pmix_nspace_t nspace;
    pmix_status_t rc;

    pid = getpid();
    gethostname(hostname, 1024);

    PMIx_Init(&myproc, NULL, 0);

    rc = PMIx_Get(&myproc, PMIX_PARENT_ID, NULL, 0, &val);
    /* If we don't find it, then we're the parent */
    if (PMIX_SUCCESS != rc) {
        printf("Parent [pid %ld] about to spawn!\n", (long)pid);
        PMIX_APP_CONSTRUCT(&apps[0]);
        apps[0].cmd = strdup(argv[0]);
        PMIX_ARGV_APPEND(rc, apps[0].argv, "This is job 1");
        apps[0].maxprocs = 2;
        PMIX_APP_CONSTRUCT(&apps[1]);
        apps[1].cmd = strdup(argv[0]);
        PMIX_ARGV_APPEND(rc, apps[1].argv, "This is job 2");
        apps[1].maxprocs = 2;

        rc = PMIx_Spawn(NULL, 0, apps, 2, nspace);
        if (PMIX_SUCCESS != rc) {
            printf("Child failed to spawn\n");
            return rc;
        }
        printf("Parent done with spawn\n");
    }
    /* Otherwise, we're the child */
    else {
        printf("Hello from the child %s.%u on host %s pid %ld argv[1] = %s\n",
               myproc.nspace, myproc.rank, hostname, (long)pid, argv[1]);
    }

    PMIx_Finalize(NULL, 0);
    return 0;
}