root/mpich2/trunk/src/pm/hydra/bootstrap/slurm/slurm_launch.c @ 4887

Revision 4887, 2.8 KB (checked in by balaji, 5 months ago)

Warning stomp.

Line 
1/* -*- Mode: C; c-basic-offset:4 ; -*- */
2/*
3 *  (C) 2008 by Argonne National Laboratory.
4 *      See COPYRIGHT in top-level directory.
5 */
6
7#include "hydra_utils.h"
8#include "bsci.h"
9#include "bscu.h"
10#include "slurm.h"
11
12HYD_Status HYD_BSCD_slurm_launch_procs(char **global_args, const char *partition_id_str,
13                                       struct HYD_Partition *partition_list)
14{
15    struct HYD_Partition *partition;
16    char *client_arg[HYD_NUM_TMP_STRINGS];
17    char *tmp[HYD_NUM_TMP_STRINGS], *path = NULL, *test_path = NULL;
18    int i, arg, num_nodes;
19    HYD_Status status = HYD_SUCCESS;
20
21    HYDU_FUNC_ENTER();
22
23    /*
24     * We use the following priority order for the executable path:
25     *    1. User-specified
26     *    2. Search in path
27     *    3. Hard-coded location
28     */
29    if (HYD_BSCI_info.bootstrap_exec) {
30        path = HYDU_strdup(HYD_BSCI_info.bootstrap_exec);
31    }
32    else {
33        status = HYDU_find_in_path("srun", &test_path);
34        HYDU_ERR_POP(status, "error while searching for executable in user path\n");
35
36        if (test_path) {
37            tmp[0] = HYDU_strdup(test_path);
38            tmp[1] = HYDU_strdup("srun");
39            tmp[2] = NULL;
40
41            status = HYDU_str_alloc_and_join(tmp, &path);
42            HYDU_ERR_POP(status, "error joining strings\n");
43
44            HYDU_free_strlist(tmp);
45        }
46        else
47            path = HYDU_strdup("/usr/bin/srun");
48    }
49
50    arg = 0;
51    client_arg[arg++] = HYDU_strdup(path);
52    client_arg[arg++] = HYDU_strdup("--nodelist");
53
54    i = 0;
55    num_nodes = 0;
56    FORALL_ACTIVE_PARTITIONS(partition, partition_list) {
57        tmp[i++] = HYDU_strdup(partition->base->name);
58        if (partition->next && partition->next->base->active)
59            tmp[i++] = HYDU_strdup(",");
60        num_nodes++;
61    }
62    tmp[i++] = NULL;
63    status = HYDU_str_alloc_and_join(tmp, &client_arg[arg]);
64    HYDU_ERR_POP(status, "error joining strings\n");
65
66    HYDU_free_strlist(tmp);
67
68    arg++;
69
70    client_arg[arg++] = HYDU_strdup("-N");
71    client_arg[arg++] = HYDU_int_to_str(num_nodes);
72
73    for (i = 0; global_args[i]; i++)
74        client_arg[arg++] = HYDU_strdup(global_args[i]);
75
76    client_arg[arg++] = NULL;
77
78    if (HYD_BSCI_info.debug) {
79        HYDU_Dump("Launching process: ");
80        HYDU_print_strlist(client_arg);
81    }
82
83    status = HYDU_create_process(client_arg, NULL,
84                                 &partition_list->base->in,
85                                 &partition_list->base->out,
86                                 &partition_list->base->err,
87                                 &partition_list->base->pid, -1);
88    HYDU_ERR_POP(status, "bootstrap spawn process returned error\n");
89
90    HYDU_free_strlist(client_arg);
91
92  fn_exit:
93    HYDU_FUNC_EXIT();
94    return status;
95
96  fn_fail:
97    goto fn_exit;
98}
Note: See TracBrowser for help on using the browser.