Skip to content

Commit 225f678

Browse files
committed
fortran, ci template
1 parent b04ffc7 commit 225f678

18 files changed

+169
-243
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 132
3+
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/

CMakeLists.txt

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,51 @@
11
cmake_minimum_required (VERSION 3.7)
2+
if(NOT CMAKE_BUILD_TYPE)
3+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Debug or Release")
4+
endif()
25
project(spectrum C CXX Fortran)
36
enable_testing()
47

5-
option(USE_MKL "use Intel MKL")
68
# we build separate libraries for real and complex to avoid polymorphic performance hits and complexities.
79
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules/)
810

9-
include(cmake/math.cmake)
1011
# *** DO NOT use -ffast-math *** it screws up the signaling between modules!!
1112
include(cmake/compilers.cmake)
1213

1314
add_compile_options(${FLAGS})
1415

15-
add_library(subspace SHARED filters.f90 covariance.f90 subspace.f90 signals.f90 perf.f90)
16-
if(f2008)
16+
find_package(LAPACK REQUIRED)
17+
18+
add_library(subspace filters.f90 covariance.f90 subspace.f90 signals.f90 perf.f90)
19+
if(f2018)
1720
target_sources(subspace PRIVATE comm.f90)
1821
else()
1922
target_sources(subspace PRIVATE comm_legacy.f90)
2023
endif()
21-
target_link_libraries(subspace PRIVATE ${FLIBS})
2224
target_compile_options(subspace PRIVATE ${FFLAGS})
25+
target_link_libraries(subspace PRIVATE ${LAPACK_LIBRARIES})
2326

2427
#------ test program: Fortran Complex Double Precision ----------
2528
add_executable(fespritcmpl RunSubspace.f90)
26-
target_link_libraries(fespritcmpl subspace ${FLIBS})
29+
target_link_libraries(fespritcmpl subspace)
2730
target_compile_options(fespritcmpl PRIVATE ${FFLAGS})
2831
add_test(NAME FortranComplexEsprit COMMAND fespritcmpl)
32+
set_tests_properties(FortranComplexEsprit PROPERTIES TIMEOUT 15)
2933
#------ test program: Fortran Real Single Precision -------------
3034
add_executable(fespritreal RunSubspace_realsp.f90)
31-
target_link_libraries(fespritreal subspace ${FLIBS})
35+
target_link_libraries(fespritreal subspace)
3236
target_compile_options(fespritreal PRIVATE ${FFLAGS})
3337
add_test(NAME FortranRealEsprit COMMAND fespritreal)
38+
set_tests_properties(FortranRealEsprit PROPERTIES TIMEOUT 15)
3439
#------ test program: C++ Real Single ---------------------------
3540
add_executable(cppesprit cppSubspace.cpp)
36-
target_link_libraries(cppesprit subspace ${CLIBS} ${CXXLIBS})
41+
target_link_libraries(cppesprit subspace)
3742
set_target_properties(cppesprit PROPERTIES CXX_STANDARD 11)
3843
add_test(NAME C++Esprit COMMAND cppesprit)
44+
set_tests_properties(C++Esprit PROPERTIES TIMEOUT 15)
3945
#------ test program: C Real Single -----------------------------
4046
add_executable(cesprit cSubspace.c)
41-
target_link_libraries(cesprit subspace ${CLIBS})
47+
target_link_libraries(cesprit subspace)
4248
set_target_properties(cesprit PROPERTIES C_STANDARD 11)
4349
add_test(NAME C-Esprit COMMAND cesprit)
44-
45-
46-
#-------------------------------------------------------------------------------
47-
48-
# ------ mkl manual working -- NOTE: -Wl,--no-as-need prevents runtime errors
49-
# gfortran -fdefault-integer-8 -g -I$MKLROOT/include/intel64/ilp64 -m64 -I$MKLROOT/include ../comm.f90 ../perf.f90 ../covariance.f90 ../subspace.f90 ../signals.f90 ../RunSubspace.f90 -L$MKLROOT/lib/intel64 -lmkl_blas95_ilp64 -lmkl_lapack95_ilp64 -lmkl_gf_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl && ./a.out
50-
51-
# OpenBLAS gfortran Complex64 WORKING
52-
# gfortran ../comm.f90 ../perf.f90 ../covariance.f90 ../subspace.f90 ../signals.f90 ../RunSubspace.f90 -lblas -llapack -lpthread -lm && ./a.out
53-
#
54-
# MKL gfortran Real32 WORKING
55-
# gfortran ../comm.f90 ../perf.f90 ../covariance_realsp.f90 ../subspace_realsp.f90 ../signals_realsp.f90 ../filters.f90 ../RunSubspace_realsp.f90 -lmkl_blas95_lp64 -lmkl_lapack95_lp64 -lmkl_gf_lp64 -lmkl_sequential -lmkl_core -ldl -lm && ./a.out
56-
#
57-
# not working 8-byte integer Parameter 13 SGESVD
58-
# ifort -i8 -I${F95ROOT}/include/intel64/ilp64 -I${MKLROOT}/include ../comm.f90 ../perf.f90 ../covariance_realsp.f90 ../subspace_realsp.f90 ../signals_realsp.f90 ../filters.f90 ../RunSubspace_realsp.f90 ${MKLROOT}/lib/intel64/libmkl_blas95_ilp64.a ${MKLROOT}/lib/intel64/libmkl_lapack95_ilp64.a -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_gf_ilp64 -lmkl_sequential -lmkl_core -lpthread -ldl -lm && ./a.out
59-
#
60-
#
61-
# ifort -I${F95ROOT}/include/intel64/lp64 -I${MKLROOT}/include ../comm.f90 ../perf.f90 ../covariance_realsp.f90 ../subspace_realsp.f90 ../signals_realsp.f90 ../filters.f90 ../RunSubspace_realsp.f90 ${MKLROOT}/lib/intel64/libmkl_blas95_lp64.a ${MKLROOT}/lib/intel64/libmkl_lapack95_lp64.a -L${MKLROOT}/lib/intel64 -lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread -ldl -lm && ./a.out
62-
63-
64-
#---- intel compiler
65-
# note that you can compile first with GCC then link with ICPC (kind of silly
66-
# since main computation is done in Fortran, but just to show the concept)
67-
# cmake ..
68-
# make
69-
# icpc ../cppSubspace.cpp libsubspace_real.a -lgfortran -llapack
70-
71-
# using Intel Compiler requires linking:
72-
# svml intlc ifcore imf
73-
# that do not work for GCC
74-
#
75-
# cd bin
76-
# rm -r *
77-
# FC=ifort CC=icc CXX=icpc cmake ..
78-
# make
79-
# icpc ../cppSubspace.cpp libsubspace_real.a -lifcore -lsvml -lintlc -limf
80-
50+
set_tests_properties(C-Esprit PROPERTIES TIMEOUT 15)
8151

File renamed without changes.

RunSubspace.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
program test_subspace
1+
22
use,intrinsic:: iso_fortran_env, only: int64, stderr=>error_unit
33
use,intrinsic:: iso_c_binding, only: c_int
4-
use comm, only: dp, random_init, err
4+
use comm, only: dp, rand_init
55
use perf, only: sysclock2ms
66
use subspace, only: esprit
77
use signals,only: signoise
@@ -22,7 +22,7 @@ program test_subspace
2222
integer :: narg
2323
character(16) :: arg
2424

25-
call random_init()
25+
call rand_init(.false., .false.)
2626
!----------- parse command line ------------------
2727
M = Ns / 4_c_int
2828
narg = command_argument_count()
@@ -49,14 +49,14 @@ program test_subspace
4949
!--- checking system numerics --------------
5050
if (storage_size(fs) /= 64) then
5151
write(stderr,*) 'expected 64-bit real but you have: ', storage_size(fs)
52-
call err('')
52+
error stop
5353
endif
5454
if (storage_size(x(1)) /= 128) then
5555
write(stderr,*) 'expected 128-bit complex but you have: ', storage_size(x(1))
56-
call err('')
56+
error stop
5757
endif
5858

59-
!------ simulate noisy signal ------------
59+
!------ simulate noisy signal ------------
6060
call signoise(fs,f0,snr,Ns,&
6161
x)
6262
!------ estimate frequency of sinusoid in noise --------
@@ -66,7 +66,7 @@ program test_subspace
6666
call system_clock(toc)
6767

6868
! -- assert <0.1% error ---------
69-
if (abs(tones(1)-f0) > 0.001*f0) call err('excessive estimation error')
69+
if (abs(tones(1)-f0) > 0.001*f0) error stop 'excessive estimation error'
7070

7171
print '(A,100F10.2)', 'estimated tone freq [Hz]: ',tones
7272
print '(A,100F5.1)', 'with sigma: ',sigma
@@ -75,5 +75,5 @@ program test_subspace
7575
print *,'OK'
7676

7777
! deallocate(x,tones,sigma) ! this is automatic going out of scope
78-
end program test_subspace
78+
end program
7979

RunSubspace_realsp.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
program test_subspace
1+
22
use,intrinsic:: iso_fortran_env, only: int64, stderr=>error_unit
33
use,intrinsic:: iso_c_binding, only: c_int,c_bool
4-
use comm, only: sp, random_init, err
4+
use comm, only: sp, rand_init
55
use perf, only: sysclock2ms
66
use subspace, only: esprit
77
use signals, only: signoise
@@ -19,7 +19,7 @@ program test_subspace
1919
integer(c_int) :: M,Nb
2020
integer:: fstat
2121
logical(c_bool) :: filtok
22-
22+
2323

2424
real(sp),allocatable :: x(:), b(:), y(:)
2525
real(sp),allocatable :: tones(:),sigma(:)
@@ -28,7 +28,7 @@ program test_subspace
2828
integer :: narg,u
2929
character(16) :: arg
3030

31-
call random_init()
31+
call rand_init(.false., .false.)
3232
!----------- parse command line ------------------
3333
M = Ns / 2_c_int
3434
narg = command_argument_count()
@@ -55,9 +55,9 @@ program test_subspace
5555
!--- checking system numerics --------------
5656
if (storage_size(fs) /= 32) then
5757
write(stderr,*) 'expected 32-bit real but you have : ', storage_size(fs)
58-
call err('')
58+
error stop
5959
endif
60-
!------ simulate noisy signal ------------
60+
!------ simulate noisy signal ------------
6161
call signoise(fs, f0, snr, Ns, x) ! output "X"
6262
!------ filter noisy signal --------------
6363
! read coefficients 'b'
@@ -89,7 +89,7 @@ program test_subspace
8989
call system_clock(toc)
9090

9191
! -- assert <0.1% error ---------
92-
if (abs(tones(1)-f0) > 0.001*f0) call err('excessive frequency estimation error')
92+
if (abs(tones(1)-f0) > 0.001*f0) error stop 'excessive frequency estimation error'
9393

9494
print '(A,100F10.2)', 'estimated tone freq [Hz]: ',tones
9595
print '(A,100F5.1)', 'with sigma: ',sigma
@@ -98,5 +98,5 @@ program test_subspace
9898
print *,'OK'
9999

100100
! deallocate(x,y,tones,sigma) ! this is automatic going out of scope
101-
end program test_subspace
101+
end program
102102

cmake/compilers.cmake

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
if(CMAKE_BUILD_TYPE STREQUAL Debug)
2-
add_compile_options(-g -O0)
3-
else()
4-
add_compile_options(-O3)
5-
endif()
6-
7-
81
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel)
92
list(APPEND CLIBS ifcoremt imf svml intlc)
103
if(CMAKE_BUILD_TYPE STREQUAL Debug)
114
list(APPEND FFLAGS -check all -fpe0 -warn -traceback -debug extended)
125
endif()
6+
7+
if(WIN32)
8+
list(APPEND FFLAGS /heap-arrays)
9+
else()
10+
list(APPEND FFLAGS -heap-arrays)
11+
endif()
1312
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
1413
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 8)
1514
list(APPEND FFLAGS -std=f2018)
@@ -21,12 +20,10 @@ elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU)
2120
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL PGI)
2221

2322
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Flang)
24-
# list(APPEND CXXLIBS) # Not needed: stdc++ c++abi Don't use: -stdlib=libc++
25-
list(APPEND FFLAGS -Mallocatable=03)
26-
list(APPEND FLIBS -static-flang-libs)
23+
2724
endif()
2825

2926

3027
include(CheckFortranSourceCompiles)
31-
check_fortran_source_compiles("program es; error stop; end" f2008
28+
check_fortran_source_compiles("call random_init(.false., .false.); end" f2018
3229
SRC_EXT f90)

cmake/math.cmake

Lines changed: 0 additions & 28 deletions
This file was deleted.

comm.f90

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
module comm
2-
use, intrinsic :: iso_c_binding, only: sp=>C_FLOAT, dp=>C_DOUBLE, int64=>C_LONG_LONG, sizeof=>c_sizeof
3-
use, intrinsic :: iso_fortran_env, only: stderr=>error_unit
4-
implicit none
5-
6-
complex(dp),parameter :: J=(0._dp, 1._dp)
7-
real(dp),parameter :: pi = 4._dp*atan(1._dp)
8-
logical :: debug = .false.
2+
use, intrinsic :: iso_c_binding, only: sp=>C_FLOAT, dp=>C_DOUBLE, int64=>C_LONG_LONG, sizeof=>c_sizeof
3+
implicit none
4+
public
5+
6+
complex(dp),parameter :: J=(0._dp, 1._dp)
7+
real(dp),parameter :: pi = 4._dp*atan(1._dp)
8+
logical :: debug = .false.
99

1010
contains
1111

12-
subroutine random_init()
13-
integer :: i, n, clock
14-
integer, allocatable :: seed(:)
12+
subroutine rand_init(repeatable, image_distinct)
13+
logical, intent(in) :: repeatable, image_distinct
1514

16-
call random_seed(size=n)
17-
allocate(seed(n))
18-
call system_clock(count=clock)
19-
seed = clock + 37 * [ (i - 1, i = 1, n) ]
20-
call random_seed(put=seed)
21-
end subroutine
15+
call random_init(repeatable, image_distinct)
16+
end subroutine rand_init
2217

23-
subroutine err(msg)
24-
character(*), intent(in) :: msg
25-
write(stderr,*) msg
26-
error stop
27-
end subroutine err
2818

2919
end module comm

comm_legacy.f90

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
module comm
2-
use, intrinsic :: iso_c_binding, only: sp=>C_FLOAT, dp=>C_DOUBLE, int64=>C_LONG_LONG, sizeof=>c_sizeof
3-
use, intrinsic :: iso_fortran_env, only: stderr=>error_unit
4-
implicit none
5-
6-
complex(dp),parameter :: J=(0._dp, 1._dp)
7-
real(dp),parameter :: pi = 4._dp*atan(1._dp)
2+
use, intrinsic :: iso_c_binding, only: sp=>C_FLOAT, dp=>C_DOUBLE, int64=>C_LONG_LONG, sizeof=>c_sizeof
3+
implicit none
4+
5+
complex(dp),parameter :: J=(0._dp, 1._dp)
6+
real(dp),parameter :: pi = 4._dp*atan(1._dp)
7+
logical :: debug = .false.
88

99
contains
1010

11-
subroutine random_init()
12-
integer :: i, n, clock
13-
integer, allocatable :: seed(:)
11+
subroutine rand_init(repeatable, image_distinct)
12+
logical, intent(in), optional :: repeatable, image_distinct
13+
integer :: i, n, clock
14+
integer, allocatable :: seed(:)
1415

15-
call random_seed(size=n)
16-
allocate(seed(n))
17-
call system_clock(count=clock)
18-
seed = clock + 37 * [ (i - 1, i = 1, n) ]
19-
call random_seed(put=seed)
20-
end subroutine
16+
call random_seed(size=n)
17+
allocate(seed(n))
18+
call system_clock(count=clock)
19+
seed = clock + 37 * [ (i - 1, i = 1, n) ]
20+
call random_seed(put=seed)
21+
end subroutine rand_init
2122

22-
subroutine err(msg)
23-
character(*), intent(in) :: msg
24-
write(stderr,*) msg
25-
stop -1
26-
end subroutine err
2723

2824
end module comm

covariance.f90

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module covariance
2-
use, intrinsic:: iso_c_binding, only: c_int
3-
use comm,only: sp, dp
4-
!use perf, only : sysclock2ms
5-
Implicit none
6-
7-
interface autocov
8-
procedure autocov_r, autocov_c
9-
end interface autocov
10-
11-
private
12-
13-
public :: autocov, autocov_r, autocov_c ! latter two for f2py
2+
use, intrinsic:: iso_c_binding, only: c_int
3+
use comm,only: sp, dp
4+
!use perf, only : sysclock2ms
5+
Implicit none
6+
7+
interface autocov
8+
procedure autocov_r, autocov_c
9+
end interface autocov
10+
11+
private
12+
13+
public :: autocov, autocov_r, autocov_c ! latter two for f2py
1414

1515
contains
1616

0 commit comments

Comments
 (0)