Skip to content
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

Add support for Flang (Classic) compiler #1538

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion modules/nwtc-library/src/NWTC_Base.f90
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ MODULE NWTC_Base

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) !< The address of procedure ProcName. (RETURN value from GetProcAddress or dlsym) [initialized to Null for pack/unpack]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this ProcAddr isn't initialized, does it cause issues with restart capabilities? I wonder if the uninitialized value becomes a problem when we pack/unpack the array like the comment (from a LONG time ago) mentions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that that it would be better to have it initialized. I'll see if it will accept initialization to another value. Unfortunately this compiler thinks that C_NULL_FUNPTR isn't valid in this context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it can be wrapped in a preprocessor directive to be safe? Otherwise, we might need to look at all the time ProcAddr is used and nullify it after the object is created.

I recall adding a safety in the DLLTypeUnPack to enforce that these variables are nullified after unpacking if no DLL is used. 39d37e6
But I don't know if such init are needed elsewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a way to fix this in the latest commit by creating an array of null function pointers.


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