Skip to content

Commit

Permalink
system interrogation for mpi/etc
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Nov 13, 2023
1 parent cffbb1e commit 24ca9c1
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 41 deletions.
30 changes: 0 additions & 30 deletions lgtm.yml

This file was deleted.

1 change: 1 addition & 0 deletions src/core/def/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_gen*
16 changes: 16 additions & 0 deletions src/core/def/mpi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

// DO NOT INCLUDE MPI MANUALLY! USE THIS FILE!

#if __has_include("core/def/_gen_mpi.hpp")
#include "core/def/_gen_mpi.hpp"
#else
// Not always an issue, but not recommended
#endif

#include "core/def/pragma_disable.hpp"

// clang-format off
DISABLE_WARNING(cast-function-type, bad-function-cast, 42)
#include "mpi.h"
ENABLE_WARNING(cast-function-type, bad-function-cast, 42)
// clang-format on
File renamed without changes.
7 changes: 1 addition & 6 deletions src/core/utilities/mpi_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
#include <cstring>
#include <exception>

// clang-format off
#include "initializer/pragma_disable.hpp"
DISABLE_WARNING(cast-function-type, bad-function-cast, 42)
#include "mpi.h"
ENABLE_WARNING(cast-function-type, bad-function-cast, 42)
// clang-format on

#include "core/def/mpi.hpp"
#include "core/utilities/span.hpp"
#include "core/utilities/types.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/initializer/python_data_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "initializer/data_provider.hpp"

#include "pragma_disable.hpp"
#include "core/def/pragma_disable.hpp"

// clang-format off
DISABLE_WARNING(shadow, shadow-field-in-constructor-modified, 42)
Expand Down
2 changes: 1 addition & 1 deletion src/python3/cpp_simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <vector>
#include <cstddef>

#include "mpi.h"
#include "core/def/mpi.hpp"

#include "core/utilities/mpi_utils.hpp"
#include "core/data/particles/particle.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <mpi.h>
#include "core/def/mpi.hpp"

#include "tests/simulator/per_test.hpp"

Expand Down
2 changes: 1 addition & 1 deletion tests/diagnostic/test-diagnostics_1d.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <mpi.h>
#include "core/def/mpi.hpp"

#include "test_diagnostics.ipp"

Expand Down
2 changes: 1 addition & 1 deletion tests/diagnostic/test-diagnostics_2d.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <mpi.h>
#include "core/def/mpi.hpp"

#include "test_diagnostics.ipp"

Expand Down
27 changes: 27 additions & 0 deletions tools/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

project(phare_configurator)

cmake_minimum_required (VERSION 3.22)

set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)


find_package(MPI REQUIRED)
foreach(LIB ${MPI_LIBRARY})
get_filename_component(MPI_LIBRARY_PATH ${LIB} DIRECTORY)
endforeach()

include_directories(${MPI_C_HEADER_DIR})

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} mpi mpi_cxx)
target_link_directories(${PROJECT_NAME} PUBLIC ${MPI_LIBRARY_PATH})

## probably should do something to check if mpi_cxx is even available, cause deprecated.
# get_cmake_property(_variableNames VARIABLES)
# list (SORT _variableNames)
# foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()

12 changes: 12 additions & 0 deletions tools/config/cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" && cd "$CWD"
ROOT_DIR=$(cd ../.. && pwd)
[ -f "${ROOT_DIR}/res/cmake/def.cmake" ] || (echo "Corruption detected" && exit 1) # confirm correct directory

[ -d build ] || (
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. -G Ninja 2>&1 > /dev/null
ninja && ./phare_configurator
)
python3 config.py
45 changes: 45 additions & 0 deletions tools/config/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
from pathlib import Path

FILE_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
ROOT_DIR = Path(os.path.realpath(FILE_DIR / ".." / ".."))
if not os.path.exists(ROOT_DIR / "src" / "core" / "def"):
raise RuntimeError("Corruption detected")
FILES = [f for f in Path(FILE_DIR).glob("build/PHARE_*")]


def local_file_format(filename):
return filename[6:-4]


def create_file(f):
with open(f, "a") as file:
file.truncate(0)


def config_mpi_version(txtfile, h_file):
with open(txtfile) as f:
version = f.readline()
out_buff = "\n"
if "OpenMPI" in version:
out_buff += "// avoids default including mpicxx \n"
out_buff += "#define OMPI_SKIP_MPICXX 1 \n\n"
with open(h_file, "w") as f:
f.write(out_buff)


def config_mpi():
h_file = ROOT_DIR / "src" / "core" / "def" / "_gen_mpi.hpp"
create_file(h_file)
operatators = dict(MPI_Get_library_version=config_mpi_version)
for f in FILES:
fn = operatators.get(local_file_format(f.name), lambda x, y: 0)
fn(f, h_file)


def main():
config_mpi()


if __name__ == "__main__":
main()
20 changes: 20 additions & 0 deletions tools/config/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#include "mpi.h"

#include <fstream>
#include <exception>

void config_mpi()
{
char version[MPI_MAX_LIBRARY_VERSION_STRING];
int resultlen = 0;
auto ret = MPI_Get_library_version(version, &resultlen);
if (ret)
throw std::runtime_error("error calling MPI_Get_library_version");
std::ofstream{"PHARE_MPI_Get_library_version.txt", std::ios::out} << version << std::endl;
}

int main()
{
config_mpi();
}

0 comments on commit 24ca9c1

Please sign in to comment.