Skip to content

Commit a33e593

Browse files
committed
Add MPI support
1 parent 0ed56af commit a33e593

File tree

3 files changed

+247
-112
lines changed

3 files changed

+247
-112
lines changed

CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ project(BabelStream VERSION 4.0 LANGUAGES CXX)
55
# uncomment for debugging build issues:
66
# set(CMAKE_VERBOSE_MAKEFILE ON)
77

8+
option(WITH_MPI "Enable MPI" OFF)
89
find_package(MPI)
910

1011
# some nicer defaults for standard C++
@@ -164,11 +165,16 @@ target_compile_options(${EXE_NAME} PUBLIC "$<$<CONFIG:Debug>:${ACTUAL_DEBUG_FLAG
164165
target_link_options(${EXE_NAME} PUBLIC LINKER:${CXX_EXTRA_LINKER_FLAGS})
165166
target_link_options(${EXE_NAME} PUBLIC ${LINK_FLAGS} ${CXX_EXTRA_LINK_FLAGS})
166167

167-
# If MPI is available, link relevant libraries
168-
if(MPI_FOUND)
169-
message(STATUS "MPI Detected. Linking relevant MPI libraries")
170-
target_link_libraries(${EXE_NAME} PUBLIC MPI::MPI_CXX)
171-
endif()
168+
# If MPI is requested, link relevant libraries
169+
if (WITH_MPI)
170+
if (MPI_FOUND)
171+
message(STATUS "MPI requested and found. Linking relevant MPI libraries.")
172+
target_link_libraries(${EXE_NAME} PUBLIC MPI::MPI_CXX)
173+
add_definitions(-DUSE_MPI)
174+
else ()
175+
message(FATAL_ERROR "MPI requested, but no implementation has been detected.")
176+
endif ()
177+
endif ()
172178

173179
# some models require the target to be already specified so they can finish their setup here
174180
# this only happens if the model.cmake definition contains the `setup_target` macro

src/hip/HIPStream.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ HIPStream<T>::HIPStream(const int ARRAY_SIZE, const int device_index)
4343
check_error();
4444

4545
// Print out device information
46-
std::cout << "Using HIP device " << getDeviceName(device_index) << std::endl;
46+
std::cout << "Using HIP device " << getDeviceName(device_index)
47+
<< " with index: " << device_index << std::endl;
4748
std::cout << "Driver: " << getDeviceDriver(device_index) << std::endl;
4849

4950
array_size = ARRAY_SIZE;

0 commit comments

Comments
 (0)