13 #include "sll_working_precision.h"
25 integer (c_int) function sll_f_compressbound_zfp(buf_in, n_doubles_in, prec) &
26 bind(c, name=
'zfp_maximum_size')
29 type (c_ptr),
value :: buf_in
30 integer (c_int),
value :: n_doubles_in
31 integer (c_int),
value :: prec
32 end function sll_f_compressbound_zfp
34 integer (c_int) function sll_f_deflate_zfp(buf_in, buf_out, n_doubles_in, n_bytes_out_max, prec) &
35 bind(c, name=
'zfp_compress_safe')
38 type (c_ptr),
value :: buf_in
39 type (c_ptr),
value :: buf_out
40 integer (c_int),
value :: n_doubles_in
41 integer (c_int),
value :: n_bytes_out_max
42 integer (c_int),
value :: prec
43 end function sll_f_deflate_zfp
45 integer (c_int) function sll_f_inflate_zfp(buf_in, buf_out, n_bytes_in, n_doubles_out_max, prec) &
46 bind(c, name=
'zfp_decompress_safe')
49 type (c_ptr),
value :: buf_in
50 type (c_ptr),
value :: buf_out
51 integer (c_int),
value :: n_bytes_in
52 integer (c_int),
value :: n_doubles_out_max
53 integer (c_int),
value :: prec
54 end function sll_f_inflate_zfp
66 character,
dimension(:),
pointer :: buffer => null()
69 integer :: n_bytes_deflated_total = 0
70 integer :: n_bytes_inflated_total = 0
71 integer,
dimension(:),
pointer :: n_bytes_deflated => null()
72 integer,
dimension(:),
pointer :: offset_deflated => null()
73 integer,
dimension(:),
pointer :: n_bytes_inflated => null()
74 integer,
dimension(:),
pointer :: offset_inflated => null()
89 sll_real64,
intent(in),
target :: buf(0:)
91 integer,
intent(in),
optional :: n_doubles, n_threads
93 integer :: n_omp_threads, omp_size, omp_rank
94 integer :: n_total, n_per_thread
95 integer :: n_offset_thread
96 integer :: n_bytes_comp_thread_max
98 character,
allocatable,
target :: thread_buf(:)
99 integer,
parameter :: word_size = 8
101 if (
present(n_doubles))
then
108 if (
present(n_threads))
then
109 n_omp_threads = n_threads
111 n_omp_threads = omp_get_max_threads()
125 omp_size = omp_get_num_threads()
126 omp_rank = omp_get_thread_num()
134 n_offset_thread = n_per_thread * omp_rank
135 if (omp_rank == omp_size-1)
then
136 n_per_thread = (n_total /
zfp_blocksize) - n_per_thread * omp_rank
142 comp%n_bytes_inflated(omp_rank) = word_size * n_per_thread
143 comp%offset_inflated(omp_rank) = word_size * n_offset_thread
145 n_bytes_comp_thread_max = sll_f_compressbound_zfp(c_loc(buf(n_offset_thread)), n_per_thread,
zfp_precision)
146 allocate(thread_buf(0:n_bytes_comp_thread_max-1))
148 comp%n_bytes_deflated(omp_rank) = sll_f_deflate_zfp(c_loc(buf(n_offset_thread)), c_loc(thread_buf), &
153 comp%n_bytes_deflated_total = sum(comp%n_bytes_deflated)
154 allocate(comp%buffer(0:comp%n_bytes_deflated_total-1))
155 comp%offset_deflated(0) = 0
157 comp%offset_deflated(i) = comp%offset_deflated(i-1) + comp%n_bytes_deflated(i-1)
163 off = comp%offset_deflated(omp_rank)
165 do i=0, comp%n_bytes_deflated(omp_rank)-1
166 comp%buffer(off + i) = thread_buf(i)
169 deallocate(thread_buf)
172 comp%n_bytes_inflated_total = word_size * n_total
181 sll_real64,
intent(inout),
target :: buf(0:)
183 integer,
intent(in),
optional :: n_threads
185 integer :: n_omp_threads, omp_size, omp_rank
186 integer :: i, off, n_el, ierr
187 integer,
parameter :: word_size = 8
190 if (
present(n_threads))
then
191 n_omp_threads = n_threads
193 n_omp_threads = omp_get_max_threads()
206 omp_size = omp_get_num_threads()
207 omp_rank = omp_get_thread_num()
214 do i=0,comp%n_slices-1
216 off = comp%offset_inflated(i)/word_size
217 n_el = comp%n_bytes_inflated(i)/word_size
218 ierr = sll_f_inflate_zfp(c_loc(comp%buffer(comp%offset_deflated(i))), c_loc(buf(off)), &
233 if (
associated(comp%buffer))
then
234 deallocate(comp%buffer);
nullify(comp%buffer)
236 if (
associated(comp%n_bytes_deflated))
then
237 deallocate(comp%n_bytes_deflated);
nullify(comp%n_bytes_deflated)
239 if (
associated(comp%offset_deflated))
then
240 deallocate(comp%offset_deflated);
nullify(comp%offset_deflated)
242 if (
associated(comp%n_bytes_inflated))
then
243 deallocate(comp%n_bytes_inflated);
nullify(comp%n_bytes_inflated)
245 if (
associated(comp%offset_inflated))
then
246 deallocate(comp%offset_inflated);
nullify(comp%offset_inflated)
249 comp%n_bytes_inflated_total = 0
250 comp%n_bytes_deflated_total = 0
256 integer,
intent(in) :: n_slices
257 allocate(comp%n_bytes_deflated(0:n_slices-1))
258 allocate(comp%offset_deflated(0:n_slices-1))
259 allocate(comp%n_bytes_inflated(0:n_slices-1))
260 allocate(comp%offset_inflated(0:n_slices-1))
261 comp%n_slices = n_slices
267 logical,
intent(in),
optional :: verbose
269 write(*,*)
"--- sll_m_compression ---------------------"
270 if ((
present(verbose)).and.(verbose))
then
271 write(*,*)
"n_slices =", comp%n_slices
273 write(*,*)
"n_bytes_inflated =", comp%n_bytes_inflated
274 write(*,*)
"offset_inflated =", comp%offset_inflated
275 write(*,*)
"n_bytes_deflated_total =", comp%n_bytes_deflated_total
276 write(*,*)
"n_bytes_deflated =", comp%n_bytes_deflated
277 write(*,*)
"offset_deflated =", comp%offset_deflated
280 if (comp%n_bytes_deflated_total > 0)
then
281 write(*,*)
"n_bytes_inflated_total =", comp%n_bytes_inflated_total
282 write(*,*)
"ratio =", &
283 real(comp%n_bytes_inflated_total)/
real(comp%n_bytes_deflated_total)
285 write(*,*)
"-------------------------------------------"
290 integer,
intent(in) :: prec
298 integer,
pointer :: array(:)
299 integer :: i, n_el, idx
301 n_el = 3 + 4 * comp%n_slices
302 allocate(array(0:n_el-1))
305 array(idx) = comp%n_slices
307 array(idx) = comp%n_bytes_deflated_total
309 array(idx) = comp%n_bytes_inflated_total
311 do i=0,comp%n_slices-1
312 array(idx) = comp%n_bytes_deflated(i)
315 do i=0,comp%n_slices-1
316 array(idx) = comp%offset_deflated(i)
319 do i=0,comp%n_slices-1
320 array(idx) = comp%n_bytes_inflated(i)
323 do i=0,comp%n_slices-1
324 array(idx) = comp%offset_inflated(i)
332 integer,
pointer :: array(:)
333 integer :: i, n_el, idx
335 comp%n_slices = array(idx)
337 comp%n_bytes_deflated_total = array(idx)
339 comp%n_bytes_inflated_total = array(idx)
342 do i=0,comp%n_slices-1
343 comp%n_bytes_deflated(i) = array(idx)
346 do i=0,comp%n_slices-1
347 comp%offset_deflated(i) = array(idx)
350 do i=0,comp%n_slices-1
351 comp%n_bytes_inflated(i) = array(idx)
354 do i=0,comp%n_slices-1
355 comp%offset_inflated(i) = array(idx)
Module providing an F90 interface to the ZFP compression library: http://computation....
subroutine allocate_compressed_buffer_index_arrays(comp, n_slices)
subroutine print_compression_information(comp, verbose)
integer function concatenate_index_arrays(comp, array)
allocate array, copy indices from comp into array, return
subroutine set_compression_precision(prec)
subroutine deallocate_compressed_buffer_obj(comp)
double precision function get_time()
subroutine decatenate_index_arrays(comp, array)
subroutine deflate_buffer_real64(buf, comp, n_doubles, n_threads)
compress buffer
subroutine inflate_buffer_real64(buf, comp, n_threads)
decompress buffer
integer, parameter zfp_blocksize
data structure to support threaded ZFP compression and decompression