Skip to content

Commit 3c16de4

Browse files
authored
Merge pull request #19 from jvdp1/cleaning
Cleaning
2 parents 84e1cdc + 33a9ff6 commit 3c16de4

6 files changed

Lines changed: 182 additions & 91 deletions

File tree

.github/workflows/CI.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
CMAKE_BUILD_PARALLEL_LEVEL: "2" # 2 cores on each GHA VM, enable parallel builds
7+
CTEST_OUTPUT_ON_FAILURE: "ON" # This way we don't need a flag to ctest
8+
CTEST_PARALLEL_LEVEL: "2"
9+
CTEST_TIME_TIMEOUT: "5" # some failures hang forever
10+
HOMEBREW_NO_ANALYTICS: "ON" # Make Homebrew installation a little quicker
11+
HOMEBREW_NO_AUTO_UPDATE: "ON"
12+
HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: "ON"
13+
HOMEBREW_NO_GITHUB_API: "ON"
14+
HOMEBREW_NO_INSTALL_CLEANUP: "ON"
15+
16+
jobs:
17+
Build:
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
# os: [ubuntu-latest, macos-12]
23+
os: [ubuntu-latest]
24+
toolchain:
25+
- {compiler: gcc, version: 10}
26+
- {compiler: gcc, version: 11}
27+
- {compiler: gcc, version: 12}
28+
- {compiler: gcc, version: 13}
29+
- {compiler: gcc, version: 14}
30+
- {compiler: intel, version: '2024.2'}
31+
- {compiler: intel, version: '2024.1'}
32+
- {compiler: intel-classic, version: '2021.9'}
33+
build: [cmake]
34+
env:
35+
BUILD_DIR: ${{ matrix.build == 'cmake' && 'build' || '.' }}
36+
MKL_PACKAGES: >-
37+
intel-oneapi-mkl
38+
intel-oneapi-mkl-devel
39+
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
- name: Set up Python 3.x
45+
uses: actions/setup-python@v5 # Use pip to install latest CMake, & FORD/Jin2For, etc.
46+
with:
47+
python-version: 3.x
48+
49+
- name: Install fypp
50+
run: pip install --upgrade fypp ninja
51+
52+
- name: Setup Fortran compiler
53+
uses: fortran-lang/setup-fortran@v1.6.1
54+
id: setup-fortran
55+
with:
56+
compiler: ${{ matrix.toolchain.compiler }}
57+
version: ${{ matrix.toolchain.version }}
58+
59+
# - name: Install Intel OneAPI MKL
60+
# run: |
61+
# sudo apt-get install ${MKL_PACKAGES}
62+
# source /opt/intel/oneapi/mkl/latest/env/vars.sh
63+
# printenv >> $GITHUB_ENV
64+
65+
- name: Configure with CMake
66+
if: ${{ contains(matrix.build, 'cmake') }}
67+
run: >-
68+
FFLAGS=-O3 cmake -Wdev
69+
-DCMAKE_BUILD_TYPE=Debug
70+
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
71+
-S . -B ${{ env.BUILD_DIR }}
72+
73+
- name: Build and compile
74+
if: ${{ contains(matrix.build, 'cmake') }}
75+
run: cmake --build ${{ env.BUILD_DIR }} --parallel
76+
77+
- name: catch build fail
78+
run: cmake --build ${{ env.BUILD_DIR }} --verbose --parallel 1
79+
if: ${{ failure() && contains(matrix.build, 'cmake') }}
80+
81+
- name: test
82+
if: ${{ contains(matrix.build, 'cmake') }}
83+
run: >-
84+
ctest
85+
--test-dir ${{ env.BUILD_DIR }}
86+
--parallel
87+
--output-on-failure
88+
--no-tests=error
89+
90+
- name: Install project
91+
if: ${{ contains(matrix.build, 'cmake') }}
92+
run: cmake --install ${{ env.BUILD_DIR }}

config/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,44 @@ install(
6363
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
6464
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
6565
)
66+
67+
# Preprocesses a list of files with given preprocessor and preprocessor options
68+
#
69+
# Args:
70+
# preproc [in]: Preprocessor program
71+
# preprocopts [in]: Preprocessor options
72+
# srcext [in]: File extension of the source files
73+
# trgext [in]: File extension of the target files
74+
# srcfiles [in]: List of the source files
75+
# trgfiles [out]: Contains the list of the preprocessed files on exit
76+
#
77+
function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles)
78+
79+
set(_trgfiles)
80+
foreach(srcfile IN LISTS srcfiles)
81+
string(REGEX REPLACE "\\.${srcext}$" ".${trgext}" trgfile ${srcfile})
82+
add_custom_command(
83+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
84+
COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
85+
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile})
86+
list(APPEND _trgfiles ${CMAKE_CURRENT_BINARY_DIR}/${trgfile})
87+
endforeach()
88+
set(${trgfiles} ${_trgfiles} PARENT_SCOPE)
89+
90+
endfunction()
91+
92+
# Preprocesses fortran files with fypp.
93+
#
94+
# It assumes that source files have the ".fypp" extension. Target files will be
95+
# created with the extension ".f90". The FYPP variable must contain the path to
96+
# the fypp-preprocessor.
97+
#
98+
# Args:
99+
# fyppopts [in]: Options to pass to fypp.
100+
# fyppfiles [in]: Files to be processed by fypp
101+
# f90files [out]: List of created f90 files on exit
102+
#
103+
function (fypp_f90 fyppopts fyppfiles f90files)
104+
preprocess("${FYPP}" "${fyppopts}" "fypp" "f90" "${fyppfiles}" _f90files)
105+
set(${f90files} ${_f90files} PARENT_SCOPE)
106+
endfunction()

src/CMakeLists.txt

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
16-
# Preprocesses a list of files with given preprocessor and preprocessor options
17-
#
18-
# Args:
19-
# preproc [in]: Preprocessor program
20-
# preprocopts [in]: Preprocessor options
21-
# srcext [in]: File extension of the source files
22-
# trgext [in]: File extension of the target files
23-
# srcfiles [in]: List of the source files
24-
# trgfiles [out]: Contains the list of the preprocessed files on exit
25-
#
26-
function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles)
27-
28-
set(_trgfiles)
29-
foreach(srcfile IN LISTS srcfiles)
30-
string(REGEX REPLACE "\\.${srcext}$" ".${trgext}" trgfile ${srcfile})
31-
add_custom_command(
32-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
33-
COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
34-
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile})
35-
list(APPEND _trgfiles ${CMAKE_CURRENT_BINARY_DIR}/${trgfile})
36-
endforeach()
37-
set(${trgfiles} ${_trgfiles} PARENT_SCOPE)
38-
39-
endfunction()
40-
41-
# Preprocesses fortran files with fypp.
42-
#
43-
# It assumes that source files have the ".fypp" extension. Target files will be
44-
# created with the extension ".f90". The FYPP variable must contain the path to
45-
# the fypp-preprocessor.
46-
#
47-
# Args:
48-
# fyppopts [in]: Options to pass to fypp.
49-
# fyppfiles [in]: Files to be processed by fypp
50-
# f90files [out]: List of created f90 files on exit
51-
#
52-
function (fypp_f90 fyppopts fyppfiles f90files)
53-
preprocess("${FYPP}" "${fyppopts}" "fypp" "f90" "${fyppfiles}" _f90files)
54-
set(${f90files} ${_f90files} PARENT_SCOPE)
55-
endfunction()
56-
5715
set(dir "${CMAKE_CURRENT_SOURCE_DIR}")
5816

5917
set(

src/modhash.fypp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ contains
6666
pos = 1
6767
do while (length > 3)
6868
#:if k[0] == 'r'
69-
a = a + transfer(k(pos), a)
70-
b = b + transfer(k(pos + 1), b)
71-
c = c + transfer(k(pos + 2), c)
69+
a = a + transfer(k(pos), a)
70+
b = b + transfer(k(pos + 1), b)
71+
c = c + transfer(k(pos + 2), c)
7272
#:else
73-
a = a + k(pos)
74-
b = b + k(pos + 1)
75-
c = c + k(pos + 2)
73+
a = a + k(pos)
74+
b = b + k(pos + 1)
75+
c = c + k(pos + 2)
7676
#:endif
7777
call mix(a, b, c)
7878
length = length - 3
@@ -82,27 +82,27 @@ contains
8282
select case (length)
8383
case (1)
8484
#:if k[0] == 'r'
85-
a = a + transfer(k(pos), a)
85+
a = a + transfer(k(pos), a)
8686
#:else
87-
a = a + k(pos)
87+
a = a + k(pos)
8888
#:endif
8989
case (2)
9090
#:if k[0] == 'r'
91-
a = a + transfer(k(pos), a)
92-
b = b + transfer(k(pos + 1), b)
91+
a = a + transfer(k(pos), a)
92+
b = b + transfer(k(pos + 1), b)
9393
#:else
94-
a = a + k(pos)
95-
b = b + k(pos + 1)
94+
a = a + k(pos)
95+
b = b + k(pos + 1)
9696
#:endif
9797
case (3)
9898
#:if k[0] == 'r'
99-
a = a + transfer(k(pos), a)
100-
b = b + transfer(k(pos + 1), b)
101-
c = c + transfer(k(pos + 2), c)
99+
a = a + transfer(k(pos), a)
100+
b = b + transfer(k(pos + 1), b)
101+
c = c + transfer(k(pos + 2), c)
102102
#:else
103-
a = a + k(pos)
104-
b = b + k(pos + 1)
105-
c = c + k(pos + 2)
103+
a = a + k(pos)
104+
b = b + k(pos + 1)
105+
c = c + k(pos + 2)
106106
#:endif
107107
end select
108108

src/modtable.fypp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,15 @@ contains
122122

123123
this%filled = 0
124124

125-
allocate (this%id(this%nel))
126-
this%id = 0
125+
allocate (this%id(this%nel), source=0_int32)
127126

128-
#:if k[0] == 'c'
129-
allocate (character(len=k) :: this%stored(this%nel))
130-
this%stored(:) = ''
131-
#:else
132-
allocate (this%stored(this%nel))
133-
this%stored = 0
134-
#:endif
127+
#:if k[0] == 'c'
128+
allocate (character(len=k) :: this%stored(this%nel))
129+
this%stored(:) = ''
130+
#:else
131+
allocate (this%stored(this%nel))
132+
this%stored = 0
133+
#:endif
135134

136135
end function
137136

@@ -363,24 +362,20 @@ contains
363362
if (io .ne. 0) error stop 'readtable: wrong io for nstorage'
364363

365364
!Initiate the table
366-
if (nfilled == 0_int32) then
367-
this%nel = default_nel
368-
else
369-
this%nel = next_power_of_2(int(1.3*nfilled, kind=int32))
370-
end if
365+
this%nel = next_power_of_2(int(1.3*nfilled, kind=int32))
371366
this%filled = 0
372367

373368
allocate (this%id(this%nel), source=0_int32)
374369

375-
#:if k[0] == 'c'
376-
allocate (character(len=nstorage) :: this%stored(this%nel))
377-
this%stored(:) = ''
378-
allocate (character(len=nstorage) :: nvalue)
379-
#:else
380-
allocate (this%stored(this%nel))
381-
this%stored = 0
382-
allocate (nvalue)
383-
#:endif
370+
#:if k[0] == 'c'
371+
allocate (character(len=nstorage) :: this%stored(this%nel))
372+
this%stored(:) = ''
373+
allocate (character(len=nstorage) :: nvalue)
374+
#:else
375+
allocate (this%stored(this%nel))
376+
this%stored = 0
377+
allocate (nvalue)
378+
#:endif
384379

385380
do i = 1, nfilled
386381
read (un, iostat=io) nvalue
@@ -404,8 +399,7 @@ contains
404399

405400
this%filled = 0
406401

407-
allocate (this%id(this%nel))
408-
this%id = 0
402+
allocate (this%id(this%nel), source=0_int32)
409403

410404
allocate (this%stored(k, this%nel))
411405
this%stored = 0
@@ -630,11 +624,7 @@ contains
630624
if (io .ne. 0) error stop 'readtable_arr: wrong io for nstorage'
631625

632626
!Initiate the table
633-
if (nfilled == 0_int32) then
634-
this%nel = 0_int32
635-
else
636-
this%nel = next_power_of_2(int(1.3*nfilled, kind=int32))
637-
end if
627+
this%nel = next_power_of_2(int(1.3*nfilled, kind=int32))
638628
this%filled = 0
639629

640630
allocate (this%id(this%nel), source=0_int32)

test/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ macro(ADDTEST name)
33
add_executable(test_${name} test_${name}.f90)
44
target_link_libraries(test_${name} "${PROJECT_NAME}")
55
add_test(NAME ${name}
6-
COMMAND $<TARGET_FILE:test_${name}> ${CMAKE_CURRENT_BINARY_DIR}
6+
COMMAND $<TARGET_FILE:test_${name}>
77
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
88
endmacro(ADDTEST)
99

10+
macro(ADDTESTFYPP name)
11+
fypp_f90("${fyppFlags}" "test_${name}.fypp" outname)
12+
add_executable(test_${name} ${outname})
13+
target_link_libraries(test_${name} "${PROJECT_NAME}")
14+
add_test(NAME ${name}
15+
COMMAND $<TARGET_FILE:test_${name}>
16+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
17+
endmacro(ADDTESTFYPP)
18+
1019
ADDTEST(hash)
1120
#ADDTEST(list)
1221
ADDTEST(table)
22+
ADDTESTFYPP(table_stream)

0 commit comments

Comments
 (0)