PrincetonUniversity / athena

Athena++ radiation GRMHD code and adaptive mesh refinement (AMR) framework
https://www.athena-astro.app
BSD 3-Clause "New" or "Revised" License
226 stars 122 forks source link

Fixes athena_read's unnecessarily large memory allocation #587

Closed dgagnier closed 5 months ago

dgagnier commented 5 months ago

athena_read allocates unnecessarily large amount of memory for each quantity, rendering file reading unnecessarily slow or even impossible. (see #586)

Prerequisite checklist

Description

                    if s > 1:
                        if nx1 > 1:
                            block_data = np.repeat(block_data, s, axis=2)
                        if nx2 > 1:
                            block_data = np.repeat(block_data, s, axis=1)
                        if nx3 > 1:
                            block_data = np.repeat(block_data, s, axis=0)
                   data[q][kl_d:ku_d, jl_d:ju_d, il_d:iu_d] = block_data[kl_s:ku_s,
                                                                          jl_s:ju_s,
                                                                          il_s:iu_s]

Allocates an array of size ( 2^s nx1, 2^s nx2, 2^s nx3), in 3D, whatever the selected size of the domain.


                    if s > 1:
                        if nx1 > 1:
                            block_data = np.repeat(block_data, s, axis=2)[:,:,il_s:iu_s]
                        if nx2 > 1:
                            block_data = np.repeat(block_data, s, axis=1)[:,jl_s:ju_s,:]
                        if nx3 > 1:
                            block_data = np.repeat(block_data, s, axis=0)[kl_s:ku_s,:,:]
                        data[q][kl_d:ku_d, jl_d:ju_d, il_d:iu_d] = block_data
                    else:
                        data[q][kl_d:ku_d, jl_d:ju_d, il_d:iu_d] = block_data[kl_s:ku_s,jl_s:ju_s,il_s:iu_s]

instead applies the selection of block_data's source indices during np.repeat.

buildbot-princeton commented 5 months ago

Can one of the admins verify this patch?