@@ -41,7 +41,7 @@ static int setup_fork(orte_job_t *jdata, orte_app_context_t *app)
41
41
{
42
42
int i ;
43
43
bool takeus = false;
44
- char * pth = NULL ;
44
+ char * pth = NULL ; // Path to the directory where the Singularity binary is
45
45
char * exec_args = NULL ;
46
46
opal_envar_t envar ;
47
47
char * * cmd_args = NULL ;
@@ -56,6 +56,9 @@ static int setup_fork(orte_job_t *jdata, orte_app_context_t *app)
56
56
}
57
57
}
58
58
}
59
+ /* If we did not find the singularity binary in the environment of the
60
+ * application, we check if the arguments include the singularity
61
+ * command itself (assuming full path) or a Singularity image. */
59
62
if (!takeus ) {
60
63
/* even if they didn't specify, check to see if
61
64
* this involves a singularity container */
@@ -78,24 +81,57 @@ static int setup_fork(orte_job_t *jdata, orte_app_context_t *app)
78
81
if (NULL != app -> env ) {
79
82
pth = opal_path_findv ("singularity" , X_OK , app -> env , NULL );
80
83
}
81
- if (NULL == pth ) {
84
+ if (NULL != pth ) {
85
+ /* opal_path_findv returned the absolute path to the Singularity binary,
86
+ * we want the directory where the binary is. */
87
+ pth = opal_dirname (pth );
88
+ opal_output_verbose (1 , orte_schizo_base_framework .framework_output ,
89
+ "%s schizo:singularity: Singularity found from env: %s\n" ,
90
+ ORTE_NAME_PRINT (ORTE_PROC_MY_NAME ), pth );
91
+ } else {
82
92
/* wasn't in the environment - see if it was found somewhere */
83
93
if (0 < strlen (OPAL_SINGULARITY_PATH )) {
84
94
if (0 != strcmp (OPAL_SINGULARITY_PATH , "DEFAULT" )) {
85
95
pth = OPAL_SINGULARITY_PATH ;
96
+ opal_output_verbose (1 , orte_schizo_base_framework .framework_output ,
97
+ "%s schizo:singularity: using default Singularity from %s\n" ,
98
+ ORTE_NAME_PRINT (ORTE_PROC_MY_NAME ), pth );
99
+ /* Update (if possible) the PATH of the app so it can find singularity otherwise
100
+ it will likely not find it and create a failure. The default path to singularity
101
+ that is set at configuration time may not be in the environment that is passed in
102
+ by the user. */
103
+ for (i = 0 ; NULL != app -> env [i ]; i ++ ) {
104
+ if (0 == strncmp (app -> env [i ], "PATH" , 4 )) {
105
+ char * cur_path_val = & app -> env [i ][5 ];
106
+ if (app -> env [i ] != NULL ) {
107
+ free (app -> env [i ]);
108
+ }
109
+ opal_asprintf (& app -> env [i ], "PATH=%s:%s" , pth , cur_path_val );
110
+ break ;
111
+ }
112
+ }
86
113
}
87
114
} else {
88
115
return ORTE_ERR_TAKE_NEXT_OPTION ;
89
116
}
90
117
}
91
- if (NULL != pth ) {
92
- /* tell the odls component to prepend this to our PATH */
93
- envar .envar = "PATH" ;
94
- envar .value = pth ;
95
- envar .separator = ':' ;
96
- orte_add_attribute (& jdata -> attributes , ORTE_JOB_PREPEND_ENVAR ,
97
- ORTE_ATTR_GLOBAL , & envar , OPAL_ENVAR );
118
+ if (NULL == pth ) {
119
+ // at this point, if we do not have a valid path to Singularity, there is nothing we can do
120
+ return ORTE_ERR_TAKE_NEXT_OPTION ;
121
+ }
122
+
123
+ /* tell the odls component to prepend this to our PATH */
124
+ envar .envar = "PATH" ;
125
+ envar .value = pth ;
126
+ envar .separator = ':' ;
127
+ orte_add_attribute (& jdata -> attributes , ORTE_JOB_PREPEND_ENVAR ,
128
+ ORTE_ATTR_GLOBAL , & envar , OPAL_ENVAR );
129
+
130
+ // the final command is now singularity
131
+ if (app -> app ) {
132
+ free (app -> app );
98
133
}
134
+ asprintf (& app -> app , "%s/singularity" , pth );
99
135
100
136
/* start building the final cmd */
101
137
opal_argv_append_nosize (& cmd_args , "singularity" );
0 commit comments