Skip to content

Commit

Permalink
Merge pull request #4 from peverwhee/sima-history
Browse files Browse the repository at this point in the history
Initial commit for working SIMA history
  • Loading branch information
peverwhee authored Oct 22, 2024
2 parents 2ef104e + f03b89e commit f59357e
Show file tree
Hide file tree
Showing 13 changed files with 1,245 additions and 216 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: code-coverage

on:
push:
branch: sima-history
workflow_dispatch:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
gcc:
runs-on: ubuntu-latest
steps:
- name: Checkout history
uses: actions/checkout@v4

- name: Build pFUnit
run: |
git clone --depth 1 --branch v4.10.0 https://github.com/Goddard-Fortran-Ecosystem/pFUnit.git
cd pFUnit
cmake -B./build -S.
cd build
make install
- name: Build history
run: |
cmake \
-DCMAKE_PREFIX_PATH=/home/runner/work/history_output/history_output/pFUnit/build/installed \
-DHISTORY_ENABLE_CODE_COVERAGE=ON \
-B./build \
-S.
cd build
make
- name: Run tests
run: |
cd build && ctest -V --output-on-failure --output-junit test_results.xml
- name: Upload unit test results
uses: actions/upload-artifact@v4
with:
name: unit-test-results
path: build/test_results.xml

- name: Setup GCov
run: |
python3 -m venv venv
source venv/bin/activate
pip3 install gcovr
- name: Run Gcov
run: |
source venv/bin/activate
cd build
gcovr -r .. --filter '\.\./src' --html history_code_coverage.html --txt
- name: Upload code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-results
path: build/history_code_coverage.html

27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.21)

project(History-Output VERSION 0.0.1 LANGUAGES Fortran)

set(CMAKE_Fortran_FLAGS "-O0 --coverage")
if(NOT History-Output_IS_TOP_LEVEL)
message(WARNING "History-Output is not integrated into the CMake build of any top level "
"project yet and this CMake is for testing purposes only. "
"Making a change to this project's CMake will not impact the build of "
"a parent project at this time.")
endif()

option(HISTORY_ENABLE_TESTS "Run pFUnit unit tests" OFF)
option(HISTORY_ENABLE_CODE_COVERAGE "Run code coverage tool" OFF)

if(HISTORY_ENABLE_CODE_COVERAGE)
add_compile_options(-O0 --coverage)
add_link_options(-lgcov)
endif()

set(DCMAKE_BUILD_TYPE Debug)
add_subdirectory(src)

if(HISTORY_ENABLE_TESTS OR HISTORY_ENABLE_CODE_COVERAGE)
enable_testing()
add_subdirectory(test)
endif()
14 changes: 14 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(HISTORY_SOURCES
hist_api.F90
hist_buffer.F90
hist_field.F90
)

add_library(history ${HISTORY_SOURCES})

target_compile_options(history PRIVATE -ffree-line-length-none)

add_subdirectory(util)
add_subdirectory(hash)

target_include_directories(history PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
6 changes: 6 additions & 0 deletions src/hash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(HISTORY_HASH_SOURCES
hist_hash_table.F90
hist_hashable.F90
)

target_sources(history PRIVATE ${HISTORY_HASH_SOURCES})
41 changes: 31 additions & 10 deletions src/hash/hist_hash_table.F90
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module hist_hash_table
class(hist_hashable_t), pointer :: entry_value => NULL()
type(table_entry_t), pointer :: next => NULL()
contains
final :: finalize_table_entry
procedure :: finalize_table_entry
end type table_entry_t

type, public :: hist_hash_table_t
Expand All @@ -117,7 +117,7 @@ module hist_hash_table
integer, private :: overflow_size = -1
integer, private :: key_offset = gen_hash_key_offset
type(table_entry_t), private, allocatable :: primary_table(:)
! Statistics
! Statistics
integer, private :: num_keys = 0
integer, private :: num_key_collisions = 0
integer, private :: max_collision = 0
Expand All @@ -126,6 +126,7 @@ module hist_hash_table
procedure :: key_hash => hash_table_key_hash
procedure :: add_hash_key => hash_table_add_hash_key
procedure :: table_value => hash_table_table_value
procedure :: deallocate_table => hash_table_deallocate_table
end type hist_hash_table_t

!! Private interfaces
Expand Down Expand Up @@ -159,13 +160,13 @@ end subroutine clear_optstring

!#######################################################################

subroutine finalize_table_entry(te)
type(table_entry_t) :: te
subroutine finalize_table_entry(this)
class(table_entry_t), intent(inout) :: this

nullify(te%entry_value) ! We do not own the memory
if (associated(te%next)) then
deallocate(te%next) ! This should invoke finalize recursively
nullify(te%next)
nullify(this%entry_value) ! We do not own the memory
if (associated(this%next)) then
deallocate(this%next) ! This should invoke finalize recursively
nullify(this%next)
end if

end subroutine finalize_table_entry
Expand All @@ -181,10 +182,11 @@ subroutine hash_table_initialize_table(this, tbl_size, key_off)

! Clear this table so it can be initialized
if (allocated(this%primary_table)) then
deallocate(this%primary_table)
call this%deallocate_table()
end if
! Avoid too-large tables
this%table_size = ishft(1, MIN(tbl_size, bit_size(1) - 2))
this%table_size = ishft(1, MIN(tbl_size, 14))

allocate(this%primary_table(this%table_size))
if (present(key_off)) then
this%key_offset = key_off
Expand All @@ -193,6 +195,25 @@ end subroutine hash_table_initialize_table

!#######################################################################

subroutine hash_table_deallocate_table(this)
! Deallocate the hash table (if present)
! Dummy argument
class(hist_hash_table_t) :: this

! Local variable
integer :: entry_index

if (allocated(this%primary_table)) then
do entry_index = 1, size(this%primary_table)
call this%primary_table(entry_index)%finalize_table_entry()
end do
deallocate(this%primary_table)
end if

end subroutine hash_table_deallocate_table

!#######################################################################

integer function hash_table_key_hash(this, string, errmsg) result(hash_key)
!
!-----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit f59357e

Please sign in to comment.