I recently installed Open MPI, and it's complaining

PMIx has detected a temporary directory name that results
in a path that is too long for the Unix domain socket:
Temp dir: /var/folders/**/*****************************/T/openmpi-sessions-501@host*******************************/*****

This question suggests setting TMPDIR to /tmp. Is that safe? Will it mess up other programs?

1 Answer 1


There can be security flaws that result from the careless use of /tmp; malicious local users may be able to delete arbitrary files or possibly even run arbitrary code under your user account, depending on how bad the /tmp flaw is. A solution that remains within the char sun_path[104] limit on unix domain sockets (see /usr/include/sys/un.h for the definition) is to create a temporary directory and use that for MPI:

$ mktemp -d /tmp/mpi-XXXXXXXX

which leaves 86 characters for the socket file to use (104 minus one for the trailing NUL minus 17).

Depending on where and when you set TMPDIR other programs could easily be messed up, notably tmux or screen that then may not then be able to locate their control socket. If possible, scope the custom TMPDIR setting as close to the MPI calls as possible, e.g. with a shell function or alias along the lines of

alias mpi4py='TMPDIR=$(mktemp -d /tmp/mpi-XXXXXXXX) mpi4py'

This would create a unique temporary directory for each invocation; the directories in /tmp are pruned automatically. If a shared or more persistent directory is needed /var/tmp is typically more suitable

$ mkdir /var/tmp/mympi

and be sure to confirm the directory did not already exist in the event a far too clever local attacker has already created that directory (unlikely, but this is why mktemp -d was created). Then, in your shell profile the alias might look something like

alias mpi4py='TMPDIR=/var/tmp/mympi mpi4py'

This form is again more suitable if there is shared state necessary between different MPI command invocations.

  • /private/tmp gets pruned regularly. If I just want one fixed tmp location for a specific application I would probably just create /tmp/APPNAME_temp and use this.
    – nohillside
    Jun 23, 2017 at 16:40
  • Just for the sake of generalization: The method is to create a new temporary tempdir, use that for mpi, and then when mpi is done TMPDIR is back to the old value? So if I want to use mpi4py I can change TMPDIR, do whatever, and then just close that terminal? Jun 23, 2017 at 18:05
  • And should your command at the end be alias yourmpicommand='TMPDIR=$(mktemp -d /tmp/mpi-XXXXXXXX) yourmpicommand' like above? Or is that something different? Jun 23, 2017 at 18:30
  • 1
    You would set an appropriate alias in your shell configuration; the terminal would not need to be closed as the custom environment would only apply to the command with the alias. Learning the basics of e.g. bash may be beneficial if this all seems mysterious.
    – thrig
    Jun 23, 2017 at 18:51
  • But if I alias mpiexec, for example, then a new TMPDIR would be set every time I run mpiexec. That doesn't seem like what I want to do. (Or is it?) Jun 23, 2017 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .