Skip to content

Commit 2521257

Browse files
author
rhc54
committed
Merge pull request #2 from rhc54/v1.8
CMR4926
2 parents ecf9846 + 520b3e3 commit 2521257

File tree

1 file changed

+69
-33
lines changed

1 file changed

+69
-33
lines changed

orte/tools/orterun/orterun.c

+69-33
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ static int create_app(int argc, char* argv[],
561561
static int init_globals(void);
562562
static int parse_globals(int argc, char* argv[], opal_cmd_line_t *cmd_line);
563563
static int parse_locals(orte_job_t *jdata, int argc, char* argv[]);
564+
static void set_classpath_jar_file(orte_app_context_t *app, int index, char *jarfile);
564565
static int parse_appfile(orte_job_t *jdata, char *filename, char ***env);
565566
static void run_debugger(char *basename, opal_cmd_line_t *cmd_line,
566567
int argc, char *argv[], int num_procs) __opal_attribute_noreturn__;
@@ -2015,57 +2016,80 @@ static int create_app(int argc, char* argv[],
20152016
NULL != strstr(app->argv[i], "classpath")) {
20162017
/* yep - but does it include the path to the mpi libs? */
20172018
found = true;
2018-
if (NULL == strstr(app->argv[i+1], "mpi.jar")) {
2019-
/* nope - need to add it */
2020-
if (':' == app->argv[i+1][strlen(app->argv[i+1]-1)]) {
2021-
asprintf(&value, "%s%s/mpi.jar", app->argv[i+1], opal_install_dirs.libdir);
2022-
} else {
2023-
asprintf(&value, "%s:%s/mpi.jar", app->argv[i+1], opal_install_dirs.libdir);
2024-
}
2025-
free(app->argv[i+1]);
2026-
app->argv[i+1] = value;
2019+
/* check if mpi.jar exists - if so, add it */
2020+
value = opal_os_path(false, opal_install_dirs.libdir, "mpi.jar", NULL);
2021+
if (access(value, F_OK ) != -1) {
2022+
set_classpath_jar_file(app, i+1, "mpi.jar");
2023+
}
2024+
free(value);
2025+
/* check for oshmem support */
2026+
value = opal_os_path(false, opal_install_dirs.libdir, "shmem.jar", NULL);
2027+
if (access(value, F_OK ) != -1) {
2028+
set_classpath_jar_file(app, i+1, "shmem.jar");
20272029
}
2030+
free(value);
2031+
/* always add the local directory */
2032+
asprintf(&value, "%s:%s", app->cwd, app->argv[i+1]);
2033+
free(app->argv[i+1]);
2034+
app->argv[i+1] = value;
20282035
break;
20292036
}
20302037
}
20312038
if (!found) {
20322039
/* check to see if CLASSPATH is in the environment */
2040+
found = false; // just to be pedantic
20332041
for (i=0; NULL != environ[i]; i++) {
20342042
if (0 == strncmp(environ[i], "CLASSPATH", strlen("CLASSPATH"))) {
2035-
/* check if mpi.jar is present */
2036-
if (NULL != strstr(environ[i], "mpi.jar")) {
2037-
/* yes - just add the envar to the argv in the
2038-
* right format
2039-
*/
2040-
value = strchr(environ[i], '=');
2041-
++value; /* step over the = */
2042-
opal_argv_insert_element(&app->argv, 1, value);
2043-
opal_argv_insert_element(&app->argv, 1, "-cp");
2044-
} else {
2045-
/* need to add it */
2046-
value = strchr(environ[i], '=');
2047-
++value; /* step over the = */
2048-
if (':' == value[strlen(value-1)]) {
2049-
asprintf(&param, "%s%s/mpi.jar", value, opal_install_dirs.libdir);
2050-
} else {
2051-
asprintf(&param, "%s:%s/mpi.jar", value, opal_install_dirs.libdir);
2052-
}
2053-
opal_argv_insert_element(&app->argv, 1, param);
2054-
opal_argv_insert_element(&app->argv, 1, "-cp");
2055-
free(param);
2043+
value = strchr(environ[i], '=');
2044+
++value; /* step over the = */
2045+
opal_argv_insert_element(&app->argv, 1, value);
2046+
/* check for mpi.jar */
2047+
value = opal_os_path(false, opal_install_dirs.libdir, "mpi.jar", NULL);
2048+
if (access(value, F_OK ) != -1) {
2049+
set_classpath_jar_file(app, 1, "mpi.jar");
2050+
}
2051+
free(value);
2052+
/* check for shmem.jar */
2053+
value = opal_os_path(false, opal_install_dirs.libdir, "shmem.jar", NULL);
2054+
if (access(value, F_OK ) != -1) {
2055+
set_classpath_jar_file(app, 1, "shmem.jar");
20562056
}
2057+
free(value);
2058+
/* always add the local directory */
2059+
(void)asprintf(&value, "%s:%s", app->cwd, app->argv[1]);
2060+
free(app->argv[1]);
2061+
app->argv[1] = value;
2062+
opal_argv_insert_element(&app->argv, 1, "-cp");
20572063
found = true;
20582064
break;
20592065
}
20602066
}
20612067
if (!found) {
20622068
/* need to add it right after the java command - have
2063-
* to include the current directory and trust that
2069+
* to include the working directory and trust that
20642070
* the user set cwd if necessary
20652071
*/
2066-
asprintf(&value, ".:%s/mpi.jar", opal_install_dirs.libdir);
2067-
opal_argv_insert_element(&app->argv, 1, value);
2072+
char *str, *str2;
2073+
/* always start with the working directory */
2074+
str = strdup(app->cwd);
2075+
/* check for mpi.jar */
2076+
value = opal_os_path(false, opal_install_dirs.libdir, "mpi.jar", NULL);
2077+
if (access(value, F_OK ) != -1) {
2078+
(void)asprintf(&str2, "%s:%s", str, value);
2079+
free(str);
2080+
str = str2;
2081+
}
2082+
free(value);
2083+
/* check for shmem.jar */
2084+
value = opal_os_path(false, opal_install_dirs.libdir, "shmem.jar", NULL);
2085+
if (access(value, F_OK ) != -1) {
2086+
asprintf(&str2, "%s:%s", str, value);
2087+
free(str);
2088+
str = str2;
2089+
}
20682090
free(value);
2091+
opal_argv_insert_element(&app->argv, 1, str);
2092+
free(str);
20692093
opal_argv_insert_element(&app->argv, 1, "-cp");
20702094
}
20712095
}
@@ -2116,6 +2140,18 @@ static int create_app(int argc, char* argv[],
21162140
return rc;
21172141
}
21182142

2143+
static void set_classpath_jar_file(orte_app_context_t *app, int index, char *jarfile)
2144+
{
2145+
if (NULL == strstr(app->argv[index], jarfile)) {
2146+
/* nope - need to add it */
2147+
char *fmt = ':' == app->argv[index][strlen(app->argv[index]-1)]
2148+
? "%s%s/%s" : "%s:%s/%s";
2149+
char *str;
2150+
asprintf(&str, fmt, app->argv[index], opal_install_dirs.libdir, jarfile);
2151+
free(app->argv[index]);
2152+
app->argv[index] = str;
2153+
}
2154+
}
21192155

21202156
static int parse_appfile(orte_job_t *jdata, char *filename, char ***env)
21212157
{

0 commit comments

Comments
 (0)