Safe to change TMPDIR? 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?
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
/tmp/mpi-zUN9SQo6


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.