Skip to content

Commit

Permalink
Merge branch 'release/0.6.1'
Browse files Browse the repository at this point in the history
* release/0.6.1:
  Version 0.6.1
  FCKIT-12 Implement array_view1d(multidimensional_logical_array, scalar_int) -> int_array1d
  FCKIT-11 Fix missing Cray flags for position independent code for fypp generated files
  • Loading branch information
wdeconinck committed Mar 6, 2019
2 parents c110192 + 02acb8f commit 9786322
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set( ${PROJECT_NAME}_VERSION_STR "0.6.0" )
set( ${PROJECT_NAME}_VERSION_STR "0.6.1" )
68 changes: 65 additions & 3 deletions cmake/fckit_preprocess_fypp.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

##############################################################################################
# fckit_target_append_fypp_args( output target )
# Purpose:
# From a target, assemble arguments to pass to fypp. These arguments are
# the include flags and compile definition flags.
# Arguments:
# output This argument will contain the flags as a list
# target The name of the target to process

function( fckit_target_append_fypp_args output target )
unset(_args)
if( CMAKE_VERSION VERSION_LESS 3.12 ) # Hopefully we can remove this soon
Expand Down Expand Up @@ -34,6 +43,24 @@ function( fckit_target_append_fypp_args output target )
endif()
endfunction()

##############################################################################################
# fckit_preprocess_fypp_sources( output
# [SOURCES file1 [file2]... ]
# [FYPP_ARGS arg1 [arg2]... ]
# [DEPENDS dep1 [dep2]... ] )
# Purpose:
# Preprocess source files with fypp
#
# Arguments:
# output Append preprocessed source files to this list
# [SOURCES file1 [file2]... ] List of source files to append
# [FYPP_ARGS arg1 [arg2]...] Arguments passed to fypp
# [DEPENDS dep1 [dep2]... ] Dependencies before processing files
#
# Notes:
# The include flags and compile flags of targets with the DEPENDS argument
# will be automatically deduced and added to the fypp command

function( fckit_preprocess_fypp_sources output )

set( options NO_LINE_NUMBERING )
Expand Down Expand Up @@ -101,6 +128,27 @@ function( fckit_preprocess_fypp_sources output )

endfunction()

##############################################################################################


##############################################################################################
# fckit_preprocess_fypp_sources( target
# [FYPP_ARGS arg1 [arg2]... ]
# [DEPENDS dep1 [dep2]... ] )
# Purpose:
# Preprocess source files in the target with the extensions
# {.fypp, .fypp.F90, .F90.fypp}
#
# Arguments:
# target Preprocess all files from this target
# [FYPP_ARGS arg1 [arg2]...] Arguments passed to fypp
# [DEPENDS dep1 [dep2]... ] Dependencies before processing files
#
# Notes:
# The include flags and compile flags of current target and targets
# within the DEPENDS argument will be automatically deduced
# and added to the fypp command

function( fckit_target_preprocess_fypp _PAR_TARGET )

set( options NO_LINE_NUMBERING )
Expand All @@ -126,7 +174,7 @@ function( fckit_target_preprocess_fypp _PAR_TARGET )
set( source_files_properties ${source} PROPERTIES HEADER_FILE_ONLY TRUE )
endforeach()

### BUG (tested upto 3.13.2)
### BUG WORKAROUND (tested upto 3.13.2)
# Even though source files to be preprocessed with final extension .F90 have just been
# declared as HEADER_FILE_ONLY, CMake still tries to compile these files.
# This does not happen for files ending with other extensions ( .fypp )
Expand All @@ -141,7 +189,7 @@ function( fckit_target_preprocess_fypp _PAR_TARGET )
set_property( TARGET ${_PAR_TARGET} PROPERTY SOURCES ${_target_sources} )
add_custom_target( ${_PAR_TARGET}_fypp SOURCES ${sources_to_be_preprocessed} )
endif()
### END BUG
### END BUG WORKAROUND



Expand All @@ -153,7 +201,7 @@ function( fckit_target_preprocess_fypp _PAR_TARGET )
endforeach()

fckit_target_append_fypp_args( args ${_PAR_TARGET} )

fckit_preprocess_fypp_sources( preprocessed_sources
SOURCES ${sources_to_be_preprocessed}
FYPP_ARGS ${_PAR_FYPP_ARGS} ${args}
Expand All @@ -162,6 +210,20 @@ function( fckit_target_preprocess_fypp _PAR_TARGET )

target_sources( ${_PAR_TARGET} PRIVATE ${preprocessed_sources} )

### BUG WORKAROUND for CMake < 3.12
# CMake seems to not add the "-fPIC -h PIC" flags for the Cray compiler when the target
# has the POSITION_INDEPENDENT_CODE property set, so add it manually
if( CMAKE_VERSION VERSION_LESS 3.12 )
get_property( _target_pic TARGET ${_PAR_TARGET} PROPERTY POSITION_INDEPENDENT_CODE )
if( _target_pic )
if( CMAKE_Fortran_COMPILER_ID MATCHES "Cray" )
foreach( _src ${preprocessed_sources} )
set_source_files_properties( ${_src} COMPILE_FLAGS "-h PIC" )
endforeach()
endif()
endif()
endif()
endif()
### END BUG WORKAROUND

endfunction()
93 changes: 89 additions & 4 deletions src/fckit/module/fckit_array.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module fckit_array_module
real(c_double), target :: zero_length_array_real64(0)
logical, target :: zero_length_array_logical(0)

INTERFACE array_view1d
interface array_view1d
module procedure array_view1d_int32_r0
module procedure array_view1d_int32_r1
module procedure array_view1d_int32_r2
Expand All @@ -54,10 +54,13 @@ module fckit_array_module
module procedure array_view1d_logical_r2
module procedure array_view1d_logical_r3
module procedure array_view1d_logical_r4

module procedure array_view1d_logical_r1_mold_int32
module procedure array_view1d_logical_r2_mold_int32
module procedure array_view1d_logical_r3_mold_int32
module procedure array_view1d_logical_r4_mold_int32
end interface

INTERFACE array_stride
interface array_stride
module procedure array_stride_int32_r1_dim
module procedure array_stride_int32_r2_dim
module procedure array_stride_int32_r3_dim
Expand All @@ -80,7 +83,7 @@ module fckit_array_module
module procedure array_stride_logical_r4_dim
end interface

INTERFACE array_strides
interface array_strides
module procedure array_stride_int32_r1
module procedure array_stride_int32_r2
module procedure array_stride_int32_r3
Expand All @@ -103,6 +106,7 @@ module fckit_array_module
module procedure array_stride_logical_r4
end interface


! =============================================================================
CONTAINS
! =============================================================================
Expand Down Expand Up @@ -532,6 +536,87 @@ function array_view1d_logical_r4(array) result( view )
endif
end function

! =============================================================================

function array_view1d_logical_r0_mold_int32(scalar,mold) result( view )
use, intrinsic :: iso_c_binding
logical, intent(in), target :: scalar
integer(c_int32_t), intent(in) :: mold
type(c_ptr) :: array_c_ptr
integer(c_int32_t), pointer :: view(:)
nullify(view)
array_c_ptr = c_loc_logical(scalar)
call c_f_pointer ( array_c_ptr , view , (/1/) )
end function

! =============================================================================

function array_view1d_logical_r1_mold_int32(array,mold) result( view )
use, intrinsic :: iso_c_binding
logical, intent(in), target :: array(:)
integer(c_int32_t), intent(in) :: mold
type(c_ptr) :: array_c_ptr
integer(c_int32_t), pointer :: view(:)
nullify(view)
if( size(array) > 0 ) then
array_c_ptr = c_loc_logical(array(1))
call c_f_pointer ( array_c_ptr , view , (/size(array)/) )
else
view => zero_length_array_int32
endif
end function

! =============================================================================

function array_view1d_logical_r2_mold_int32(array,mold) result( view )
use, intrinsic :: iso_c_binding
logical, intent(in), target :: array(:,:)
integer(c_int32_t), intent(in) :: mold
type(c_ptr) :: array_c_ptr
integer(c_int32_t), pointer :: view(:)
nullify(view)
if( size(array) > 0 ) then
array_c_ptr = c_loc_logical(array(1,1))
call c_f_pointer ( array_c_ptr , view , (/size(array)/) )
else
view => zero_length_array_int32
endif
end function

! =============================================================================

function array_view1d_logical_r3_mold_int32(array,mold) result( view )
use, intrinsic :: iso_c_binding
logical, intent(in), target :: array(:,:,:)
integer(c_int32_t), intent(in) :: mold
type(c_ptr) :: array_c_ptr
integer(c_int32_t), pointer :: view(:)
nullify(view)
if( size(array) > 0 ) then
array_c_ptr = c_loc_logical(array(1,1,1))
call c_f_pointer ( array_c_ptr , view , (/size(array)/) )
else
view => zero_length_array_int32
endif
end function

! =============================================================================

function array_view1d_logical_r4_mold_int32(array,mold) result( view )
use, intrinsic :: iso_c_binding
logical, intent(in), target :: array(:,:,:,:)
integer(c_int32_t), intent(in) :: mold
type(c_ptr) :: array_c_ptr
integer(c_int32_t), pointer :: view(:)
nullify(view)
if( size(array) > 0 ) then
array_c_ptr = c_loc_logical(array(1,1,1,1))
call c_f_pointer ( array_c_ptr , view , (/size(array)/) )
else
view => zero_length_array_int32
endif
end function

! =============================================================================
! stride interface

Expand Down

0 comments on commit 9786322

Please sign in to comment.