Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active February 16, 2023 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scivision/bd9710c49b5b11d479675c261821af58 to your computer and use it in GitHub Desktop.
Save scivision/bd9710c49b5b11d479675c261821af58 to your computer and use it in GitHub Desktop.
OpenMPI 4.x TMPDIR race vader unlink error workaround
# this is a dummy exmaple project. The actual workaround is in openmpi.cmake.
cmake_minimum_required(VERSION 3.14)
project(Workaround LANGUAGES C)
enable_testing()
include(openmpi.cmake)
set(MPI_DETERMINE_LIBRARY_VERSION true)
find_package(MPI COMPONENTS C REQUIRED)
message(STATUS "MPI Library Version: ${MPI_C_LIBRARY_VERSION_STRING}")
add_executable(my_mpi main.c)
add_test(NAME MyMPI
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} my_mpi)
get_property(tests DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
if(DEFINED mpi_tmpdir)
# enact the workaround
set_property(TEST ${tests} PROPERTY ENVIRONMENT TMPDIR=${mpi_tmpdir})
endif()
# https://github.com/open-mpi/ompi/issues/7393
# https://github.com/gerlero/openfoam-app/pull/112
# https://apple.stackexchange.com/a/287710
# *** OpenMPI workaround
if(UNIX AND MPI_C_LIBRARY_VERSION_STRING MATCHES "Open[ ]?MPI"))
if(NOT DEFINED mpi_tmpdir)
execute_process(COMMAND mktemp -d /tmp/mpi-XXXXXXXX
RESULT_VARIABLE ret
OUTPUT_VARIABLE mpi_tmpdir
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ret EQUAL 0)
message(FATAL_ERROR "could not create MPI working dir via mktemp -d: ${ret}")
endif()
set(mpi_tmpdir ${mpi_tmpdir} CACHE PATH "MPI working dir")
message(STATUS "${ret}: Created MPI working dir ${mpi_tmpdir}")
endif()
endif()
# *** END OpenMPI workaround
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment