Closed bluescarni closed 9 years ago
I dropped all the multithreaded-related stuff for now. I need more time to figure out a way to work around the problems on OSX.
@bluescarni - thanks for your work on this! Could you look into whether you can figure out how to adapt the code on the Fortran side to take the new format?
@astrofrog Sure. This is where I need to do the modifications, if I have understood correctly?
https://github.com/hyperion-rt/hyperion/blob/master/src/grid/grid_geometry_voronoi.f90
@bluescarni - yes, that should be the right file to modify. Let me know if you have any questions about Fortran syntax!
@astrofrog I have pushed the changes we discussed (I just overrode the current PR with the new branch).
For some reason the new version uses more memory. Investigating.
Old
New
Apparently this happens in the Fortran code, which is weird.
Mhm... I am noticing that, while the sparse representation saves some memory, we do have to store the indices as well. I am wondering if maybe that balances things out.
@bluescarni - I don't think that's going to be it, I think there should still see a net gain. This may be related to some other changes btw, the 'old' version above is from a few weeks ago, so checking.
Apart from the changes we discussed, I think this is good algorithmically. I ran for many photons and cells and no errors :) So once you resolve the table/dataset issue, we can merge!
@astrofrog I submitted the preliminary implementation of the change we discussed, that involves only the neighbours. If it looks good to you I can proceed to make the changes to the rest of the table as well.
@bluescarni - this works a lot better now and doesn't show the strange memory behavior - thanks for fixing it! The copying is not much faster but it's much more memory efficient. I don't think we need to extend this to that remaining table since there are no memory issues there.
This PR with the latest changes
Well actually it is quite a bit faster, I take that back. But I'm not sure if we'll see much gains for the main table since there is no memory issue there.
Works great, thanks! :)
@bluescarni - just noticed that the np.int32 was removed during debugging - can you open another small PR to add back the dtype=np.int32 so we can check things still pass?
@astrofrog Cheers! I will add back the int32 check in another PR. Good to see the speedup and the reduction in memory usage.
If you want I can still push this a bit forward with similar modifications in the table.
@bluescarni - for the table: why not, we can give it a try! :)
Here is the initial implementation of the sparse representation of the neighbours.
The
voronoi_grid
class invoronoi_helpers.py
now has an extra attribute, calledst
(sparse table). This is a tuple of 2 elements: the list of all neighbours of all cells, and a list of indices specifying at what points in the first list the neighbours for the n-th cell start. This second list always has a size ofnsites + 1
, while the first list has a size that depends on the initial distribution of the sites.Example:
st[0]
is[0,2,3,4,6,1,4,5,6,4,3]
andst[1]
is[0,3,4,11]
. This means that:[0,2,3]
,[4]
,[6,1,4,5,6,4,3]
.The previous dense representation is available as before in the
neighbours_table
attribute. I have added some checks to the existing test code in order to make sure that the sparse representation is consistent with the dense one.I also made some optimisations to the initial setup of the tessellation on the Python side (specifically, the check that all sites are within the domain boundaries is now done in numpy and hence much faster).