ROMS
Loading...
Searching...
No Matches
get_hash_mod Module Reference

Functions/Subroutines

subroutine, public get_hash (a, asize, hash, lreduce)
 
subroutine, private bitsum (a, asize, hash, lreduce)
 

Function/Subroutine Documentation

◆ bitsum()

subroutine, private get_hash_mod::bitsum ( real(r8), dimension(:), intent(in) a,
integer, intent(in) asize,
integer(i8b) hash,
logical, intent(in), optional lreduce )
private

Definition at line 169 of file get_hash.F.

170!***********************************************************************
171! !
172! Computes the checksum of a 1D floating-point by casting each value !
173! to an integer to faciliate the invariant order of the sum in tiled !
174! parallel applications. A real number can be represented with a set !
175! 64-bit integers (Hallberg and Adcroft, 2014). !
176! !
177! Reference: !
178! !
179! Hallberg, R. and A. Adcroft, 2014: An order-invariant real-to- !
180! integer conversion sum, Parallel Computing, 40, 140-143, !
181! doi:10.1016/j.parco.2014.04.007. !
182! !
183!***********************************************************************
184!
185! Imported variable declarations.
186!
187 logical, intent(in), optional :: Lreduce
188!
189 integer, intent(in) :: Asize
190
191 integer(i8b) :: hash
192!
193 real(r8), intent(in) :: A(:)
194!
195! Local variable declarations.
196!
197 integer, parameter :: Ak = kind(a)
198 integer :: i, j
199!
200 integer(i8b) :: Ac, Asum
201#if defined DISTRIBUTE && (defined JEDI || defined PIO_LIB)
202 integer(i8b) :: ibuffer(1)
203!
204 character (len=3) :: op_handle(1)
205#endif
206!
207!-----------------------------------------------------------------------
208! Compute checksum by counting bit-by-bit and summing.
209!-----------------------------------------------------------------------
210!
211! Here, the "POPCNT" function counts the number of set bits in a
212! machine instruction. For example, for two 8-bit words operated
213! with XOR, we get
214!
215! 00100110
216! 01100000
217! ----------
218! 01000110
219!
220! POPCNT(01000110) = 3 'counts the number of bits set to 1'
221!
222! The POPCNT is available in all modern Fortran compilers and CPU
223! architectures.
224!
225 asum=0_i8b
226 DO i=1,asize
227 ac=popcnt(transfer(abs(a(i)), 1_ak))
228 asum=asum+ac
229 END DO
230 hash=asum
231
232#if defined DISTRIBUTE && (defined JEDI || defined PIO_LIB)
233!
234! If PIO library data processing, sum across all processes. Recall that
235! one or several PETs are reading and or writing data, so we need a
236! global reduction of the checksum, which is order invariant for parallel
237! tiles. The integer arithmetic has no truncation errors. Notice that
238! such reduction is not required in I/0 processed by the master node
239! and Lreduce=.FALSE in such cases.
240!
241 IF (PRESENT(lreduce)) THEN
242 IF (lreduce) THEN
243 ibuffer(1)=asum
244 op_handle(1)='SUM'
245 CALL mp_reduce (1, 1, 1, ibuffer, op_handle)
246 hash=ibuffer(1)
247 END IF
248 END IF
249#endif
250!
251 RETURN

Referenced by get_hash().

Here is the caller graph for this function:

◆ get_hash()

subroutine, public get_hash_mod::get_hash ( real(r8), dimension(:), intent(in) a,
integer, intent(in) asize,
integer(i8b), intent(out) hash,
logical, intent(in), optional lreduce )

Definition at line 71 of file get_hash.F.

72!***********************************************************************
73!
74!
75! Imported variable declarations.
76!
77 logical, intent(in), optional :: Lreduce
78!
79 integer, intent(in) :: Asize
80 integer(i8b), intent(out) :: hash
81!
82 real(r8), intent(in) :: A(:)
83!
84! Local variable declarations.
85!
86 logical, save :: first = .true.
87!
88!-----------------------------------------------------------------------
89! Compute checksum for the requested floating point vector.
90!-----------------------------------------------------------------------
91!
92 hash=0_i8b
93!
94 SELECT CASE (uppercase(trim(hashmethod)))
95#ifdef ADLER32_CHECKSUM
96 CASE ('ADLER32')
97 CALL adler32 (a, asize, hash)
98#endif
99 CASE ('BITSUM')
100 CALL bitsum (a, asize, hash, lreduce)
101#ifdef CRC32_CHECKSUM
102 CASE ('CRC32')
103 IF (first) THEN
104 first=.false.
105 CALL crc32_ini ! compute CRC-32 look table
106 END IF
107 CALL crc32 (a, asize, hash)
108#endif
109 CASE DEFAULT
110 WRITE (stdout,10) trim(hashmethod)
111 exit_flag=5
112 END SELECT
113!
114 10 FORMAT (/,' GET_HASH - Illegal checksum method: ',a)
115!
116 RETURN

References bitsum(), mod_scalars::exit_flag, mod_scalars::hashmethod, mod_iounits::stdout, and strings_mod::uppercase().

Referenced by get_ngfld_nf90(), get_ngfld_pio(), get_ngfldr_nf90(), get_ngfldr_pio(), nf_fread2d_mod::nf_fread2d::nf90_fread2d(), nf_fread2d_bry_mod::nf_fread2d_bry::nf90_fread2d_bry(), nf_fread3d_mod::nf_fread3d::nf90_fread3d(), nf_fread3d_bry_mod::nf_fread3d_bry::nf90_fread3d_bry(), nf_fread4d_mod::nf_fread4d::nf90_fread4d(), nf_fread2d_mod::nf_fread2d::pio_fread2d(), nf_fread2d_bry_mod::nf_fread2d_bry::pio_fread2d_bry(), nf_fread3d_mod::nf_fread3d::pio_fread3d(), nf_fread3d_bry_mod::nf_fread3d_bry::pio_fread3d_bry(), nf_fread4d_mod::nf_fread4d::pio_fread4d(), stats_mod::stats_2dfld(), stats_mod::stats_3dfld(), and stats_mod::stats_4dfld().

Here is the call graph for this function:
Here is the caller graph for this function: