Skip to content

Commit 36a6a3b

Browse files
author
rhc54
committed
Merge pull request #1430 from rhc54/topic/sing
Update singularity support
2 parents f55a06d + 4d0cc27 commit 36a6a3b

File tree

11 files changed

+155
-65
lines changed

11 files changed

+155
-65
lines changed

opal/mca/shmem/mmap/shmem_mmap_component.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,6 @@ mmap_open(void)
176176
static int
177177
mmap_query(mca_base_module_t **module, int *priority)
178178
{
179-
/* if we are in a container, then we must disqualify ourselves */
180-
if (NULL != getenv("OPAL_PROC_CONTAINER")) {
181-
*priority = 0;
182-
*module = NULL;
183-
return OPAL_ERROR;
184-
}
185-
186179
*priority = mca_shmem_mmap_component.priority;
187180
*module = (mca_base_module_t *)&opal_shmem_mmap_module.super;
188181
return OPAL_SUCCESS;

opal/mca/shmem/posix/shmem_posix_component.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,6 @@ posix_runtime_query(mca_base_module_t **module,
201201
static int
202202
posix_query(mca_base_module_t **module, int *priority)
203203
{
204-
/* if we are in a container, then we must disqualify ourselves */
205-
if (NULL != getenv("OPAL_PROC_CONTAINER")) {
206-
*priority = 0;
207-
*module = NULL;
208-
return OPAL_ERROR;
209-
}
210-
211204
*priority = mca_shmem_posix_component.priority;
212205
*module = (mca_base_module_t *)&opal_shmem_posix_module.super;
213206
return OPAL_SUCCESS;

opal/mca/shmem/sysv/shmem_sysv_component.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,6 @@ sysv_runtime_query(mca_base_module_t **module, int *priority, const char *hint)
210210
static int
211211
sysv_query(mca_base_module_t **module, int *priority)
212212
{
213-
/* if we are in a container, then we must disqualify ourselves */
214-
if (NULL != getenv("OPAL_PROC_CONTAINER")) {
215-
*priority = 0;
216-
*module = NULL;
217-
return OPAL_ERROR;
218-
}
219-
220213
*priority = mca_shmem_sysv_component.priority;
221214
*module = (mca_base_module_t *)&opal_shmem_sysv_module.super;
222215
return OPAL_SUCCESS;

orte/mca/schizo/alps/schizo_alps.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
#include "schizo_alps.h"
3030

3131
static orte_schizo_launch_environ_t check_launch_environment(void);
32+
static void finalize(void);
3233

3334
orte_schizo_base_module_t orte_schizo_alps_module = {
34-
.check_launch_environment = check_launch_environment
35+
.check_launch_environment = check_launch_environment,
36+
.finalize = finalize
3537
};
3638

3739
static char **pushed_envs = NULL;

orte/mca/schizo/base/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ ORTE_DECLSPEC int orte_schizo_base_parse_env(char **personality,
6868
opal_cmd_line_t *cmd_line,
6969
char **srcenv,
7070
char ***dstenv);
71+
ORTE_DECLSPEC int orte_schizo_base_setup_app(char **personality,
72+
orte_app_context_t *app);
7173
ORTE_DECLSPEC int orte_schizo_base_setup_fork(orte_job_t *jdata,
7274
orte_app_context_t *context);
7375
ORTE_DECLSPEC int orte_schizo_base_setup_child(orte_job_t *jobdat,

orte/mca/schizo/base/schizo_base_frame.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ orte_schizo_base_t orte_schizo_base = {{{0}}};
3939
orte_schizo_base_module_t orte_schizo = {
4040
.parse_cli = orte_schizo_base_parse_cli,
4141
.parse_env = orte_schizo_base_parse_env,
42+
.setup_app = orte_schizo_base_setup_app,
4243
.setup_fork = orte_schizo_base_setup_fork,
4344
.setup_child = orte_schizo_base_setup_child,
4445
.check_launch_environment = orte_schizo_base_check_launch_environment,

orte/mca/schizo/base/schizo_base_stubs.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "orte/util/name_fns.h"
2020
#include "orte/mca/schizo/base/base.h"
2121

22-
const char* orte_schizo_base_print_env(orte_schizo_launch_environ_t env)
23-
{
22+
const char* orte_schizo_base_print_env(orte_schizo_launch_environ_t env)
23+
{
2424
switch(env) {
2525
case ORTE_SCHIZO_UNDETERMINED:
2626
return "UNDETERMINED";
@@ -80,6 +80,24 @@ int orte_schizo_base_parse_env(char **personality,
8080
return ORTE_SUCCESS;
8181
}
8282

83+
int orte_schizo_base_setup_app(char **personality,
84+
orte_app_context_t *app)
85+
{
86+
int rc;
87+
orte_schizo_base_active_module_t *mod;
88+
89+
OPAL_LIST_FOREACH(mod, &orte_schizo_base.active_modules, orte_schizo_base_active_module_t) {
90+
if (NULL != mod->module->setup_app) {
91+
rc = mod->module->setup_app(personality, app);
92+
if (ORTE_SUCCESS != rc && ORTE_ERR_TAKE_NEXT_OPTION != rc) {
93+
ORTE_ERROR_LOG(rc);
94+
return rc;
95+
}
96+
}
97+
}
98+
return ORTE_SUCCESS;
99+
}
100+
83101
int orte_schizo_base_setup_fork(orte_job_t *jdata,
84102
orte_app_context_t *context)
85103
{

orte/mca/schizo/schizo.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,44 @@ BEGIN_C_DECLS
4040
* the base stub functions
4141
*/
4242

43+
/* initialize the module - allow it to do whatever one-time
44+
* things it requires */
4345
typedef int (*orte_schizo_base_module_init_fn_t)(void);
4446

47+
/* given an argv-array of personalities, parse a tool command line
48+
* starting from the given location according to the cmd line options
49+
* known to this module's personality. First, of course, check that
50+
* this module is included in the specified array of personalities!
51+
* Only one command-line parser is allowed to operate - i.e., if */
4552
typedef int (*orte_schizo_base_module_parse_cli_fn_t)(char **personality,
4653
int argc, int start,
4754
char **argv);
4855

56+
/* given an argv-array of personalities, parse the environment of the
57+
* tool to extract any personality-specific envars that need to be
58+
* forward to the app's environment upon execution */
4959
typedef int (*orte_schizo_base_module_parse_env_fn_t)(char **personality,
5060
char *path,
5161
opal_cmd_line_t *cmd_line,
5262
char **srcenv,
5363
char ***dstenv);
5464

65+
/* given an argv-array of personalities, do whatever preparation work
66+
* is required to setup the app for execution. This is intended to be
67+
* used by orterun and other launcher tools to, for example, change
68+
* an executable's relative-path to an absolute-path, or add a command
69+
* required for starting a particular kind of application (e.g., adding
70+
* "java" to start a Java application) */
71+
typedef int (*orte_schizo_base_module_setup_app_fn_t)(char **personality,
72+
orte_app_context_t *app);
73+
74+
/* add any personality-specific envars required at the job level prior
75+
* to beginning to execute local procs */
5576
typedef int (*orte_schizo_base_module_setup_fork_fn_t)(orte_job_t *jdata,
5677
orte_app_context_t *context);
5778

79+
/* add any personality-specific envars required for this specific local
80+
* proc upon execution */
5881
typedef int (*orte_schizo_base_module_setup_child_fn_t)(orte_job_t *jdata,
5982
orte_proc_t *child,
6083
orte_app_context_t *app);
@@ -86,6 +109,7 @@ typedef struct {
86109
orte_schizo_base_module_init_fn_t init;
87110
orte_schizo_base_module_parse_cli_fn_t parse_cli;
88111
orte_schizo_base_module_parse_env_fn_t parse_env;
112+
orte_schizo_base_module_setup_app_fn_t setup_app;
89113
orte_schizo_base_module_setup_fork_fn_t setup_fork;
90114
orte_schizo_base_module_setup_child_fn_t setup_child;
91115
orte_schizo_base_module_ck_launch_environ_fn_t check_launch_environment;

orte/mca/schizo/singularity/schizo_singularity.c

Lines changed: 91 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,36 @@
2020
#include "opal/util/argv.h"
2121
#include "opal/util/basename.h"
2222
#include "opal/util/opal_environ.h"
23+
#include "opal/util/os_dirpath.h"
24+
#include "opal/util/path.h"
2325

2426
#include "orte/runtime/orte_globals.h"
2527
#include "orte/util/name_fns.h"
2628
#include "orte/mca/schizo/base/base.h"
2729

2830
#include "schizo_singularity.h"
2931

32+
static int setup_app(char **personality,
33+
orte_app_context_t *context);
3034
static int setup_fork(orte_job_t *jdata,
3135
orte_app_context_t *context);
3236

3337
orte_schizo_base_module_t orte_schizo_singularity_module = {
38+
.setup_app = setup_app,
3439
.setup_fork = setup_fork
3540
};
3641

37-
static int setup_fork(orte_job_t *jdata,
38-
orte_app_context_t *app)
42+
static int setup_app(char **personality,
43+
orte_app_context_t *app)
3944
{
4045
int i;
41-
char *newenv;
46+
char *newenv, *pth;
4247
bool takeus = false;
43-
char *cmd, *tmp = NULL, *p, *t2;
48+
char *p, *t2;
4449

4550
/* see if we are included */
46-
for (i=0; NULL != jdata->personality[i]; i++) {
47-
if (0 == strcmp(jdata->personality[i], "singularity")) {
51+
for (i=0; NULL != personality[i]; i++) {
52+
if (0 == strcmp(personality[i], "singularity")) {
4853
takeus = true;
4954
break;
5055
}
@@ -64,55 +69,104 @@ static int setup_fork(orte_job_t *jdata,
6469
"%s schizo:singularity: checking app %s",
6570
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), app->argv[0]);
6671

72+
if (0 < strlen(OPAL_SINGULARITY_PATH)) {
73+
asprintf(&pth, "%s/singularity", OPAL_SINGULARITY_PATH);
74+
} else {
75+
/* since we allow for detecting singularity's presence, it
76+
* is possible that we found it in the PATH, but not in a
77+
* standard location. Check for that here */
78+
pth = opal_path_findv("singularity", X_OK, app->env, NULL);
79+
if (NULL == pth) {
80+
/* cannot execute */
81+
return ORTE_ERR_TAKE_NEXT_OPTION;
82+
}
83+
}
6784
/* find the path and prepend it with the path to Singularity */
6885
for (i = 0; NULL != app->env && NULL != app->env[i]; ++i) {
6986
/* add to PATH */
7087
if (0 == strncmp("PATH=", app->env[i], 5)) {
71-
asprintf(&newenv, "%s:%s", OPAL_SINGULARITY_PATH, app->env[i] + 5);
88+
t2 = opal_dirname(pth);
89+
asprintf(&newenv, "%s:%s", t2, app->env[i] + 5);
7290
opal_setenv("PATH", newenv, true, &app->env);
7391
free(newenv);
92+
free(t2);
7493
break;
7594
}
7695
}
7796

78-
/* flag that the app is in a container */
79-
opal_setenv("OPAL_PROC_CONTAINER", "1", true, &app->env);
80-
8197
/* ensure that we use "singularity run" to execute this app */
8298
if (0 != strcmp(app->app, "singularity")) {
8399
opal_output_verbose(1, orte_schizo_base_framework.framework_output,
84-
"%s schizo:singularity: adding singularity cmds at %s",
85-
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), OPAL_SINGULARITY_PATH);
100+
"%s schizo:singularity: adding singularity cmd %s",
101+
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), pth);
86102
/* change the app to the "singularity" command */
87103
free(app->app);
88-
if (0 < strlen(OPAL_SINGULARITY_PATH)) {
89-
asprintf(&app->app, "%s/singularity", OPAL_SINGULARITY_PATH);
90-
} else {
91-
app->app = strdup("singularity");
92-
}
93-
/* if the app contains .sapp, then we need to strip that
94-
* extension so singularity doesn't bark at us */
95-
if (NULL != (p = strstr(app->argv[0], ".sapp"))) {
96-
tmp = strdup(app->argv[0]);
97-
t2 = opal_basename(app->argv[0]);
98-
p = strstr(t2, ".sapp");
99-
*p = '\0'; // strip the extension
100-
free(app->argv[0]);
101-
app->argv[0] = t2;
104+
app->app = pth;
105+
} else {
106+
free(pth);
107+
}
108+
109+
/* if the app contains .sapp, then we need to strip that
110+
* extension so singularity doesn't bark at us */
111+
if (NULL != (p = strstr(app->argv[0], ".sapp"))) {
112+
t2 = opal_basename(app->argv[0]);
113+
p = strstr(t2, ".sapp");
114+
*p = '\0'; // strip the extension
115+
free(app->argv[0]);
116+
app->argv[0] = t2;
117+
}
118+
opal_argv_prepend_nosize(&app->argv, "run");
119+
opal_argv_prepend_nosize(&app->argv, "singularity");
120+
121+
/* export an envar to permit shared memory operations */
122+
opal_setenv("SINGULARITY_NO_NAMESPACE_PID", "1", true, &app->env);
123+
124+
return ORTE_SUCCESS;
125+
}
126+
127+
static int setup_fork(orte_job_t *jdata,
128+
orte_app_context_t *app)
129+
{
130+
int i;
131+
bool takeus = false;
132+
char *p;
133+
char dir[MAXPATHLEN];
134+
135+
/* see if we are included */
136+
for (i=0; NULL != jdata->personality[i]; i++) {
137+
if (0 == strcmp(jdata->personality[i], "singularity")) {
138+
takeus = true;
139+
break;
102140
}
103-
opal_argv_prepend_nosize(&app->argv, "run");
104-
opal_argv_prepend_nosize(&app->argv, "singularity");
105141
}
106-
/* ensure this application has been "installed" */
107-
if (NULL != tmp) {
108-
opal_output_verbose(1, orte_schizo_base_framework.framework_output,
109-
"%s schizo:singularity: installing container %s",
110-
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), tmp);
111-
(void)asprintf(&cmd, "singularity install %s >> /dev/null", tmp);
112-
system(cmd);
113-
free(cmd);
114-
free(tmp);
142+
if (!takeus) {
143+
/* even if they didn't specify, check to see if
144+
* this involves a singularity container */
145+
if (0 != strcmp(app->argv[0],"singularity") &&
146+
0 != strcmp(app->argv[0],"sapprun") &&
147+
NULL == strstr(app->argv[0], ".sapp")) {
148+
/* guess not! */
149+
return ORTE_ERR_TAKE_NEXT_OPTION;
150+
}
115151
}
116152

153+
/* save our current directory */
154+
getcwd(dir, sizeof(dir));
155+
156+
/* change to the working directory for this context */
157+
chdir(app->cwd);
158+
159+
/* ensure the app is installed */
160+
opal_output_verbose(1, orte_schizo_base_framework.framework_output,
161+
"%s schizo:singularity: installing app %s",
162+
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), app->argv[2]);
163+
(void)asprintf(&p, "%s install %s.sapp &> /dev/null", app->app, app->argv[2]);
164+
system(p);
165+
free(p);
166+
167+
/* return to the original directory */
168+
chdir(dir);
169+
117170
return ORTE_SUCCESS;
118171
}
172+

orte/tools/orterun/orterun.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,9 @@ static int parse_locals(orte_job_t *jdata, int argc, char* argv[])
12581258
++app_num;
12591259
opal_pointer_array_add(jdata->apps, app);
12601260
++jdata->num_apps;
1261+
if (ORTE_SUCCESS != (rc = orte_schizo.setup_app(jdata->personality, app))) {
1262+
return rc;
1263+
}
12611264
}
12621265

12631266
/* Reset the temps */
@@ -1284,6 +1287,9 @@ static int parse_locals(orte_job_t *jdata, int argc, char* argv[])
12841287
++app_num;
12851288
opal_pointer_array_add(jdata->apps, app);
12861289
++jdata->num_apps;
1290+
if (ORTE_SUCCESS != (rc = orte_schizo.setup_app(jdata->personality, app))) {
1291+
return rc;
1292+
}
12871293
}
12881294
}
12891295
if (NULL != env) {
@@ -1670,6 +1676,8 @@ static int create_app(int argc, char* argv[],
16701676
rc = ORTE_ERR_NOT_FOUND;
16711677
goto cleanup;
16721678
}
1679+
free(app->argv[0]);
1680+
app->argv[0] = opal_basename(app->app);
16731681

16741682
/* if this is a Java application, we have a bit more work to do. Such
16751683
* applications actually need to be run under the Java virtual machine

0 commit comments

Comments
 (0)