Skip to content

Commit

Permalink
Fix single-threaded CPU build with LLVM Clang/Flang (#24)
Browse files Browse the repository at this point in the history
* Fix single-threaded CPU build with LLVM Clang/Flang

Tested with LLVM main branch at f905877f2039 and OpenMPI 5.0.2 built
by that LLVM.

* Add usual compiler options for LLVM Clang/Flang builds

Tested with LLVM main branch at d1a461dbb229 and OpenMPI 5.0.2 built
by that LLVM.

---------

Co-authored-by: Joel E. Denny <jdenny-ornl@gmail.com>
  • Loading branch information
jdenny-ornl and Joel E. Denny authored Mar 29, 2024
1 parent 0aeeeb1 commit b7867c4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
16 changes: 16 additions & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ System libraries
-----------------------
UMT Requires MPI to be installed on your system to provide a C++ and Fortran compiler.

To build UMT with LLVM Clang/Flang, you must also use them to build MPI so that
Fortran mod files are compatible. For example, you might build OpenMPI as
follows:

```
$ CC=clang CXX=clang++ FC=flang-new \
CFLAGS=-O3 CXXFLAGS=-O3 FCFLAGS=-O3 \
../configure --prefix=$PWD/../install-flang \
--without-knem --without-ucx --enable-pretty-print-stacktrace \
--enable-orterun-prefix-by-default --enable-mpi1-compatibility
$ make -j
$ make install
```

Reference: <https://github.com/llvm/llvm-project/issues/56348>

Third party libraries
-----------------------
The code depends on several libraries.
Expand Down
12 changes: 11 additions & 1 deletion build_and_run_umt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ FFLAGS=-fallow-argument-mismatch
#CXX=icpx
#FC=ifx

# LLVM Clang/Flang build
#
# See DEPENDENCIES.md for a compatible MPI.
#
# So far this works only for single-threaded CPU execution.
#CC=clang
#CXX=clang++
#FC=flang-new
#FFLAGS=-flang-experimental-polymorphism

# Get directory this script is located in. This is assumed to be the UMT repo location.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
Expand All @@ -47,7 +57,7 @@ cd umt_workspace
git clone --recurse-submodules https://github.com/LLNL/conduit.git conduit -b v0.9.0
mkdir build_conduit
cd build_conduit
cmake ${PWD}/../conduit/src -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_Fortran_COMPILER=${FC} -DMPI_CXX_COMPILER=mpicxx -DMPI_Fortran_COMPILER=mpifort -DBUILD_SHARED_LIBS=OFF -DENABLE_TESTS=OFF -DENABLE_EXAMPLES=OFF -DENABLE_DOCS=OFF -DENABLE_FORTRAN=ON -DENABLE_MPI=ON -DENABLE_PYTHON=OFF
cmake ${PWD}/../conduit/src -DCMAKE_Fortran_FLAGS="${FFLAGS}" -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_Fortran_COMPILER=${FC} -DMPI_CXX_COMPILER=mpicxx -DMPI_Fortran_COMPILER=mpifort -DBUILD_SHARED_LIBS=OFF -DENABLE_TESTS=OFF -DENABLE_EXAMPLES=OFF -DENABLE_DOCS=OFF -DENABLE_FORTRAN=ON -DENABLE_MPI=ON -DENABLE_PYTHON=OFF
gmake -j install
cd ..

Expand Down
7 changes: 7 additions & 0 deletions src/cmake/InitBuildTypeCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "XL" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "XLClang")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -qstrict -qarch=auto -qtune=auto -qmaxmem=-1 -qsuppress=1500-036")
Expand Down Expand Up @@ -54,6 +57,10 @@ if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_Fortran_FLAGS_DEBUG "-fcheck=all -O0 -g -ffree-line-length-none")

elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Clang") # For Clang or AppleClang
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "LLVMFlang")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g")

elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "XL")
# Enable F2003 support via the below -qxlf2003 flag list. This behavior is the default if xlf2003 compiler is used, but not if xlf is used.
Expand Down
4 changes: 4 additions & 0 deletions src/cmake/InitLinkerWrapperFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ if ("Fortran" IN_LIST languages AND "${CMAKE_Fortran_LINKER_WRAPPER_FLAG}" STREQ
message(WARNING "Cray Fortran toolchain failed to set CMAKE_Fortran_LINKER_WRAPPER_FLAGS. Report this to vendor. Setting flag to '-Wl,' manually as workaround.")
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "LLVMFlang")
message(WARNING "LLVM Flang toolchain failed to set CMAKE_Fortran_LINKER_WRAPPER_FLAGS. Report this to vendor. Setting flag to '-Wl,' manually as workaround.")
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
else()
message(FATAL_ERROR "Toolchain file failed to initialize CMAKE_Fortran_LINKER_WRAPPER_FLAG, please submit a ticket to vendor.")
endif()
Expand Down
5 changes: 5 additions & 0 deletions src/teton/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ if(ENABLE_TESTS)
add_executable( test_driver
driver/test_driver.cc )

if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "LLVMFlang")
set_target_properties( test_driver PROPERTIES LINK_FLAGS -fno-fortran-main)
set(OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS} -fno-fortran-main")
endif()

if (ENABLE_FIND_MPI)
target_link_libraries( test_driver PUBLIC MPI::MPI_Fortran MPI::MPI_CXX )
endif()
Expand Down

0 comments on commit b7867c4

Please sign in to comment.