Skip to content

Commit 91bd396

Browse files
authored
Merge pull request #5715 from garlick/issue#5714
pmi: prepend Flux PMI directory to LD_LIBRARY_PATH
2 parents d8e288c + 0463f94 commit 91bd396

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

src/shell/pmi/pmi.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <unistd.h>
5959
#include <stdlib.h>
6060
#include <assert.h>
61+
#include <libgen.h>
6162
#ifdef HAVE_ARGZ_ADD
6263
#include <argz.h>
6364
#else
@@ -649,6 +650,25 @@ static int shell_pmi_init (flux_plugin_t *p,
649650
return 0;
650651
}
651652

653+
/* Prepend 'path' to the environment variable 'name' which is assumed to
654+
* be a colon-separated list. If 'name' isn't already set, set it to 'path'.
655+
* Return 0 on success, -1 on failure.
656+
*/
657+
static int prepend_path_to_cmd_env (flux_cmd_t *cmd,
658+
const char *name,
659+
const char *path)
660+
{
661+
const char *searchpath = flux_cmd_getenv (cmd, name);
662+
663+
return flux_cmd_setenvf (cmd,
664+
1,
665+
name,
666+
"%s%s%s",
667+
path,
668+
searchpath ? ":" : "",
669+
searchpath ? searchpath : "");
670+
}
671+
652672
static int shell_pmi_task_init (flux_plugin_t *p,
653673
const char *topic,
654674
flux_plugin_arg_t *args,
@@ -674,12 +694,31 @@ static int shell_pmi_task_init (flux_plugin_t *p,
674694
return -1;
675695
if (flux_shell_task_channel_subscribe (task, "PMI_FD", pmi_fd_cb, pmi) < 0)
676696
return -1;
697+
const char *pmipath;
698+
if (!(pmipath = flux_conf_builtin_get ("pmi_library_path", FLUX_CONF_AUTO)))
699+
return -1;
700+
/* Flux libpmi.so and libpmi2.so are installed to a directory outside
701+
* of the default ld.so search path. Add this directory to LD_LIBRARY_PATH
702+
* so Flux jobs find Flux PMI libs before Slurm's PMI libs which are in
703+
* the system path (a tripping hazard).
704+
* N.B. The cray-pals plugin in flux-coral2 will need to undo this
705+
* so Cray MPICH finds the Cray libpmi2.so first which uses libpals.
706+
* See also flux-framework/flux-core#5714.
707+
*/
708+
char *cpy;
709+
char *pmidir;
710+
if (!(cpy = strdup (pmipath))
711+
|| !(pmidir = dirname (cpy))
712+
|| prepend_path_to_cmd_env (cmd, "LD_LIBRARY_PATH", pmidir) < 0) {
713+
free (cpy);
714+
return -1;
715+
}
716+
free (cpy);
677717
/* N.B. The pre-v5 OpenMPI flux MCA plugin dlopens the library pointed to
678718
* by FLUX_PMI_LIBRARY_PATH. Since the library only works when this shell
679719
* plugin is active, set it here.
680720
*/
681-
const char *s = flux_conf_builtin_get ("pmi_library_path", FLUX_CONF_AUTO);
682-
if (!s || flux_cmd_setenvf (cmd, 1, "FLUX_PMI_LIBRARY_PATH", "%s", s) < 0)
721+
if (flux_cmd_setenvf (cmd, 1, "FLUX_PMI_LIBRARY_PATH", "%s", pmipath) < 0)
683722
return -1;
684723
return 0;
685724
}

t/t3001-mpi-personalities.t

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ run_program() {
1616
run_timeout $timeout flux run $OPTS -n${ntasks} -N${nnodes} $*
1717
}
1818

19-
test_expect_success 'LD_LIBRARY_PATH is not being set by MPI personalties' '
20-
test_must_fail flux run --env-remove=* printenv LD_LIBRARY_PATH
21-
'
22-
2319
test_expect_success NO_ASAN "spectrum mpi only enabled with option" '
2420
LD_PRELOAD_saved=${LD_PRELOAD} &&
2521
unset LD_PRELOAD &&

t/t3002-pmi.t

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ test_expect_success 'flux run sets PMI_FD' '
2020
test_expect_success 'flux run sets FLUX_PMI_LIBRARY_PATH' '
2121
flux run printenv FLUX_PMI_LIBRARY_PATH
2222
'
23+
test_expect_success 'flux run sets LD_LIBRARY_PATH if unset' '
24+
flux run --env=-LD_LIBRARY_PATH printenv LD_LIBRARY_PATH \
25+
>libpath.out &&
26+
echo $(dirname $(flux config builtin pmi_library_path)) \
27+
>libpath.exp &&
28+
test_cmp libpath.exp libpath.out
29+
'
30+
test_expect_success 'flux run prepends to LD_LIBRARY_PATH if set' '
31+
flux run --env=LD_LIBRARY_PATH=/a printenv LD_LIBRARY_PATH \
32+
>libpath2.out &&
33+
echo $(dirname $(flux config builtin pmi_library_path)):/a \
34+
>libpath2.exp &&
35+
test_cmp libpath2.exp libpath2.out
36+
'
37+
test_expect_success 'flux run -o pmi=off does not set LD_LIBRARY_PATH' '
38+
test_must_fail flux run -o pmi=off --env=-LD_LIBRARY_PATH \
39+
printenv LD_LIBRARY_PATH
40+
'
2341
test_expect_success 'flux run -o pmi=simple sets PMI_FD' '
2442
flux run -o pmi=simple printenv PMI_FD
2543
'

0 commit comments

Comments
 (0)