Skip to content

Commit e401645

Browse files
authored
Merge pull request #186 from manodeep/gridlink-memory-footprint
Reduce gridlink memory footprint
2 parents c86e7a1 + 9ed92bc commit e401645

15 files changed

+99
-128
lines changed

CHANGES.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ New features
1010
- conda installable package
1111
- GPU version
1212

13-
2.3.0 (upcoming)
13+
2.3.1 (upcoming)
1414
================
1515

16+
Enhancements
17+
------------
18+
- Reduce memory footprint of the cell pairs [#186]
19+
20+
21+
2.3.0 (2019-05-20)
22+
==================
23+
1624
**Breaking Changes**
1725
--------------------
1826

Corrfunc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
unicode_literals)
1111
import os
1212

13-
__version__ = "2.3.0"
13+
__version__ = "2.3.1"
1414
__author__ = "Manodeep Sinha <manodeep@gmail.com>"
1515

1616

common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ OPT += -DUSE_OMP
4141
DISTNAME:=Corrfunc
4242
MAJOR:=2
4343
MINOR:=3
44-
PATCHLEVEL:=0
44+
PATCHLEVEL:=1
4545
VERSION:=$(MAJOR).$(MINOR).$(PATCHLEVEL)
4646
ABI_COMPAT_VERSION:=$(MAJOR).0
4747
# Whenever conda needs to be checked again

mocks/DDrppi_mocks/countpairs_rp_pi_mocks_impl.c.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,13 @@ int countpairs_mocks_DOUBLE(const int64_t ND1, DOUBLE *ra1, DOUBLE *dec1, DOUBLE
625625
DOUBLE *this_rpavg = options->need_avg_sep ? rpavg:NULL;
626626
DOUBLE *this_weightavg = need_weightavg ? weightavg:NULL;
627627

628-
const int status = countpairs_rp_pi_mocks_function_DOUBLE(this_cell_pair->N1, this_cell_pair->x1,
629-
this_cell_pair->y1, this_cell_pair->z1, this_cell_pair->weights1,
630-
this_cell_pair->N2, this_cell_pair->x2,
631-
this_cell_pair->y2, this_cell_pair->z2, this_cell_pair->weights2,
628+
const int64_t icell = this_cell_pair->cellindex1;
629+
const int64_t icell2 = this_cell_pair->cellindex2;
630+
const cellarray_mocks_DOUBLE *first = &lattice1[icell];
631+
const cellarray_mocks_DOUBLE *second = &lattice2[icell2];
632+
633+
const int status = countpairs_rp_pi_mocks_function_DOUBLE(first->nelements, first->x, first->y, first->z, &(first->weights),
634+
second->nelements, second->x, second->y, second->z, &(second->weights),
632635
this_cell_pair->same_cell,
633636
options->fast_divide_and_NR_steps,
634637
sqr_rpmax, sqr_rpmin, nrpbin, npibin, rupp_sqr, pimax,

mocks/DDsmu_mocks/countpairs_s_mu_mocks_impl.c.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,13 @@ int countpairs_mocks_s_mu_DOUBLE(const int64_t ND1, DOUBLE *ra1, DOUBLE *dec1, D
631631
DOUBLE *this_savg = options->need_avg_sep ? &(savg[0]):NULL;
632632
DOUBLE *this_weightavg = need_weightavg ? weightavg:NULL;
633633

634-
const int status = countpairs_s_mu_mocks_function_DOUBLE(this_cell_pair->N1, this_cell_pair->x1,
635-
this_cell_pair->y1, this_cell_pair->z1, this_cell_pair->weights1,
636-
this_cell_pair->N2, this_cell_pair->x2,
637-
this_cell_pair->y2, this_cell_pair->z2, this_cell_pair->weights2,
634+
const int64_t icell = this_cell_pair->cellindex1;
635+
const int64_t icell2 = this_cell_pair->cellindex2;
636+
const cellarray_mocks_DOUBLE *first = &lattice1[icell];
637+
const cellarray_mocks_DOUBLE *second = &lattice2[icell2];
638+
639+
const int status = countpairs_s_mu_mocks_function_DOUBLE(first->nelements, first->x, first->y, first->z, &(first->weights),
640+
second->nelements, second->x, second->y, second->z, &(second->weights),
638641
this_cell_pair->same_cell,
639642
options->fast_divide_and_NR_steps,
640643
sqr_smax, sqr_smin, nsbin, nmu_bins, supp_sqr, mu_max,

mocks/DDtheta_mocks/countpairs_theta_mocks_impl.c.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,10 +1007,13 @@ int countpairs_theta_mocks_DOUBLE(const int64_t ND1, DOUBLE *ra1, DOUBLE *dec1,
10071007
DOUBLE *this_thetaavg = options->need_avg_sep ? thetaavg:NULL;
10081008
DOUBLE *this_weightavg = need_weightavg ? weightavg:NULL;
10091009

1010-
const int status = countpairs_theta_mocks_function_DOUBLE(this_cell_pair->N1, this_cell_pair->x1,
1011-
this_cell_pair->y1, this_cell_pair->z1, this_cell_pair->weights1,
1012-
this_cell_pair->N2, this_cell_pair->x2,
1013-
this_cell_pair->y2, this_cell_pair->z2, this_cell_pair->weights2,
1010+
const int64_t icell = this_cell_pair->cellindex1;
1011+
const int64_t icell2 = this_cell_pair->cellindex2;
1012+
const cellarray_mocks_DOUBLE *first = &lattice1[icell];
1013+
const cellarray_mocks_DOUBLE *second = &lattice2[icell2];
1014+
1015+
const int status = countpairs_theta_mocks_function_DOUBLE(first->nelements, first->x, first->y, first->z, &(first->weights),
1016+
second->nelements, second->x, second->y, second->z, &(second->weights),
10141017
this_cell_pair->same_cell,
10151018
options->fast_acos,
10161019
costhetamax, costhetamin, nthetabin,

theory/DD/countpairs_impl.c.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,13 @@ int countpairs_DOUBLE(const int64_t ND1, DOUBLE *X1, DOUBLE *Y1, DOUBLE *Z1,
452452
DOUBLE *this_rpavg = options->need_avg_sep ? rpavg:NULL;
453453
DOUBLE *this_weightavg = need_weightavg ? weightavg:NULL;
454454

455-
const int status = countpairs_function_DOUBLE(this_cell_pair->N1, this_cell_pair->x1,
456-
this_cell_pair->y1, this_cell_pair->z1, this_cell_pair->weights1,
457-
this_cell_pair->N2, this_cell_pair->x2,
458-
this_cell_pair->y2, this_cell_pair->z2, this_cell_pair->weights2,
455+
const int64_t icell = this_cell_pair->cellindex1;
456+
const int64_t icell2 = this_cell_pair->cellindex2;
457+
const cellarray_DOUBLE *first = &lattice1[icell];
458+
const cellarray_DOUBLE *second = &lattice2[icell2];
459+
460+
const int status = countpairs_function_DOUBLE(first->nelements, first->x, first->y, first->z, &(first->weights),
461+
second->nelements, second->x, second->y, second->z, &(second->weights),
459462
this_cell_pair->same_cell,
460463
sqr_rpmax, sqr_rpmin, nrpbin, rupp_sqr, pimax, //pimax is simply rpmax cast to DOUBLE
461464
this_cell_pair->xwrap, this_cell_pair->ywrap, this_cell_pair->zwrap,

theory/DDrppi/countpairs_rp_pi_impl.c.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,13 @@ int countpairs_rp_pi_DOUBLE(const int64_t ND1, DOUBLE *X1, DOUBLE *Y1, DOUBLE *Z
446446
DOUBLE *this_rpavg = options->need_avg_sep ? rpavg:NULL;
447447
DOUBLE *this_weightavg = need_weightavg ? weightavg:NULL;
448448

449-
const int status = countpairs_rp_pi_function_DOUBLE(this_cell_pair->N1, this_cell_pair->x1,
450-
this_cell_pair->y1, this_cell_pair->z1, this_cell_pair->weights1,
451-
this_cell_pair->N2, this_cell_pair->x2,
452-
this_cell_pair->y2, this_cell_pair->z2, this_cell_pair->weights2,
449+
const int64_t icell = this_cell_pair->cellindex1;
450+
const int64_t icell2 = this_cell_pair->cellindex2;
451+
const cellarray_DOUBLE *first = &lattice1[icell];
452+
const cellarray_DOUBLE *second = &lattice2[icell2];
453+
454+
const int status = countpairs_rp_pi_function_DOUBLE(first->nelements, first->x, first->y, first->z, &(first->weights),
455+
second->nelements, second->x, second->y, second->z, &(second->weights),
453456
this_cell_pair->same_cell,
454457
sqr_rpmax, sqr_rpmin, nrpbin, npibin, rupp_sqr, pimax,
455458
this_cell_pair->xwrap, this_cell_pair->ywrap, this_cell_pair->zwrap,

theory/DDsmu/countpairs_s_mu_impl.c.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,13 @@ int countpairs_s_mu_DOUBLE(const int64_t ND1, DOUBLE *X1, DOUBLE *Y1, DOUBLE *Z1
466466
DOUBLE *this_rpavg = options->need_avg_sep ? savg:NULL;
467467
DOUBLE *this_weightavg = need_weightavg ? weightavg:NULL;
468468

469-
const int status = countpairs_s_mu_function_DOUBLE(this_cell_pair->N1, this_cell_pair->x1,
470-
this_cell_pair->y1, this_cell_pair->z1, this_cell_pair->weights1,
471-
this_cell_pair->N2, this_cell_pair->x2,
472-
this_cell_pair->y2, this_cell_pair->z2, this_cell_pair->weights2,
469+
const int64_t icell = this_cell_pair->cellindex1;
470+
const int64_t icell2 = this_cell_pair->cellindex2;
471+
const cellarray_DOUBLE *first = &lattice1[icell];
472+
const cellarray_DOUBLE *second = &lattice2[icell2];
473+
474+
const int status = countpairs_s_mu_function_DOUBLE(first->nelements, first->x, first->y, first->z, &(first->weights),
475+
second->nelements, second->x, second->y, second->z, &(second->weights),
473476
this_cell_pair->same_cell,
474477
options->fast_divide_and_NR_steps,
475478
sqr_smax, sqr_smin, nsbin, nmu_bins, supp_sqr, mu_max, pimax,

theory/wp/countpairs_wp_impl.c.src

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,13 @@ int countpairs_wp_DOUBLE(const int64_t ND, DOUBLE * restrict X, DOUBLE * restric
427427
current_utc_time(&tcell_start);
428428
}
429429

430-
const int status = wp_function_DOUBLE(this_cell_pair->x1, this_cell_pair->y1, this_cell_pair->z1,
431-
this_cell_pair->weights1, this_cell_pair->N1,
432-
this_cell_pair->x2, this_cell_pair->y2, this_cell_pair->z2,
433-
this_cell_pair->weights2, this_cell_pair->N2,
430+
const int64_t icell = this_cell_pair->cellindex1;
431+
const int64_t icell2 = this_cell_pair->cellindex2;
432+
const cellarray_DOUBLE *first = &lattice[icell];
433+
const cellarray_DOUBLE *second = &lattice[icell2];
434+
435+
const int status = wp_function_DOUBLE(first->x, first->y, first->z, &(first->weights), first->nelements,
436+
second->x, second->y, second->z, &(second->weights), second->nelements,
434437
this_cell_pair->same_cell,
435438
sqr_rpmax, sqr_rpmin, nrpbins, rupp_sqr, pimax,
436439
this_cell_pair->xwrap, this_cell_pair->ywrap, this_cell_pair->zwrap,
@@ -448,7 +451,7 @@ int countpairs_wp_DOUBLE(const int64_t ND, DOUBLE * restrict X, DOUBLE * restric
448451
current_utc_time(&tcell_end);
449452
double time_in_ns = REALTIME_ELAPSED_NS(tcell_start, tcell_end);
450453
struct api_cell_timings *base_cell = &(options->cell_timings[icellpair]);
451-
ASSIGN_CELL_TIMINGS(base_cell, this_cell_pair->N1, this_cell_pair->N2, time_in_ns,
454+
ASSIGN_CELL_TIMINGS(base_cell, first->nelements, second->nelements, time_in_ns,
452455
tid, this_cell_pair->cellindex1, this_cell_pair->cellindex2);
453456
}
454457
}//abort-status

theory/xi/countpairs_xi_impl.c.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,13 @@ int countpairs_xi_DOUBLE(const int64_t ND, DOUBLE * restrict X, DOUBLE * restric
395395
DOUBLE *this_rpavg = options->need_avg_sep ? ravg:NULL;
396396
DOUBLE *this_weightavg = need_weightavg ? weightavg:NULL;
397397

398-
const int status = xi_function_DOUBLE(this_cell_pair->x1, this_cell_pair->y1, this_cell_pair->z1,
399-
this_cell_pair->weights1, this_cell_pair->N1,
400-
this_cell_pair->x2, this_cell_pair->y2, this_cell_pair->z2,
401-
this_cell_pair->weights2, this_cell_pair->N2,
398+
const int64_t icell = this_cell_pair->cellindex1;
399+
const int64_t icell2 = this_cell_pair->cellindex2;
400+
const cellarray_DOUBLE *first = &lattice[icell];
401+
const cellarray_DOUBLE *second = &lattice[icell2];
402+
403+
const int status = xi_function_DOUBLE(first->x, first->y, first->z, &(first->weights), first->nelements,
404+
second->x, second->y, second->z, &(second->weights), second->nelements,
402405
this_cell_pair->same_cell,
403406
sqr_rmax, sqr_rmin, nbins, rupp_sqr,
404407
this_cell_pair->xwrap, this_cell_pair->ywrap, this_cell_pair->zwrap,

utils/cell_pair.h.src

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,7 @@ extern "C" {
1818
#include "weight_defs_DOUBLE.h"
1919

2020
struct cell_pair_DOUBLE{
21-
int64_t N1;
22-
DOUBLE *x1;
23-
DOUBLE *y1;
24-
DOUBLE *z1;
25-
int64_t *orig_index1;
26-
weight_struct_DOUBLE *weights1;
2721
int64_t cellindex1;
28-
29-
int64_t N2;
30-
DOUBLE *x2;
31-
DOUBLE *y2;
32-
DOUBLE *z2;
33-
int64_t *orig_index2;
34-
weight_struct_DOUBLE *weights2;
3522
int64_t cellindex2;
3623

3724
DOUBLE xwrap;
@@ -47,16 +34,6 @@ struct cell_pair_DOUBLE{
4734
DOUBLE closest_z1;
4835

4936
int8_t same_cell;
50-
union{
51-
int16_t xbin_offset;
52-
int16_t ra_bin_offset;
53-
};
54-
union{
55-
int16_t ybin_offset;
56-
int16_t dec_bin_offset;
57-
};
58-
int16_t zbin_offset;
59-
int8_t unused;//explicitly adding here for alignment
6037
};
6138

6239
#ifdef __cplusplus

utils/defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
extern "C" {
2020
#endif
2121

22-
#define API_VERSION STR("2.3.0")
22+
#define API_VERSION STR("2.3.1")
2323

2424
typedef enum {
2525
DEFAULT=-42,/* present simply to make the enum a signed int*/

utils/gridlink_impl.c.src

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,17 @@ struct cell_pair_DOUBLE * generate_cell_pairs_DOUBLE(struct cellarray_DOUBLE *la
428428
const int64_t nx_ngb = 2*xbin_refine_factor + 1;
429429
const int64_t ny_ngb = 2*ybin_refine_factor + 1;
430430
const int64_t nz_ngb = 2*zbin_refine_factor + 1;
431-
const int64_t max_ngb_cells = nx_ngb * ny_ngb * nz_ngb;
431+
const int64_t max_ngb_cells = nx_ngb * ny_ngb * nz_ngb - 1; // -1 for self
432432

433-
const int64_t max_num_cell_pairs = totncells * max_ngb_cells;
433+
434+
if( ! (autocorr == 0 || autocorr == 1) ) {
435+
fprintf(stderr,"Error: Strange value of autocorr = %d. Expected to receive either 1 (auto-correlations) or 0 (cross-correlations)\n", autocorr);
436+
return NULL;
437+
}
438+
const int64_t num_self_pairs = totncells;
439+
const int64_t num_nonself_pairs = totncells * max_ngb_cells / (1 + autocorr);
440+
441+
const int64_t max_num_cell_pairs = num_self_pairs + num_nonself_pairs;
434442
int64_t num_cell_pairs = 0;
435443
struct cell_pair_DOUBLE *all_cell_pairs = my_malloc(sizeof(*all_cell_pairs), max_num_cell_pairs);
436444
XRETURN(all_cell_pairs != NULL, NULL,
@@ -542,20 +550,7 @@ struct cell_pair_DOUBLE * generate_cell_pairs_DOUBLE(struct cellarray_DOUBLE *la
542550
//If we have reached here, then this cell *MIGHT* have a pair. We
543551
//need to add a cell-pair to the array of all cell-pairs
544552
struct cell_pair_DOUBLE *this_cell_pair = &all_cell_pairs[num_cell_pairs];
545-
this_cell_pair->N1 = first->nelements;
546-
this_cell_pair->x1 = first->x;
547-
this_cell_pair->y1 = first->y;
548-
this_cell_pair->z1 = first->z;
549-
this_cell_pair->orig_index1 = first->original_index;
550-
this_cell_pair->weights1 = &first->weights;
551553
this_cell_pair->cellindex1 = icell;
552-
553-
this_cell_pair->N2 = second->nelements;
554-
this_cell_pair->x2 = second->x;
555-
this_cell_pair->y2 = second->y;
556-
this_cell_pair->z2 = second->z;
557-
this_cell_pair->orig_index2 = second->original_index;
558-
this_cell_pair->weights2 = &second->weights;
559554
this_cell_pair->cellindex2 = icell2;
560555

561556
this_cell_pair->xwrap = off_xwrap;
@@ -570,10 +565,6 @@ struct cell_pair_DOUBLE * generate_cell_pairs_DOUBLE(struct cellarray_DOUBLE *la
570565
this_cell_pair->closest_y1 = closest_y1;
571566
this_cell_pair->closest_z1 = closest_z1;
572567

573-
this_cell_pair->xbin_offset = iix;
574-
this_cell_pair->ybin_offset = iiy;
575-
this_cell_pair->zbin_offset = iiz;
576-
577568
this_cell_pair->same_cell = (autocorr == 1 && icell2 == icell) ? 1:0;
578569

579570
num_cell_pairs++;

0 commit comments

Comments
 (0)