Skip to content

Commit 570abf9

Browse files
authored
Merge pull request #6 from jvdp1/myhash2
Proposition: changes to hash function tests
2 parents 1c3a707 + 9d32d06 commit 570abf9

30 files changed

+443
-230
lines changed

.github/workflows/CI.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
build: make
3232
env:
3333
FC: gfortran-${{ matrix.gcc_v }}
34+
CC: gcc-${{ matrix.gcc_v }}
35+
CXX: g++-${{ matrix.gcc_v }}
3436
GCC_V: ${{ matrix.gcc_v }}
3537
BUILD_DIR: ${{ matrix.build == 'cmake' && 'build' || '.' }}
3638

@@ -50,17 +52,18 @@ jobs:
5052
- name: Install fypp
5153
run: pip install --upgrade fypp
5254

53-
- name: Install GFortran Linux
55+
- name: Install GCC compilers Linux
5456
if: contains( matrix.os, 'ubuntu')
5557
run: |
5658
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
5759
sudo apt-get update
58-
sudo apt-get install -y gcc-${GCC_V} gfortran-${GCC_V}
60+
sudo apt-get install -y gcc-${GCC_V} g++-${GCC_V} gfortran-${GCC_V}
5961
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
6062
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
63+
--slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_V} \
6164
--slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_V}
6265
63-
- name: Install GFortran macOS
66+
- name: Install GCC compilers macOS
6467
if: contains( matrix.os, 'macos')
6568
run: |
6669
brew install gcc@${GCC_V} || brew upgrade gcc@${GCC_V} || true
@@ -107,12 +110,16 @@ jobs:
107110
matrix:
108111
os: [ubuntu-latest, macos-latest]
109112
fc: [ifort]
113+
cc: [icc]
114+
cxx: [icpc]
110115
env:
111116
MACOS_HPCKIT_URL: >-
112117
https://registrationcenter-download.intel.com/akdlm/irc_nas/17398/m_HPCKit_p_2021.1.0.2681_offline.dmg
113118
MACOS_FORTRAN_COMPONENTS: >-
114119
intel.oneapi.mac.ifort-compiler
115120
FC: ${{ matrix.fc }}
121+
CC: ${{ matrix.cc }}
122+
CXX: ${{ matrix.cxx }}
116123

117124
steps:
118125
- name: Checkout code
@@ -154,6 +161,7 @@ jobs:
154161
if: contains(matrix.os, 'ubuntu')
155162
run: |
156163
sudo apt-get install intel-oneapi-compiler-fortran
164+
sudo apt-get install intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic
157165
158166
- name: Install Intel oneAPI compiler (OSX)
159167
if: contains(matrix.os, 'macos') && steps.cache-install.outputs.cache-hit != 'true'

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
4242
add_compile_options(-std=f2018)
4343
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
4444
if(WIN32)
45-
add_compile_options(/warn:declarations,general,usage,interfaces,unused)
46-
add_compile_options(/stand:f18)
45+
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:/warn:declarations,general,usage,interfaces,unused>")
46+
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:/stand:f18>")
4747
else()
48-
add_compile_options(-warn declarations,general,usage,interfaces,unused)
49-
add_compile_options(-stand f18)
48+
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-warn declarations,general,usage,interfaces,unused>")
49+
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-stand f18>")
5050
endif()
5151
endif()
5252

ci/fpm-deployment.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ include=(
2929
prune=(
3030
"$destdir/test/test_always_fail.f90"
3131
"$destdir/test/test_always_skip.f90"
32+
"$destdir/test/test_hash_functions.f90"
3233
"$destdir/src/common.f90"
3334
"$destdir/src/f18estop.f90"
3435
)

src/stdlib_32_bit_nmhashes.fypp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ submodule(stdlib_32_bit_hash_codes) stdlib_32_bit_nmhashes
6262
integer(int32), parameter :: nmh_m2_v(0:31) = nmh_m2
6363
integer(int32), parameter :: nmh_m3_v(0:31) = nmh_m3
6464

65-
integer(int16), parameter :: nmh_m3_16(2) = transfer( nmh_m3, 0_int16, 2 )
66-
6765
logical, parameter :: nmh_short32_without_seed2=.false.
6866
logical, parameter :: nmh_short32_with_seed2=.true.
6967

@@ -126,24 +124,20 @@ contains
126124
integer(int32), parameter :: m3 = int(z'E9139917', int32)
127125

128126
integer(int16) :: vx16(2)
129-
integer(int16), parameter :: &
130-
m116(2) = transfer( m1, 0_int16, 2 ), &
131-
m216(2) = transfer( m2, 0_int16, 2 ), &
132-
m316(2) = transfer( m3, 0_int16, 2 )
133127

134128
vx32 = x
135129
vx32 = ieor( vx32, ieor( ishft( vx32, -12 ), ishft( vx32, -6 ) ) )
136130
vx16 = transfer( vx32, 0_int16, 2 )
137-
vx16 = vx16 * m116
131+
vx16 = vx16 * transfer( m1, 0_int16, 2 )
138132
vx32 = transfer( vx16, 0_int32 )
139133
vx32 = ieor( vx32, ieor( ishft( vx32, 11 ), ishft( vx32, -19 ) ) )
140134
vx16 = transfer( vx32, 0_int16, 2 )
141-
vx16 = vx16 * m216
135+
vx16 = vx16 * transfer( m2, 0_int16, 2 )
142136
vx32 = transfer( vx16, 0_int32 )
143137
vx32 = ieor( vx32, seed )
144138
vx32 = ieor( vx32, ieor( ishft( vx32, -15 ), ishft( vx32, -9 ) ) )
145139
vx16 = transfer( vx32, 0_int16, 2 )
146-
vx16 = vx16 * m316
140+
vx16 = vx16 * transfer( m3, 0_int16, 2 )
147141
vx32 = transfer( vx16, 0_int32 )
148142
vx32 = ieor( vx32, ieor( ishft(vx32, 16), ishft(vx32, -11) ) )
149143

@@ -157,15 +151,23 @@ contains
157151

158152
integer(int32) :: xu32(0:3), yu32(0:3)
159153
integer(int16) :: xu16(0:1)
160-
integer(int16), parameter :: &
161-
nmh_m1_16(0:1) = transfer( nmh_m1, 0_int16, 2 ), &
162-
nmh_m2_16(0:1) = transfer( nmh_m2, 0_int16, 2 ), &
163-
nmh_m3_16(0:1) = transfer( nmh_m3, 0_int16, 2 )
154+
! Due to an issue with Intel OneAPI ifort 2021 (see
155+
! https://community.intel.com/t5/Intel-Fortran-Compiler/Intrinsic-transfer-with-a-provided-size-un-expected-behavior/m-p/1343313#M158733
156+
! ), it is not possible to define the following variables as a parameter.
157+
! integer(int16), parameter :: &
158+
! nmh_m1_16(0:1) = transfer( nmh_m1, 0_int16, 2 ), &
159+
! nmh_m2_16(0:1) = transfer( nmh_m2, 0_int16, 2 ), &
160+
! nmh_m3_16(0:1) = transfer( nmh_m3, 0_int16, 2 )
161+
integer(int16) :: nmh_m1_16(0:1), nmh_m2_16(0:1), nmh_m3_16(0:1)
164162
integer(int32) :: s1
165163
integer(int64) :: length
166164
integer(int32) :: length32(0:1)
167165
integer(int64) :: i, j, r
168166

167+
nmh_m1_16(0:1) = transfer( nmh_m1, 0_int16, 2 )
168+
nmh_m2_16(0:1) = transfer( nmh_m2, 0_int16, 2 )
169+
nmh_m3_16(0:1) = transfer( nmh_m3, 0_int16, 2 )
170+
169171
! base mixer: [f0d9649b 5 -13 29a7935d -9 11 55d35831 -20 -10 ] =
170172
! 0.93495901789135362
171173

@@ -382,10 +384,17 @@ contains
382384
integer(int16) :: u16(0:1)
383385
integer(int32), parameter:: m1 = int(z'CCE5196D', int32)
384386
integer(int32), parameter:: m2 = int(z'464BE229', int32)
385-
integer(int16), parameter:: m1_16(0:1) = transfer(m1, 0_int16, 2)
386-
integer(int16), parameter:: m2_16(0:1) = transfer(m2, 0_int16, 2)
387+
! Due to an issue with Intel OneAPI ifort 2021 (see
388+
! https://community.intel.com/t5/Intel-Fortran-Compiler/Intrinsic-transfer-with-a-provided-size-un-expected-behavior/m-p/1343313#M158733
389+
! ), it is not possible to define the following variables as a parameter.
390+
!integer(int16), parameter:: m1_16(0:1) = transfer(m1, 0_int16, 2)
391+
!integer(int16), parameter:: m2_16(0:1) = transfer(m2, 0_int16, 2)
392+
integer(int16) :: m1_16(0:1), m2_16(0:1)
387393
! [-21 -8 cce5196d 12 -7 464be229 -21 -8] = 3.2267098842182733
388394

395+
m1_16(0:1) = transfer(m1, 0_int16, 2)
396+
m2_16(0:1) = transfer(m2, 0_int16, 2)
397+
389398
u32 = x
390399
u32 = ieor( u32, ieor( ishft( u32, -8 ), ishft( u32, -21 ) ) )
391400
u16 = transfer( u32, 0_int16, 2 )

src/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ list(
1818
add_subdirectory(ascii)
1919
add_subdirectory(bitsets)
2020
add_subdirectory(hash_functions)
21+
add_subdirectory(hash_functions_perf)
2122
add_subdirectory(io)
2223
add_subdirectory(linalg)
2324
add_subdirectory(logger)

src/tests/Makefile.manual

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ testdrive.F90:
1414
all test clean::
1515
$(MAKE) -f Makefile.manual --directory=ascii $@
1616
$(MAKE) -f Makefile.manual --directory=bitsets $@
17+
$(MAKE) -f Makefile.manual --directory=hash_functions_perf $@
1718
$(MAKE) -f Makefile.manual --directory=hash_functions $@
1819
$(MAKE) -f Makefile.manual --directory=io $@
1920
$(MAKE) -f Makefile.manual --directory=logger $@
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1-
ADDTEST(32_bit_hash_performance)
2-
ADDTEST(64_bit_hash_performance)
1+
#ADDTEST(hash_functions)
2+
3+
set(SRC
4+
nmhash_scalar.c
5+
pengyhash.c
6+
SpookyV2.cpp
7+
SpookyV2Test.cpp
8+
waterhash.c
9+
generate_hash_arrays.cpp
10+
)
11+
12+
enable_language(CXX)
13+
enable_language(C)
14+
15+
add_library(libc_hash ${SRC})
16+
17+
set(CMAKE_FORTRAN_LINK_EXECUTABLE "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
18+
19+
add_executable(test_hash_functions test_hash_functions.f90)
20+
target_link_libraries(test_hash_functions "${PROJECT_NAME}" "test-drive::test-drive" "libc_hash")
21+
add_test(NAME hash_functions
22+
COMMAND $<TARGET_FILE:test_hash_functions> ${CMAKE_CURRENT_BINARY_DIR}
23+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
24+
25+
set_target_properties(test_hash_functions PROPERTIES LINKER_LANGUAGE FORTRAN)

src/tests/hash_functions/Makefile.manual

100755100644
Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1-
PROGS_SRC = test_64_bit_hash_performance.f90 test_32_bit_hash_performance.f90
1+
CC ?= gcc
2+
CXX ?= g++
3+
4+
CPPFLAGS += -I. -I../.. -I..
5+
LDFLAGS += -L../.. -L.. -lstdlib-testing -lstdlib
6+
7+
PROGS = test_hash_functions
8+
TESTPROGS = $(PROGS:=TEST)
9+
10+
all: $(PROGS)
11+
12+
test: $(TESTPROGS)
13+
14+
$(TESTPROGS):
15+
./$(@:TEST=)
16+
17+
test_hash_functions: test_hash_functions.f90 generate_hash_arrays.o libc_hash.a
18+
$(FC) $(FFLAGS) $(CPPFLAGS) -L. -o $@ $^ $(LDFLAGS) -lc_hash -lstdc++
19+
20+
generate_hash_arrays.o: generate_hash_arrays.cpp libc_hash.a
21+
$(CXX) $(CXXFLAGS) -c generate_hash_arrays.cpp -o generate_hash_arrays.o
22+
23+
libc_hash.a: SpookyV2.o SpookyV2Test.o pengyhash.o nmhash_scalar.o waterhash.o
24+
ar rcs libc_hash.a SpookyV2.o SpookyV2Test.o pengyhash.o \
25+
nmhash_scalar.o waterhash.o
26+
27+
pengyhash.o: pengyhash.c pengyhash.h
28+
$(CC) $(CFLAGS) $(CPPFLAGS) -c pengyhash.c -o pengyhash.o
29+
30+
waterhash.o: waterhash.c waterhash.h
31+
$(CC) $(CFLAGS) $(CPPFLAGS) -c waterhash.c -o waterhash.o
32+
33+
SpookyV2.o: SpookyV2.cpp SpookyV2.h
34+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c SpookyV2.cpp -o SpookyV2.o
35+
36+
SpookyV2Test.o: SpookyV2Test.cpp SpookyV2.h
37+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c SpookyV2Test.cpp -o SpookyV2Test.o
38+
39+
nmhash_scalar.o: nmhash_scalar.c nmhash_scalar.h
40+
$(CC) $(CFLAGS) $(CPPFLAGS) -c nmhash_scalar.c -o nmhash_scalar.o
41+
42+
clean:
43+
rm nmhash_scalar.o SpookyV2Test.o SpookyV2.o waterhash.o pengyhash.o \
44+
libc_hash.a generate_hash_arrays.o $(PROGS) *.*mod\
45+
*.bin
46+
247

3-
include ../Makefile.manual.test.mk

src/tests/hash_functions/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The validation directory contains code to validate the Fortran hash functions against the original C/C++ codes. It consists of one executable `test_hash_functions` that:
2+
3+
* creates a file containing 2048 random 8 bit integers using the subroutine
4+
`generate_key_array`.
5+
6+
* reads the file generated by the subroutine `generate_key_array` and uses its contents to generate 2049 hashes for each C/C++ hash algorithm and outputs files containing the hashes.
7+
8+
* reads the file generated by the subroutine `generate_key_array` and uses its contents to generate 2049 hashes for each Fortran hash algorithm and compares the result with the corresponding outputs of C/C++ hash algorithms.
File renamed without changes.

0 commit comments

Comments
 (0)