Skip to content

Commit

Permalink
Merge pull request #1538 from deslaughter/f/flang
Browse files Browse the repository at this point in the history
Add support for Flang (Classic) compiler
  • Loading branch information
andrew-platt authored Apr 20, 2023
2 parents 004a1fa + 55eb00c commit e083682
Show file tree
Hide file tree
Showing 10 changed files with 537 additions and 26 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ elseif (USE_LOCAL_STATIC_LAPACK)
)
set(LAPACK_LIBRARIES ${BLAS_LIB_PATH} ${LAPACK_LIB_PATH} CACHE STRING "LAPACK library" FORCE)
install(FILES ${LAPACK_LIBRARIES} DESTINATION ${CMAKE_SOURCE_DIR}/install/lib)
message(STATUS "Using LAPACK libraries: ${LAPACK_LIBRARIES}")
else()
message(FATAL_ERROR "Unable to find BLAS and LAPACK")
endif()
message(STATUS "Using LAPACK libraries: ${LAPACK_LIBRARIES}")

########################################################################
# Build rules for OpenFAST Registry
Expand Down Expand Up @@ -214,16 +214,19 @@ if(BUILD_TESTING)
include(CTest)

# Find python
cmake_policy(SET CMP0094 NEW) # Search for python by LOCATION
find_package (Python COMPONENTS Interpreter)
if(NOT ${Python_FOUND})
if(NOT ${Python_Interpreter_FOUND})
message(FATAL_ERROR "CMake cannot find a Python interpreter in your path. Python is required to run OpenFAST tests." )
endif()

# regression tests
add_subdirectory(reg_tests)

# unit tests
add_subdirectory(unit_tests)
if(NOT (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Flang"))
add_subdirectory(unit_tests)
endif()
endif()

option(BUILD_DOCUMENTATION "Build documentation." OFF)
Expand Down
28 changes: 26 additions & 2 deletions cmake/OpenfastFortranOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ macro(set_fast_fortran)

# Abort if we do not have gfortran or Intel Fortran Compiler.
if (NOT (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU" OR
${CMAKE_Fortran_COMPILER_ID} MATCHES "^Intel"))
message(FATAL_ERROR "OpenFAST requires either GFortran or Intel Fortran Compiler. Compiler detected by CMake: ${FCNAME}.")
${CMAKE_Fortran_COMPILER_ID} MATCHES "^Intel" OR
${CMAKE_Fortran_COMPILER_ID} STREQUAL "Flang"))
message(FATAL_ERROR "OpenFAST requires GFortran, Intel, or Flang Compiler. Compiler detected by CMake: ${FCNAME}.")
endif()

# Verify proper compiler versions are available
Expand All @@ -70,6 +71,8 @@ macro(set_fast_fortran)
set_fast_gfortran()
elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES "^Intel")
set_fast_intel_fortran()
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Flang")
set_fast_flang()
endif()

# If double precision option enabled, set preprocessor define to use
Expand Down Expand Up @@ -238,3 +241,24 @@ macro(set_fast_intel_fortran_windows)

check_f2008_features()
endmacro(set_fast_intel_fortran_windows)

#
# set_fast_flang - Customizations for GNU Fortran compiler
#
macro(set_fast_flang)

set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-backslash -cpp -fPIC")

# Deal with Double/Single precision
if (DOUBLE_PRECISION)
add_definitions(-DOPENFAST_DOUBLE_PRECISION)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8")
endif (DOUBLE_PRECISION)

# OPENMP
if (OPENMP)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fopenmp")
endif()

check_f2008_features()
endmacro(set_fast_flang)
26 changes: 13 additions & 13 deletions modules/aerodyn14/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ install(TARGETS aerodyn14lib aerodyn14lib_obj
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

set(DWM_SOURCES
src/DWM_driver_wind_farm_mod.f90
src/DWM_driver_wind_farm_sub.f90
src/DWM_driver_wind_farm.f90
)

add_executable(dwm_driver_wind_farm ${DWM_SOURCES})
target_link_libraries(dwm_driver_wind_farm aerodyn14lib versioninfolib)

install(TARGETS dwm_driver_wind_farm
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# set(DWM_SOURCES
# src/DWM_driver_wind_farm_mod.f90
# src/DWM_driver_wind_farm_sub.f90
# src/DWM_driver_wind_farm.f90
# )

# add_executable(dwm_driver_wind_farm ${DWM_SOURCES})
# target_link_libraries(dwm_driver_wind_farm aerodyn14lib versioninfolib)

# install(TARGETS dwm_driver_wind_farm
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION lib
# ARCHIVE DESTINATION lib)
4 changes: 2 additions & 2 deletions modules/aerodyn14/src/AeroSubs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1264,13 +1264,13 @@ SUBROUTINE READFL(InitInp, P, x, xd, z, m, y, ErrStat, ErrMess )

IF ( p%PMOMENT ) THEN

READ( NUNIT,*,END=150 ) m%AirFoil%AL(NFOILID,I), &
READ( NUNIT,*,END=150,ERR=150 ) m%AirFoil%AL(NFOILID,I), &
(m%AirFoil%CL(NFOILID,I,IPHI), m%AirFoil%CD(NFOILID,I,IPHI), &
m%AirFoil%CM(NFOILID,I,IPHI), IPHI = 1, p%AirFoil%NTables(NFOILID))

ELSE

READ( NUNIT,*,END=150 ) m%AirFoil%AL(NFOILID,I), &
READ( NUNIT,*,END=150,ERR=150 ) m%AirFoil%AL(NFOILID,I), &
(m%AirFoil%CL(NFOILID,I,IPHI), m%AirFoil%CD(NFOILID,I,IPHI), &
IPHI = 1, p%AirFoil%NTables(NFOILID))

Expand Down
7 changes: 6 additions & 1 deletion modules/beamdyn/src/BeamDyn_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,10 @@ SUBROUTINE BD_ReadBladeFile(BldFile,BladeInputFileData,UnEc,ErrStat,ErrMsg)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )

DO i=1,BladeInputFileData%station_total
if (i > 1) then
CALL ReadCom(UnIn,BldFile,'blank line after mass matrix',ErrStat2,ErrMsg2,UnEc)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
end if

CALL ReadVar(UnIn,BldFile,BladeInputFileData%station_eta(i),'station_eta','Station '//trim(num2lstr(i))//' Eta',ErrStat2,ErrMsg2,UnEc)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
Expand All @@ -1122,7 +1126,8 @@ SUBROUTINE BD_ReadBladeFile(BldFile,BladeInputFileData,UnEc,ErrStat,ErrMsg)
return
end if
BladeInputFileData%stiff0(:,:,i) = temp66

CALL ReadCom(UnIn,BldFile,'blank line after stiffness matrix',ErrStat2,ErrMsg2,UnEc)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
DO j=1,6
CALL ReadAry(UnIn,BldFile,temp66(j,:),6,'mass_matrix','Blade C/S mass matrix',ErrStat2,ErrMsg2,UnEc)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
Expand Down
4 changes: 4 additions & 0 deletions modules/nwtc-library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ elseif (${CMAKE_Fortran_COMPILER_ID} MATCHES "^Intel")
set(NWTC_SYS_FILE src/SysIVF.f90)
set(NWTC_SYS_FILE_MATLAB src/SysMatlabWindows.f90)
endif (APPLE OR UNIX)
elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Flang")
if(APPLE OR UNIX)
set(NWTC_SYS_FILE src/SysFlangLinux.f90)
endif()
endif ()

if (NWTC_SYS_FILE)
Expand Down
5 changes: 3 additions & 2 deletions modules/nwtc-library/src/NWTC_Base.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ MODULE NWTC_Base

INTEGER(IntKi), PARAMETER :: NWTC_MAX_DLL_PROC = 5 !< maximum number of procedures that can be dynamically loaded from a DLL (see DLL_Type nwtc_base::dll_type)

TYPE(C_FUNPTR), PARAMETER :: NULL_PROC_ADDR(NWTC_MAX_DLL_PROC) = C_NULL_FUNPTR !< this is a hack so the Flang compiler will initialize ProcAddr to C_NULL_FUNPTR in DLL_Type (remove if no longer needed)

!> Type definition for dynamically loaded libraries:
!! Note that changes here may need to be reflected in DLLTypePack() (nwtc_io::dlltypepack) DLLTypeUnPack() (nwtc_io::dlltypeunpack),
!! and the FAST Registry executable.

TYPE DLL_Type

INTEGER(C_INTPTR_T) :: FileAddr = INT(0,C_INTPTR_T) !< The address of file FileName. (RETURN value from LoadLibrary ) [Windows]
TYPE(C_PTR) :: FileAddrX = C_NULL_PTR !< The address of file FileName. (RETURN value from dlopen ) [Linux]
TYPE(C_FUNPTR) :: ProcAddr(NWTC_MAX_DLL_PROC) = C_NULL_FUNPTR !< The address of procedure ProcName. (RETURN value from GetProcAddress or dlsym) [initialized to Null for pack/unpack]
TYPE(C_FUNPTR) :: ProcAddr(NWTC_MAX_DLL_PROC) = NULL_PROC_ADDR !< The address of procedure ProcName. (RETURN value from GetProcAddress or dlsym) [initialized to Null for pack/unpack]

CHARACTER(1024) :: FileName !< The name of the DLL file including the full path to the current working directory.
CHARACTER(1024) :: ProcName(NWTC_MAX_DLL_PROC) = "" !< The name of the procedure in the DLL that will be called.
Expand Down
Loading

0 comments on commit e083682

Please sign in to comment.