Skip to content

Commit

Permalink
Merge pull request #10 from LIHPC-Computational-Geometry/fortran_comp…
Browse files Browse the repository at this point in the history
…ile_flags

Cmake target lima_fortran_compile_flags intended to pass to fortran c…
  • Loading branch information
CharlesPignerol authored Mar 1, 2024
2 parents 8609b58 + 9635904 commit ab80057
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ option (FORMAT_MLI2 "Format remplaçant le format MLI recommandé partout. Requi
# Binaires optionnels :
option (BUILD_SCRIPTING "Génération du wrapper swig/python pour utilisation scriptée de Lima." ON)
option (BUILD_XLMLIMA "Utilitaire xlmlima (conversions, préparations de maillages), symetrise (symétrisation / x, y ou z)." ON)
option (BUILD_TESTS "Création de l'utilitaire comparaison." OFF)
option (BUILD_TESTS "Création de l'utilitaire comparaison." ON)
option (DISABLE_MLI_WARNING "Désactivation de l'affichage d'un avertissement signalant que le format mli est obsolète et recommandant en remplacement l'usage du format mli2." OFF)

add_subdirectory (src)
Expand Down
133 changes: 133 additions & 0 deletions cmake/compilation_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# -------------------------------------------------------------------------------------------------------------------------
# Le contenu de ce fichier permet de gérer des options de compilation indispensables à une bonne utilisation de Lima.
# Ces options de compilation définissent la taille d'encodage des entiers et réels.
# C'est par exemple indispensable à des codes fortran dont les arguments transmis lors des appels Lima sont de type
# INTEGER ou REAL.
# -------------------------------------------------------------------------------------------------------------------------

# ---------------------------------
# manage integer
# ---------------------------------
#
# I4
# C and C++
# Fortran if Intel
# Fortran if GNU
# Fortran if ARM
# Fortran if FLANG
# Fortran if IBM
# Fortran if PGI
# I8
# C and C++
# Fortran if Intel
# Fortran if GNU
# Fortran if ARM
# Fortran if FLANG
# Fortran if IBM
# Fortran if PGI
# ---------------------------------
if (NOT INT_8)
set (LIMA_INT_SIZE "INTEGER_32")
else() # I8
set (LIMA_INT_SIZE "INTEGER_64")
endif()


# ---------------------------------
# manage real
# ---------------------------------
#
# R4
# C and C++
# Fortran if Intel
# Fortran if GNU
# Fortran if ARM
# Fortran if FLANG
# Fortran if IBM
# Fortran if PGI
# R8
# C and C++
# Fortran if Intel
# Fortran if GNU
# Fortran if ARM
# Fortran if FLANG
# Fortran if IBM
# Fortran if PGI
# ---------------------------------
if (NOT REAL_8)
set (LIMA_REAL_SIZE "REAL_32")
else() # R8
set (LIMA_REAL_SIZE "REAL_64")
endif()



if (DEFINED CMAKE_Fortran_COMPILER_ID)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "ARM" OR CMAKE_Fortran_COMPILER MATCHES "armflang") # cmake does always have proper COMPILER_ID for arm compiler
set(i4_opt "") # -i4 does not exists, but it's the default
set(i8_opt -i8)
set(r4_opt "") # -r4 does not exists, but it's the default
set(r8_opt -r8)
set(r16_opt -r16) # future ?
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") # gnu (gcc) gfortran
set(i4_opt "") # -fdefault-integer-4 does not exists, but it's the default
set(i8_opt -fdefault-integer-8)
set(r4_opt "") # -fdefault-real-4 does not exists, but it's default
set(r8_opt -fdefault-real-8)
set(r16_opt -fdefault-real-16) # future ?
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM") # intel (icc/icx) ifort/ifx
set(i4_opt -i4)
set(i8_opt -i8)
set(r4_opt "") # -r4 does not exists, but it's the default
set(r8_opt -r8)
set(r16_opt -r16)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Flang") # llvm (clang) flang
set(i4_opt "")
set(i8_opt -i8)
set(r4_opt "")
set(r8_opt -r8)
set(r16_opt -r16) # future ?
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "XL" OR CMAKE_Fortran_COMPILER_NAME MATCHES "xlf*") # VisualAge (ibm) xlfortran
# set(i2_opt -qintsize=2) # available but not used
set(i4_opt -qintsize=4) # (default)
set(i8_opt -qintsize=8)
set(r4_opt -qrealsize=4) # (default)
set(r8_opt -qrealsize=8)
set(r16_opt -qrealsize=16) # not present in xlf (xlf_r) 16.1
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" OR CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC") # PGI (portland group) pgf[77,90,95] = pgfortran
# set(i2_opt -i2) # available but not used
set(i4_opt -i4) # (default)
set(i8_opt -i8)
set(r4_opt -r4) # (default)
set(r8_opt -r8)
set(r16_opt -r16) # not present in pgfortran 20.9-0
else()
message(FATAL_ERROR
"Unknown Fortran compiler '${CMAKE_Fortran_COMPILER_ID}' ('${CMAKE_Fortran_COMPILER}'), "
"IR flags not implemented.")
endif()

set(FORTRAN_FLAGS "")
set(FORTRAN_FLAGS_LIST "")
if (NOT INT_8)
string (APPEND FORTRAN_FLAGS " ${i4_opt}")
list (APPEND FORTRAN_FLAGS_LIST "${i4_opt}")
else()
string (APPEND FORTRAN_FLAGS " ${i8_opt}")
list (APPEND FORTRAN_FLAGS_LIST "${i8_opt}")
endif()

if (NOT REAL_8)
string (APPEND FORTRAN_FLAGS " ${r4_opt}")
list (APPEND FORTRAN_FLAGS_LIST "${r4_opt}")
else()
string (APPEND FORTRAN_FLAGS " ${r8_opt}")
list (APPEND FORTRAN_FLAGS_LIST "${r8_opt}")
endif()
set(FORTRAN_FLAGS "")
string (REPLACE ";" " " FORTRAN_FLAGS "${FORTRAN_FLAGS_LIST}")
# set compile flags

set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FORTRAN_FLAGS}" CACHE FILEPATH "" FORCE)

endif()
4 changes: 2 additions & 2 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#

set (LIMA_MAJOR_VERSION "7")
set (LIMA_MINOR_VERSION "9")
set (LIMA_RELEASE_VERSION "6")
set (LIMA_MINOR_VERSION "10")
set (LIMA_RELEASE_VERSION "0")
set (LIMA_VERSION ${LIMA_MAJOR_VERSION}.${LIMA_MINOR_VERSION}.${LIMA_RELEASE_VERSION})


9 changes: 0 additions & 9 deletions configurations/Ubuntu_GNU11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ set(CMAKE_CXX_COMPILER g++-11)
set(CMAKE_CXX_FLAGS -std=c++11)
set(CMAKE_Fortran_COMPILER "${GNU_ROOT}/bin/gfortran")

#set (CMAKE_Fortran_FLAGS "-fdefault-real-8") # I4/R8 insuffisant si des double precision sont déclarés car alors promus en R16
set (CMAKE_Fortran_FLAGS)
if (INT_8)
string(APPEND CMAKE_Fortran_FLAGS " -fdefault-integer-8")
endif (INT_8)
if (REAL_8)
string (APPEND CMAKE_Fortran_FLAGS " -fdefault-real-8 -fdefault-double-8")
endif (REAL_8)

# SWIG_EXECUTABLE : requiert d'être en cache pour fonctionner tout au long de la chaine ...
set (SWIG_EXECUTABLE "/opt/swig/3.0.12/bin/swig" CACHE FILEPATH "Swig exe" FORCE)

Expand Down
6 changes: 5 additions & 1 deletion configurations/Ubuntu_GNU11_external_meshlibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ set (ZLIB_ROOT ${HDF5_DIR} CACHE PATH "Chemin d'acces a la bibliotheque ZLIB uti
message (STATUS "======================================================== VARIABLES ENVIRONNEMENTALES DEPENDANCES MAILLAGE ========================================================")
message (STATUS "======================> HDF5_DIR =${HDF5_DIR}")


set (HDF145_DIR "/opt22/hdf145/1.3.1" CACHE PATH "Chemin d'acces a la bibliotheque HDF 145" FORCE)
set (HDF145_ROOT ${HDF145_DIR} CACHE PATH "Chemin d'acces a la bibliotheque HDF 145" FORCE)
set (HDF145_INCLUDE_DIR "${HDF145_DIR}/include" CACHE PATH "Chemin d'acces aux entetes de la bibliotheque HDF 145" FORCE)
set (HDF145CPP_LIBRARY "${HDF145_DIR}/lib/libhdf145_cpp.so" CACHE PATH "Chemin d'acces aux entetes de la bibliotheque HDF 145" FORCE)
set (HDF145_LIBRARY "${HDF145_DIR}/lib/libhdf145.so" CACHE PATH "Chemin d'acces aux entetes de la bibliotheque HDF 145" FORCE)

9 changes: 0 additions & 9 deletions configurations/Ubuntu_GNU7.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ set(CMAKE_CXX_COMPILER g++-7)
set(CMAKE_CXX_FLAGS -std=c++11)
set(CMAKE_Fortran_COMPILER "${GNU_ROOT}/bin/gfortran")

#set (CMAKE_Fortran_FLAGS "-fdefault-real-8") # I4/R8 insuffisant si des double precision sont déclarés car alors promus en R16
set (CMAKE_Fortran_FLAGS)
if (INT_8)
string(APPEND CMAKE_Fortran_FLAGS " -fdefault-integer-8")
endif (INT_8)
if (REAL_8)
string (APPEND CMAKE_Fortran_FLAGS " -fdefault-real-8 -fdefault-double-8")
endif (REAL_8)

# SWIG_EXECUTABLE : requiert d'être en cache pour fonctionner tout au long de la chaine ...
set (SWIG_EXECUTABLE "/opt/swig/3.0.12/bin/swig" CACHE FILEPATH "Swig exe" FORCE)

Expand Down
8 changes: 6 additions & 2 deletions installation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_
-DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_XLMLIMA=ON -DBUILD_TESTS:BOOL=ON -DBUILD_SCRIPTING:BOOL=ON -DMACHINE_TYPES:BOOL=OFF -DSUMESH:BOOL=OFF -DFORMAT_MLI:BOOL=OFF -DFORMAT_MLI2:BOOL=ON -DFORMAT_MLI2:BOOL=ON \
-DBUILD_SHARED_LIBS:BOOL=ON -DINT_8:BOOL=ON -DREAL_8:BOOL=ON \
-DSWIG_EXECUTABLE=/opt/swig/4.1.1/bin/swig -DPython2_ROOT_DIR=/usr/lib/python2.7 -DHDF5_ROOT=/opt/HDF5/1.12.0 \
-B /tmp/lima_build_dir -DCMAKE_INSTALL_PREFIX=/opt/Lima/7.9.6
-B /tmp/lima_build_dir -DCMAKE_INSTALL_PREFIX=/opt/Lima/7.10.0
cmake --build /tmp/lima_build_dir
cmake --install /tmp/lima_build_dir

Expand All @@ -30,7 +30,7 @@ cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_
-DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_XLMLIMA=ON -DBUILD_TESTS:BOOL=ON -DBUILD_SCRIPTING:BOOL=ON -DMACHINE_TYPES:BOOL=ON -DSUMESH:BOOL=ON -DFORMAT_MLI:BOOL=ON -DFORMAT_MLI2:BOOL=ON \
-DBUILD_SHARED_LIBS:BOOL=ON -DINT_8:BOOL=ON -DREAL_8:BOOL=ON \
-DSWIG_EXECUTABLE=/opt/swig/4.1.1/bin/swig -DPython2_ROOT_DIR=/usr/lib/python2.7 -DHDF5_ROOT=/opt/HDF5/1.12.0 -DHDF145_INCLUDE_DIR=/opt/hdf145/1.3.0/include -DHDF145CPP_LIBRARY=/opt/hdf145/1.3.0/lib/libhdf145_cpp.so -DHDF145_LIBRARY=/opt/hdf145/1.3.0/lib/libhdf145.so \
-B /tmp/lima_build_dir -DCMAKE_INSTALL_PREFIX=/opt/Lima/7.9.6
-B /tmp/lima_build_dir -DCMAKE_INSTALL_PREFIX=/opt/Lima/7.10.0
cmake --build /tmp/lima_build_dir
cmake --install /tmp/lima_build_dir

Expand All @@ -51,6 +51,7 @@ L'option -DMACHINE_TYPES:BOOL=OFF permet de désactiver l'utilisation de Machine
L'option -DSUMESH:BOOL=OFF permet de désactiver l'utilisation de la bibliothèque sumesh (lissage).

L'option -DFORMAT_MLI:BOOL=OFF permet de désactiver le lecteur/écrivain obsolète "mli" qui repose sur la bibliothèque HDF 5 1.4.5.
L'option -DDISABLE_MLI_WARNING:BOOL=ON, fortement déconseillée, permet de désactiver l'affichage en bleu dans la console d'un avertissement signalant l'utilisation de ce lecteur/écrivain obsolète "mli".

L'option -DFORMAT_MLI2:BOOL=OFF permet de désactiver le lecteur/écrivain "mli2" qui repose sur une version supérieure ou égale à 1.10.0 de la bibliothèque HDF 5.

Expand All @@ -74,6 +75,9 @@ ATTENTION : la lib Z peut être requise pour HDF 1.4.5, HDF5, et le logiciel à
Taille des entiers pour le langage fortran : il convient de transmettre aux compilateurs C/C++ l'option -DINTEGER_32 si ils sont codés sur 32 bits ou -DINTEGER_64 si ils sont codés sur 64 bits, ce codage étant souvent côté
fortran une instruction transmise au compilateur type -i8.
On peut préciser à cmake la taille d'encodage des entiers et réels via les options booléennes INT_8 et REAL_8. Ex pour I4.R8 : -DINT_8:BOOL=OFF -DREAL_8:BOOL=ON
Depuis la version 7.10.0 les codes fortran peuvent profiter de la cible Lima::lima_fortran_compile_flags pour récupérer à la compilation les drapeaux de compilation permettant au compilateur fortran d'encoder les entiers (INTEGER) et flottants (REAL) par défaut sur le même nombre d'octets que Lima. Pour ce il suffit par exemple d'utiliser cette cible comme suit :
find_package (Lima REQUIRED)
target_link_libraries (code_fortran PUBLIC Lima::Lima Lima::lima_fortran_compile_flags)

Le script build.sh et les fichiers du répertoire configurations - à adapter - permettent d'installer lima à moindre coût.

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ if (BUILD_XLMLIMA) # and other tools
add_subdirectory (Symetrise)
endif ( )

enable_testing ( )
24 changes: 11 additions & 13 deletions src/Lima/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ set (CURRENT_PACKAGE_NAME "Lima")
set (CURRENT_PACKAGE_MACRO_NAME "LIMA_KERNEL")
include (${CMAKE_SOURCE_DIR}/cmake/version.cmake)
include (${CMAKE_SOURCE_DIR}/cmake/common.cmake)
include (${CMAKE_SOURCE_DIR}/cmake/compilation_options.cmake)
include (${CMAKE_SOURCE_DIR}/cmake/workarounds.cmake)


if (MACHINE_TYPES)
find_package (MachineTypes REQUIRED)
endif (MACHINE_TYPES)
Expand Down Expand Up @@ -35,6 +38,7 @@ if ((PLATFORM STREQUAL "CentOS") OR (PLATFORM STREQUAL "Atos_7__x86_64") OR (PLA
endif ()

add_library (Lima ${CPP_SOURCES} ${HEADERS} ${ICEMCFD_OBJS})
add_library (lima_fortran_compile_flags INTERFACE)

set (MLI_SUPPORTED OFF)
set (EXTERNAL_LIBS_FLAGS)
Expand All @@ -60,16 +64,9 @@ else (HDF5_FOUND AND HDF5_INCLUDE_DIRS AND HDF5_CXX_LIBRARIES AND (HDF5_VERSION
message (WARNING "======================> API HDF5 NON TROUVEE (ou version < 1.10.0 ou absence d'API c++) : pas de support du format mli2 <======================")
endif (HDF5_FOUND AND HDF5_INCLUDE_DIRS AND HDF5_CXX_LIBRARIES AND (HDF5_VERSION VERSION_GREATER_EQUAL 1.10.0))

if (INT_8)
list (APPEND LIMA_CFLAGS -DINTEGER_64)
else (INT_8)
list (APPEND LIMA_CFLAGS -DINTEGER_32)
endif (INT_8)
if (REAL_8)
list (APPEND LIMA_CFLAGS -DREAL_64)
else (REAL_8)
list (APPEND LIMA_CFLAGS -DREAL_32)
endif (REAL_8)
list (APPEND LIMA_CFLAGS "-D${LIMA_INT_SIZE}")
list (APPEND LIMA_CFLAGS "-D${LIMA_REAL_SIZE}")
target_compile_options (lima_fortran_compile_flags INTERFACE "${FORTRAN_FLAGS_LIST}")

set (MachineTypes_ENABLED OFF)
if (${MachineTypes_FOUND})
Expand Down Expand Up @@ -99,7 +96,7 @@ endif (${Sumesh_FOUND})

set (LIMA_KERNEL_PUBLIC_FLAGS "${LIMA_CFLAGS}" LIMA_MT LIMA_USES_ATOMIC_API)
#set (LIMA_KERNEL_PRIVATE_FLAGS "${CMAKE_CXX_FLAGS}")
set (ALL_TARGETS Lima)
set (ALL_TARGETS Lima lima_fortran_compile_flags)
set_property (TARGET Lima PROPERTY VERSION ${LIMA_VERSION})
set_property (TARGET Lima PROPERTY SOVERSION ${LIMA_MAJOR_VERSION})
target_include_directories (Lima PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/public>$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
Expand All @@ -113,8 +110,9 @@ target_compile_definitions (Lima PUBLIC ${EXTERNAL_LIBS_FLAGS})
if (DISABLE_MLI_WARNING)
target_compile_definitions (Lima PRIVATE "DISABLE_MLI_WARNING")
endif (DISABLE_MLI_WARNING)
# Threads::Threads : A ne pas mettre en PRIVATE car "référence au symbole non défini «sem_getvalue@@GLIBC_2.2.5»"
target_link_libraries (Lima PUBLIC Threads::Threads)
# v 7.10.0 : Lima a au moins 1 appel direct à la lm (pow), et HDF145 en a aussi (ceil), mais HDF145 ne déclare pas de dépendance à la lm. Dans de rares cas ça manque au linker ...
# Donc la dépendance ci-dessous est à laisser.
target_link_libraries (Lima PUBLIC Threads::Threads m)


# Etre capable une fois installée de retrouver Lima*, ... :
Expand Down

0 comments on commit ab80057

Please sign in to comment.