manodeep / Corrfunc

⚡️⚡️⚡️Blazing fast correlation functions on the CPU.
https://corrfunc.readthedocs.io
MIT License
163 stars 50 forks source link

Buggy grid refinement due to int8 overflow #179

Closed lgarrison closed 5 years ago

lgarrison commented 5 years ago

General information

Issue description

Automatic grid refinement is accidentally triggered due to an int8 overflow in max_nmesh (e.g. from here: https://github.com/manodeep/Corrfunc/blob/master/theory/DD/countpairs_impl.c.src#L244)

We're taking the max of three ints and assigning the result to an int8. Obviously the grid refinement needs an overhaul anyway, but in the meantime we can squash this bug.

Expected behavior

Grid refinement is only triggered for max_nmesh < BOOST_CELL_THRESH (=10) or avg_np >= BOOST_NUMPART_THRESH (=25)

Minimal failing example

import Corrfunc
import numpy as np
box = 1000
X,Y,Z = np.random.rand(3,1000)*box
Corrfunc.theory.DD(True, 1, [0.1,4], X,Y,Z, max_cells_per_dim=300, boxsize=box, verbose=True)
Running with points in [xmin,xmax] = 1.033422,998.203714 with periodic wrapping = 1000.000000
Running with points in [ymin,ymax] = 0.129471,999.796202 with periodic wrapping = 1000.000000
Running with points in [zmin,zmax] = 0.990155,999.890578 with periodic wrapping = 1000.000000
In gridlink_index_particles_double> Running with [nmesh_x, nmesh_y, nmesh_z]  = 250,250,250.  Time taken =   3.544 sec
countpairs_double> gridlink seems inefficient. nmesh = (250, 250, 250); avg_np = 6.4e-05. Boosting bin refine factor - should lead to better performance
xmin = 1.033422 xmax=998.203714 rpmax = 4.000000
In gridlink_index_particles_double> Running with [nmesh_x, nmesh_y, nmesh_z]  = 300,300,250.  Time taken =   4.522 sec
0%.........10%.........20%.........30%.........40%.........50%.........60%.........70%.........80%.........90%.........100% done. Time taken =  5.199 secs