PyTrilinos: How can I get the MPI include directory in a robust way?
Created by: wfspotz
@trilinos/pytrilinos @trilinos/framework
Expectations
In PyTrilinos, I have a python script that generates a SWIG interface file. That SWIG interface file needs to know where the mpi.h
header file is, so I can parse it and extract MPI_VERSION
. I developed some logic to find it that worked for me, but it is not robust enough to work for all users. How can I obtain the MPI include path for finding mpi.h
in a robust way?
Current Behavior
In #3618 the user specifies his MPI configuration with
-D TPL_ENABLE_MPI:BOOL=ON
-D MPI_EXEC:FILEPATH=/opt/apps/xalt/0.6/bin/ibrun
but my script specifies the path to mpi.h
incorrectly.
Motivation and Context
Here is what I do. I start with a file get_teuchos_rcp.py.in
that will get copied to the build directory with cmake
variable substituted in. It has the following function defined to correctly interpret cmake
boolean variables:
def cmake_bool(value):
if value.upper() in ("", "0", "FALSE", "N", "NO", "OFF"):
return False
return True
I then define python variable WITH_MPI
(among many others) using
WITH_MPI = cmake_bool("${TPL_ENABLE_MPI}")
I then use this logic to define python variable MPI_BASE_DIR
:
MPI_BASE_DIR = "${MPI_BASE_DIR}"
if WITH_MPI:
if MPI_BASE_DIR == "":
MPI_BIN_DIR = os.path.split("${MPI_CXX_COMPILER}")[0]
MPI_BASE_DIR = os.path.split(MPI_BIN_DIR)[0]
All this leads to supporting the following function:
def get_mpi_version():
header = os.path.join(MPI_BASE_DIR, "include", "mpi.h")
version = ""
for line in open(header, 'r').readlines():
if "MPI_VERSION" in line:
version = line.split()[2]
break
return version
But the assumption that mpi.h
lives in MPI_BASE_DIR/include
is wrong, because in my user's case, the actual path does not have an include
suffix.
Definition of Done
When the user in #3618 can build PyTrilinos at his installation, which is TACC.
Possible Solution
Does the cmake
logic that looks for MPI have logic that extracts the location of the mpi.h
file? If not, could it be added?
Related Issues
- Blocks #3618