-
Notifications
You must be signed in to change notification settings - Fork 66
Update BLT to apply MPI flags for the respective compilers to only the respective compiler lines #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aaroncblack
wants to merge
2
commits into
develop
Choose a base branch
from
bugfix/aaroncblack/fix_mpi_flags
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update BLT to apply MPI flags for the respective compilers to only the respective compiler lines #771
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| cmake_minimum_required(VERSION 3.14) | ||
|
|
||
| project(mpi-mixed-language LANGUAGES CXX) | ||
|
|
||
| set(BLT_CXX_STD c++14 CACHE STRING "") | ||
| set(ENABLE_MPI On CACHE BOOL "") | ||
| list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../fake_mpi") | ||
|
|
||
| include(${BLT_SOURCE_DIR}/SetupBLT.cmake) | ||
|
|
||
| blt_install_tpl_setups(DESTINATION lib/cmake/${PROJECT_NAME}) | ||
|
|
||
| blt_add_library( | ||
| NAME mpi-mixed-language | ||
| SOURCES mpi-mixed-language.cpp | ||
| DEPENDS_ON blt::mpi) | ||
|
|
||
| install(TARGETS mpi-mixed-language | ||
| EXPORT mpi-mixed-language-targets) | ||
|
|
||
| install(FILES | ||
| ${PROJECT_SOURCE_DIR}/mpi-mixed-language-config.cmake | ||
| DESTINATION lib/cmake/mpi-mixed-language) | ||
|
|
||
| install(EXPORT mpi-mixed-language-targets | ||
| DESTINATION lib/cmake/mpi-mixed-language) |
2 changes: 2 additions & 0 deletions
2
tests/projects/mpi-mixed-language/base/mpi-mixed-language-config.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| include("${CMAKE_CURRENT_LIST_DIR}/mpi-mixed-language-targets.cmake") | ||
| include("${CMAKE_CURRENT_LIST_DIR}/BLTSetupTargets.cmake") |
13 changes: 13 additions & 0 deletions
13
tests/projects/mpi-mixed-language/base/mpi-mixed-language.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <mpi.h> | ||
|
|
||
| #ifndef BLT_FAKE_MPI_CXX_HEADER | ||
| #error "Expected the fake CXX MPI include directory" | ||
| #endif | ||
|
|
||
| #ifndef BLT_FAKE_MPI_CXX_COMPILE_OPTION | ||
| #error "Expected the fake CXX MPI compile option" | ||
| #endif | ||
|
|
||
| void blt_mpi_mixed_language() | ||
| { | ||
| } |
77 changes: 77 additions & 0 deletions
77
tests/projects/mpi-mixed-language/downstream/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| foreach(_option MPI CUDA HIP OPENMP) | ||
| unset(ENABLE_${_option} CACHE) | ||
| unset(ENABLE_${_option}) | ||
| endforeach() | ||
|
|
||
| cmake_minimum_required(VERSION 3.14) | ||
|
|
||
| project(mpi-mixed-language-user LANGUAGES CXX Fortran) | ||
|
|
||
| list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../fake_mpi") | ||
|
|
||
| find_package(mpi-mixed-language REQUIRED | ||
| NO_DEFAULT_PATH | ||
| PATHS ${base_install_dir}/lib/cmake/mpi-mixed-language) | ||
|
|
||
| set(_fake_mpi_root "${CMAKE_CURRENT_LIST_DIR}/../fake_mpi") | ||
| get_filename_component(_fake_mpi_root "${_fake_mpi_root}" ABSOLUTE) | ||
|
|
||
| function(_require_property_item target property expected) | ||
| get_target_property(_items ${target} ${property}) | ||
| if(NOT _items) | ||
| message(FATAL_ERROR "Expected ${target} to have ${property}") | ||
| endif() | ||
|
|
||
| if(NOT "${expected}" IN_LIST _items) | ||
| message(FATAL_ERROR | ||
| "Expected ${target} ${property} to contain '${expected}', " | ||
| "but got '${_items}'") | ||
| endif() | ||
| endfunction() | ||
|
|
||
| function(_reject_raw_property_item target property unexpected) | ||
| get_target_property(_items ${target} ${property}) | ||
| if(NOT _items) | ||
| return() | ||
| endif() | ||
|
|
||
| if("${unexpected}" IN_LIST _items) | ||
| message(FATAL_ERROR | ||
| "Expected ${target} ${property} not to contain unguarded item " | ||
| "'${unexpected}', but got '${_items}'") | ||
| endif() | ||
| endfunction() | ||
|
|
||
| set(_c_include "${_fake_mpi_root}/include/c") | ||
| set(_cxx_include "${_fake_mpi_root}/include/cxx") | ||
| set(_fortran_include "${_fake_mpi_root}/include/fortran") | ||
|
|
||
| _require_property_item(mpi INTERFACE_SYSTEM_INCLUDE_DIRECTORIES | ||
| "$<$<COMPILE_LANGUAGE:C>:${_c_include}>") | ||
| _require_property_item(mpi INTERFACE_SYSTEM_INCLUDE_DIRECTORIES | ||
| "$<$<COMPILE_LANGUAGE:CXX>:${_cxx_include}>") | ||
| _require_property_item(mpi INTERFACE_SYSTEM_INCLUDE_DIRECTORIES | ||
| "$<$<COMPILE_LANGUAGE:Fortran>:${_fortran_include}>") | ||
|
|
||
| _reject_raw_property_item(mpi INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_c_include}") | ||
| _reject_raw_property_item(mpi INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_cxx_include}") | ||
| _reject_raw_property_item(mpi INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_fortran_include}") | ||
|
|
||
| _require_property_item(mpi INTERFACE_COMPILE_OPTIONS | ||
| "$<$<COMPILE_LANGUAGE:C>:-DBLT_FAKE_MPI_C_COMPILE_OPTION>") | ||
| _require_property_item(mpi INTERFACE_COMPILE_OPTIONS | ||
| "$<$<COMPILE_LANGUAGE:CXX>:-DBLT_FAKE_MPI_CXX_COMPILE_OPTION>") | ||
| _require_property_item(mpi INTERFACE_COMPILE_OPTIONS | ||
| "$<$<COMPILE_LANGUAGE:Fortran>:-DBLT_FAKE_MPI_FORTRAN_COMPILE_OPTION>") | ||
|
|
||
| _reject_raw_property_item(mpi INTERFACE_COMPILE_OPTIONS "-DBLT_FAKE_MPI_C_COMPILE_OPTION") | ||
| _reject_raw_property_item(mpi INTERFACE_COMPILE_OPTIONS "-DBLT_FAKE_MPI_CXX_COMPILE_OPTION") | ||
| _reject_raw_property_item(mpi INTERFACE_COMPILE_OPTIONS "-DBLT_FAKE_MPI_FORTRAN_COMPILE_OPTION") | ||
|
|
||
| add_executable(mpi-mixed-language-user mpi-mixed-language-user.F) | ||
| target_link_libraries(mpi-mixed-language-user PUBLIC mpi-mixed-language mpi) | ||
|
|
||
| set_source_files_properties( | ||
| mpi-mixed-language-user.F | ||
| PROPERTIES | ||
| Fortran_FORMAT FREE) |
10 changes: 10 additions & 0 deletions
10
tests/projects/mpi-mixed-language/downstream/mpi-mixed-language-user.F
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #ifndef BLT_FAKE_MPI_FORTRAN_COMPILE_OPTION | ||
| #error "Expected the fake Fortran MPI compile option" | ||
| #endif | ||
|
|
||
| program fortran_test | ||
| include 'mpif.h' | ||
|
|
||
| if (blt_fake_mpi_fortran_header .ne. 1) stop 1 | ||
|
|
||
| end program fortran_test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and | ||
| # other BLT Project Developers. See the top-level LICENSE file for details | ||
| # | ||
| # SPDX-License-Identifier: (BSD-3-Clause) | ||
|
|
||
| set(_fake_mpi_root "${CMAKE_CURRENT_LIST_DIR}") | ||
|
|
||
| set(MPI_FOUND TRUE) | ||
| set(MPI_C_FOUND TRUE) | ||
| set(MPI_CXX_FOUND TRUE) | ||
| set(MPI_Fortran_FOUND TRUE) | ||
|
|
||
| set(MPIEXEC_EXECUTABLE "${CMAKE_COMMAND}") | ||
| set(MPIEXEC "${CMAKE_COMMAND}") | ||
| set(MPIEXEC_NUMPROC_FLAG "-E") | ||
|
|
||
| set(MPI_C_INCLUDE_DIRS "${_fake_mpi_root}/include/c") | ||
| set(MPI_CXX_INCLUDE_DIRS "${_fake_mpi_root}/include/cxx") | ||
| set(MPI_Fortran_INCLUDE_DIRS "${_fake_mpi_root}/include/fortran") | ||
|
|
||
| set(MPI_C_INCLUDE_PATH "${MPI_C_INCLUDE_DIRS}") | ||
| set(MPI_CXX_INCLUDE_PATH "${MPI_CXX_INCLUDE_DIRS}") | ||
| set(MPI_Fortran_INCLUDE_PATH "${MPI_Fortran_INCLUDE_DIRS}") | ||
|
|
||
| set(MPI_C_COMPILE_OPTIONS "-DBLT_FAKE_MPI_C_COMPILE_OPTION") | ||
| set(MPI_CXX_COMPILE_OPTIONS "-DBLT_FAKE_MPI_CXX_COMPILE_OPTION") | ||
| set(MPI_Fortran_COMPILE_OPTIONS "-DBLT_FAKE_MPI_FORTRAN_COMPILE_OPTION") | ||
|
|
||
| set(MPI_C_COMPILE_FLAGS "${MPI_C_COMPILE_OPTIONS}") | ||
| set(MPI_CXX_COMPILE_FLAGS "${MPI_CXX_COMPILE_OPTIONS}") | ||
| set(MPI_Fortran_COMPILE_FLAGS "${MPI_Fortran_COMPILE_OPTIONS}") | ||
|
|
||
| set(MPI_C_LINK_FLAGS "") | ||
| set(MPI_CXX_LINK_FLAGS "") | ||
| set(MPI_Fortran_LINK_FLAGS "") | ||
| set(MPI_C_LIBRARIES "") | ||
| set(MPI_CXX_LIBRARIES "") | ||
| set(MPI_Fortran_LIBRARIES "") | ||
|
|
||
| unset(_fake_mpi_root) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #ifndef BLT_TEST_FAKE_MPI_C_MPI_H | ||
| #define BLT_TEST_FAKE_MPI_C_MPI_H | ||
|
|
||
| #define BLT_FAKE_MPI_C_HEADER 1 | ||
|
|
||
| #endif |
48 changes: 48 additions & 0 deletions
48
tests/projects/mpi-mixed-language/fake_mpi/include/cxx/mpi.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #ifndef BLT_TEST_FAKE_MPI_CXX_MPI_H | ||
| #define BLT_TEST_FAKE_MPI_CXX_MPI_H | ||
|
|
||
| #define BLT_FAKE_MPI_CXX_HEADER 1 | ||
|
|
||
| typedef int MPI_Comm; | ||
| typedef int MPI_Datatype; | ||
| typedef int MPI_Op; | ||
|
|
||
| #define MPI_COMM_WORLD 0 | ||
| #define MPI_INT 0 | ||
| #define MPI_SUM 0 | ||
|
|
||
| static inline int MPI_Init(int *, char ***) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static inline int MPI_Comm_rank(MPI_Comm, int *rank) | ||
| { | ||
| *rank = 0; | ||
| return 0; | ||
| } | ||
|
|
||
| static inline int MPI_Comm_size(MPI_Comm, int *size) | ||
| { | ||
| *size = 4; | ||
| return 0; | ||
| } | ||
|
|
||
| static inline int MPI_Reduce(const void *sendbuf, | ||
| void *recvbuf, | ||
| int, | ||
| MPI_Datatype, | ||
| MPI_Op, | ||
| int, | ||
| MPI_Comm) | ||
| { | ||
| *static_cast<int *>(recvbuf) = *static_cast<const int *>(sendbuf) * 4; | ||
| return 0; | ||
| } | ||
|
|
||
| static inline int MPI_Finalize() | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| #endif |
1 change: 1 addition & 0 deletions
1
tests/projects/mpi-mixed-language/fake_mpi/include/fortran/mpif.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| integer, parameter :: blt_fake_mpi_fortran_header = 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@white238 I told the agent that our C++ codes make heavy use of the C MPI API, so to focus on splitting out the C/C++ vs the Fortran paths and flags.
It said in many MPI installs the MPI_C_INCLUDE_DIRS and MPI_CXX_INCLUDE_DIRS are identical, but if its a concern, another option is to have the C++ get both C and CXX mpi flags and paths, de-duplicated.