File: orte_spawn.c

package info (click to toggle)
openmpi 4.1.0-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 126,560 kB
  • sloc: ansic: 685,465; makefile: 42,952; f90: 19,220; sh: 7,002; java: 6,360; perl: 3,524; cpp: 2,227; python: 1,350; lex: 989; fortran: 61; tcl: 12
file content (91 lines) | stat: -rw-r--r-- 2,428 bytes parent folder | download | duplicates (4)
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
/* -*- C -*-
 *
 * $HEADER$
 *
 * The most basic of MPI applications
 */

#include <stdio.h>

#include "opal/util/argv.h"

#include "orte/util/proc_info.h"
#include "orte/mca/plm/plm.h"
#include "orte/mca/rml/rml.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/runtime/runtime.h"
#include "orte/runtime/orte_globals.h"
#include "orte/util/name_fns.h"

#define MY_TAG 12345

int main(int argc, char* argv[])
{
    int rc;
    orte_job_t *jdata;
    orte_app_context_t *app;
    char cwd[1024];
    orte_process_name_t name;
    struct iovec msg;
    orte_vpid_t i;


    if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
        fprintf(stderr, "couldn't init orte - error code %d\n", rc);
        return rc;
    }

    /* setup the job object */
    jdata = OBJ_NEW(orte_job_t);
    orte_set_attribute(&jdata->attributes, ORTE_JOB_NON_ORTE_JOB, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);

    /* create an app_context that defines the app to be run */
    app = OBJ_NEW(orte_app_context_t);
    app->app = strdup("hostname");
    opal_argv_append_nosize(&app->argv, "hostname");
    app->num_procs = 3;

    getcwd(cwd, sizeof(cwd));
    app->cwd = strdup(cwd);
    /*===================================*/
    char *host_list = "vm,vm3,vm4";
    orte_set_attribute(&app->attributes, ORTE_APP_DASH_HOST, ORTE_ATTR_GLOBAL, host_list, OPAL_STRING);
    /*==================================*/

    /* add the app to the job data */
    opal_pointer_array_add(jdata->apps, app);
    jdata->num_apps = 1;
#if 0
    /* setup a map object */
    jdata->map = OBJ_NEW(orte_job_map_t);
    jdata->map->display_map = true;
#endif
    /* launch the job */
    fprintf(stderr, "Parent: spawning children!\n");
    if (ORTE_SUCCESS != (rc = orte_plm.spawn(jdata))) {
        ORTE_ERROR_LOG(rc);
        orte_finalize();
        return 1;
    }
    fprintf(stderr, "Parent: children spawned!\n");

#if 0
    /* send messages to all children - this will verify that we know their contact info */
    name.jobid = jdata->jobid;
    i = 1;
    msg.iov_base = (void *) &i;
    msg.iov_len  = sizeof(i);
    for (i=0; i < app->num_procs; i++) {
        name.vpid = i;

        fprintf(stderr, "Parent: sending message to child %s\n", ORTE_NAME_PRINT(&name));
        if (0 > (rc = orte_rml.send(&name, &msg, 1, MY_TAG, 0))) {
            ORTE_ERROR_LOG(rc);
        }
    }
#endif

    /* All done */
    orte_finalize();
    return 0;
}