From 7faf27e3b9082225509411779fa95b9b3183359a Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Tue, 12 May 2020 14:51:37 -0300 Subject: [PATCH 1/6] PYTHON: Use the maximum used level instead of maxlev. This reduces the resolution and memory usage if parameter maxlev is actually larger than the maximu used level. Signed-off-by: Grzegorz Kowal --- python/amunpy.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/amunpy.py b/python/amunpy.py index 7c21985..caa6319 100644 --- a/python/amunpy.py +++ b/python/amunpy.py @@ -193,9 +193,6 @@ class AmunXML: rm = np.array([nx, ny]) bm = np.array([nc, nc]) - dm = rm[0:nd] * int(nc * 2**(ml - 1) / self.shrink) - arr = np.zeros(dm[:]) - dfile = op.join(self.path, 'metablock_fields.bin') if op.exists(dfile): mset = np.fromfile(dfile, dtype='int32') @@ -215,6 +212,10 @@ class AmunXML: for n in range(nm): level[mset[0,n]] = mset[ 1,n] coord[mset[0,n]] = mset[2:5,n] + ml = mset[1,:].max() + + dm = rm[0:nd] * int(nc * 2**(ml - 1) / self.shrink) + arr = np.zeros(dm[:]) for n in range(self.attributes['nprocs']): From ca3580e2ec1b016a62761a91e70f315aa3333adf Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Wed, 13 May 2020 06:47:38 -0300 Subject: [PATCH 2/6] IO: Fix wrong warning while reading from an XML+binary restart snapshot. If the forcing is off, the number of forcing modes is zero, but it is not the same as a wrong number of forcing modes stored in the restart file. Signed-off-by: Grzegorz Kowal --- sources/io.F90 | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sources/io.F90 b/sources/io.F90 index 6ffa4bc..79a70c6 100644 --- a/sources/io.F90 +++ b/sources/io.F90 @@ -1572,16 +1572,18 @@ module io ! check the number of forcing modes ! - if (lnmodes == nmodes .and. lnmodes > 0) then - write(fname,"(a,'forcing_coefficients.bin')") trim(dname) - open(newunit = lun, file = fname, form = 'unformatted', & - access = 'direct', recl = sizeof(fcoefs)) - read(lun, rec = 1) fcoefs - close(lun) - read(hforce(7:), fmt = "(1z16)") hash - if (hash /= xxh64_complex(size(fcoefs), fcoefs)) then - write(error_unit,"('[',a,']: ',a)") trim(loc) & - , "'" // trim(fname) // "' seems to be corrupted!" + if (lnmodes == nmodes) then + if (lnmodes > 0) then + write(fname,"(a,'forcing_coefficients.bin')") trim(dname) + open(newunit = lun, file = fname, form = 'unformatted', & + access = 'direct', recl = sizeof(fcoefs)) + read(lun, rec = 1) fcoefs + close(lun) + read(hforce(7:), fmt = "(1z16)") hash + if (hash /= xxh64_complex(size(fcoefs), fcoefs)) then + write(error_unit,"('[',a,']: ',a)") trim(loc) & + , "'" // trim(fname) // "' seems to be corrupted!" + end if end if else write(error_unit,"('[',a,']: ',a)") trim(loc) & From 97e572ec94978b1f110f7f8f2a4d8fced4a323be Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Wed, 13 May 2020 06:49:53 -0300 Subject: [PATCH 3/6] IO: Make sure bounds have the same domensions while stored and read. Signed-off-by: Grzegorz Kowal --- sources/io.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/io.F90 b/sources/io.F90 index 79a70c6..26a869e 100644 --- a/sources/io.F90 +++ b/sources/io.F90 @@ -2027,7 +2027,7 @@ module io ! prepare and store metablocks ! - allocate(fields(nm,14), children(nm,nc), bounds(nm,3,2), & + allocate(fields(nm,14), children(nm,nc), bounds(nm,NDIMS,2), & #if NDIMS == 3 faces(nm,NDIMS,ns,ns,ns), & edges(nm,NDIMS,ns,ns,ns), corners(nm,ns,ns,ns), & From 86c7f87365ae74b925fcc18fa744524b93220e68 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Wed, 13 May 2020 06:57:26 -0300 Subject: [PATCH 4/6] HASH: Fix hash calculation in xxh64_integer() for odd length vectors. If the input data has an odd number of elements, the last 4-byte element has to be padded by 4-byte structure of zeros. Signed-off-by: Grzegorz Kowal --- sources/hash.F90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sources/hash.F90 b/sources/hash.F90 index c5e5a24..57f5593 100644 --- a/sources/hash.F90 +++ b/sources/hash.F90 @@ -148,7 +148,8 @@ module hash end do if (remain == 1) then - hash = ieor(hash, data(offset) * prime1) + chk(1) = transfer((/ data(offset), 0 /), chk(1)) + hash = ieor(hash, chk(1) * prime1) hash = xxh64_rotl(hash, 23) hash = hash * prime2 + prime3 From e1e025017aa7a5e72b42fc2dcf4833274b37b1ca Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Wed, 13 May 2020 07:05:44 -0300 Subject: [PATCH 5/6] HASH: Rename argument data to input. Word DATA is reserved in Fortran. Rename this argument, just to avoid confusion. Signed-off-by: Grzegorz Kowal --- sources/hash.F90 | 52 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/sources/hash.F90 b/sources/hash.F90 index 57f5593..532beb0 100644 --- a/sources/hash.F90 +++ b/sources/hash.F90 @@ -77,19 +77,19 @@ module hash ! ! Arguments: ! -! n - the size of the input vector; -! data - the input vactor of integer values; +! n - the size of the input vector; +! input - the input vactor of integer values; ! !=============================================================================== ! - integer(kind=8) function xxh64_integer(n, data) result(hash) + integer(kind=8) function xxh64_integer(n, input) result(hash) implicit none ! subroutine arguments ! integer(kind=4) , intent(in) :: n - integer(kind=4), dimension(n), intent(in) :: data + integer(kind=4), dimension(n), intent(in) :: input ! local variables ! @@ -112,7 +112,7 @@ module hash lane(4) = seed - prime1 do while (remain >= 8) - chk(1:4) = transfer(data(offset:offset+7), chk) + chk(1:4) = transfer(input(offset:offset+7), chk) lane(1) = xxh64_round(lane(1), chk(1)) lane(2) = xxh64_round(lane(2), chk(2)) @@ -138,7 +138,7 @@ module hash hash = hash + int(4 * n, kind = 8) do while (remain >= 2) - chk(1) = transfer(data(offset:offset+1), chk(1)) + chk(1) = transfer(input(offset:offset+1), chk(1)) hash = ieor(hash, xxh64_round(0_8, chk(1))) hash = xxh64_rotl(hash, 27) hash = hash * prime1 + prime4 @@ -148,7 +148,7 @@ module hash end do if (remain == 1) then - chk(1) = transfer((/ data(offset), 0 /), chk(1)) + chk(1) = transfer((/ input(offset), 0 /), chk(1)) hash = ieor(hash, chk(1) * prime1) hash = xxh64_rotl(hash, 23) hash = hash * prime2 + prime3 @@ -174,19 +174,19 @@ module hash ! ! Arguments: ! -! n - the size of the input vector; -! data - the input vactor of real values; +! n - the size of the input vector; +! input - the input vactor of real values; ! !=============================================================================== ! - integer(kind=8) function xxh64_long(n, data) result(hash) + integer(kind=8) function xxh64_long(n, input) result(hash) implicit none ! subroutine arguments ! integer(kind=4) , intent(in) :: n - integer(kind=8), dimension(n), intent(in) :: data + integer(kind=8), dimension(n), intent(in) :: input ! local variables ! @@ -209,7 +209,7 @@ module hash lane(4) = seed - prime1 do while (remain >= 4) - chk(1:4) = transfer(data(offset:offset+3), chk) + chk(1:4) = transfer(input(offset:offset+3), chk) lane(1) = xxh64_round(lane(1), chk(1)) lane(2) = xxh64_round(lane(2), chk(2)) @@ -235,7 +235,7 @@ module hash hash = hash + int(8 * n, kind = 8) do while (remain >= 1) - hash = ieor(hash, xxh64_round(0_8, transfer(data(offset), 0_8))) + hash = ieor(hash, xxh64_round(0_8, transfer(input(offset), 0_8))) hash = xxh64_rotl(hash, 27) hash = hash * prime1 + prime4 @@ -260,19 +260,19 @@ module hash ! ! Arguments: ! -! n - the size of the input vector; -! data - the input vactor of real values; +! n - the size of the input vector; +! input - the input vactor of real values; ! !=============================================================================== ! - integer(kind=8) function xxh64_double(n, data) result(hash) + integer(kind=8) function xxh64_double(n, input) result(hash) implicit none ! subroutine arguments ! integer(kind=4) , intent(in) :: n - real(kind=8), dimension(n), intent(in) :: data + real(kind=8), dimension(n), intent(in) :: input ! local variables ! @@ -295,7 +295,7 @@ module hash lane(4) = seed - prime1 do while (remain >= 4) - chk(1:4) = transfer(data(offset:offset+3), chk) + chk(1:4) = transfer(input(offset:offset+3), chk) lane(1) = xxh64_round(lane(1), chk(1)) lane(2) = xxh64_round(lane(2), chk(2)) @@ -321,7 +321,7 @@ module hash hash = hash + int(8 * n, kind = 8) do while (remain >= 1) - hash = ieor(hash, xxh64_round(0_8, transfer(data(offset), 0_8))) + hash = ieor(hash, xxh64_round(0_8, transfer(input(offset), 0_8))) hash = xxh64_rotl(hash, 27) hash = hash * prime1 + prime4 @@ -346,19 +346,19 @@ module hash ! ! Arguments: ! -! n - the size of the input vector; -! data - the input vactor of real values; +! n - the size of the input vector; +! input - the input vactor of real values; ! !=============================================================================== ! - integer(kind=8) function xxh64_complex(n, data) result(hash) + integer(kind=8) function xxh64_complex(n, input) result(hash) implicit none ! subroutine arguments ! integer(kind=4) , intent(in) :: n - complex(kind=8), dimension(n), intent(in) :: data + complex(kind=8), dimension(n), intent(in) :: input ! local variables ! @@ -381,7 +381,7 @@ module hash lane(4) = seed - prime1 do while (remain >= 2) - chk(1:4) = transfer(data(offset:offset+1), chk) + chk(1:4) = transfer(input(offset:offset+1), chk) lane(1) = xxh64_round(lane(1), chk(1)) lane(2) = xxh64_round(lane(2), chk(2)) @@ -407,10 +407,10 @@ module hash hash = hash + int(16 * n, kind = 8) if (remain == 1) then - hash = ieor(hash, xxh64_round(0_8, transfer(dreal(data(offset)), 0_8))) + hash = ieor(hash, xxh64_round(0_8, transfer(dreal(input(offset)), 0_8))) hash = xxh64_rotl(hash, 27) hash = hash * prime1 + prime4 - hash = ieor(hash, xxh64_round(0_8, transfer(dimag(data(offset)), 0_8))) + hash = ieor(hash, xxh64_round(0_8, transfer(dimag(input(offset)), 0_8))) hash = xxh64_rotl(hash, 27) hash = hash * prime1 + prime4 From 3dbbd0b8b129e1b4a59c9e883e5b86d2cc4f65ab Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Wed, 13 May 2020 08:32:27 -0300 Subject: [PATCH 6/6] HASH: Change kind of local variables. Local variables remain and offset cannot be larger than the size of input array, so they can be 4-byte integers. Signed-off-by: Grzegorz Kowal --- sources/hash.F90 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sources/hash.F90 b/sources/hash.F90 index 532beb0..b3c63e1 100644 --- a/sources/hash.F90 +++ b/sources/hash.F90 @@ -93,7 +93,7 @@ module hash ! local variables ! - integer(kind=8) :: remain, offset + integer(kind=4) :: remain, offset ! local arrays ! @@ -135,7 +135,7 @@ module hash hash = seed + prime5 end if - hash = hash + int(4 * n, kind = 8) + hash = hash + 4_8 * n do while (remain >= 2) chk(1) = transfer(input(offset:offset+1), chk(1)) @@ -190,7 +190,7 @@ module hash ! local variables ! - integer(kind=8) :: remain, offset + integer(kind=4) :: remain, offset ! local arrays ! @@ -232,7 +232,7 @@ module hash hash = seed + prime5 end if - hash = hash + int(8 * n, kind = 8) + hash = hash + 8_8 * n do while (remain >= 1) hash = ieor(hash, xxh64_round(0_8, transfer(input(offset), 0_8))) @@ -276,7 +276,7 @@ module hash ! local variables ! - integer(kind=8) :: remain, offset + integer(kind=4) :: remain, offset ! local arrays ! @@ -318,7 +318,7 @@ module hash hash = seed + prime5 end if - hash = hash + int(8 * n, kind = 8) + hash = hash + 8_8 * n do while (remain >= 1) hash = ieor(hash, xxh64_round(0_8, transfer(input(offset), 0_8))) @@ -362,7 +362,7 @@ module hash ! local variables ! - integer(kind=8) :: remain, offset + integer(kind=4) :: remain, offset ! local arrays ! @@ -404,7 +404,7 @@ module hash hash = seed + prime5 end if - hash = hash + int(16 * n, kind = 8) + hash = hash + 16_8 * n if (remain == 1) then hash = ieor(hash, xxh64_round(0_8, transfer(dreal(input(offset)), 0_8)))