From 0ec5ddf57deaefdf8bb6c18e502082a1acd7832d Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Fri, 9 Sep 2016 10:10:27 -0400 Subject: [PATCH] @variance runtime: fix map.c aggregate/calculations gcc's indentation warnings pointed a finger of suspicion at the new code that merges variance-related partial statistics across stats structs. Two blocks are now conditioned on STAT_OP_VARIANCE. --- runtime/map.c | 71 ++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/runtime/map.c b/runtime/map.c index 0e0f3d3c6..d24c94c99 100644 --- a/runtime/map.c +++ b/runtime/map.c @@ -478,31 +478,31 @@ static int _new_map_copy_stat (MAP map, struct stat_data *sd1, struct stat_data sd1->min = sd2->min; if (sd2->max > sd1->max) sd1->max = sd2->max; - sd1->shift = sd2->shift; - - sd1->avg_s = _stp_div64(NULL, sd1->sum << sd2->shift, sd1->count); - /* - * A bit shift would certainly be faster below, but that would - * introduce rounding errors. - */ - sd1->avg = _stp_div64(NULL, sd1->sum, sd1->count); - - /* - * For aggregating variance over available CPUs, the Total Variance - * formula is being used. This formula is mentioned in following - * paper: Niranjan Kamat, Arnab Nandi: A Closer Look at Variance - * Implementations In Modern Database Systems: SIGMOD Record 2015. - * Available at: http://web.cse.ohio-state.edu/~kamatn/variance.pdf - */ - S11 = sd1_count * (sd1_avg_s - sd1->avg_s) * (sd1_avg_s - sd1->avg_s); - S12 = (sd1_count - 1) * sd1->variance_s; - - S21 = sd2->count * (sd2->avg_s - sd1->avg_s) * (sd2->avg_s - sd1->avg_s); - S22 = (sd2->count - 1) * sd2->variance_s; - - sd1->variance_s = _stp_div64(NULL, (S11 + S12 + S21 + S22), (sd1->count - 1)); - - sd1->variance = sd1->variance_s >> (2 * sd2->shift); + + if (sd2->stat_ops & STAT_OP_VARIANCE) { + sd1->shift = sd2->shift; + sd1->avg_s = _stp_div64(NULL, sd1->sum << sd2->shift, sd1->count); + /* + * A bit shift would certainly be faster below, but that would + * introduce rounding errors. + */ + sd1->avg = _stp_div64(NULL, sd1->sum, sd1->count); + + /* + * For aggregating variance over available CPUs, the Total Variance + * formula is being used. This formula is mentioned in following + * paper: Niranjan Kamat, Arnab Nandi: A Closer Look at Variance + * Implementations In Modern Database Systems: SIGMOD Record 2015. + * Available at: http://web.cse.ohio-state.edu/~kamatn/variance.pdf + */ + S11 = sd1_count * (sd1_avg_s - sd1->avg_s) * (sd1_avg_s - sd1->avg_s); + S12 = (sd1_count - 1) * sd1->variance_s; + S21 = sd2->count * (sd2->avg_s - sd1->avg_s) * (sd2->avg_s - sd1->avg_s); + S22 = (sd2->count - 1) * sd2->variance_s; + + sd1->variance_s = _stp_div64(NULL, (S11 + S12 + S21 + S22), (sd1->count - 1)); + sd1->variance = sd1->variance_s >> (2 * sd2->shift); + } if (st->type != HIST_NONE) { int j; for (j = 0; j < st->buckets; j++) @@ -513,16 +513,17 @@ static int _new_map_copy_stat (MAP map, struct stat_data *sd1, struct stat_data sd1->sum = sd2->sum; sd1->min = sd2->min; sd1->max = sd2->max; - sd1->shift = sd2->shift; - sd1->avg_s = sd2->avg_s; - - /* - * Setting sd1->avg = sd2->avg_s >> sd2->shift; below would - * introduce slight rounding issues. - */ - sd1->avg = _stp_div64(NULL, sd1->sum, sd1->count); - sd1->variance_s = sd2->variance_s; - sd1->variance = sd2->variance_s >> (2 * sd2->shift);; + if (sd2->stat_ops & STAT_OP_VARIANCE) { + sd1->shift = sd2->shift; + sd1->avg_s = sd2->avg_s; + /* + * Setting sd1->avg = sd2->avg_s >> sd2->shift; below would + * introduce slight rounding issues. + */ + sd1->avg = _stp_div64(NULL, sd1->sum, sd1->count); + sd1->variance_s = sd2->variance_s; + sd1->variance = sd2->variance_s >> (2 * sd2->shift); + } if (st->type != HIST_NONE) { int j; for (j = 0; j < st->buckets; j++) -- 2.43.5