From 4e25c330f34fde74bb0ea61ef9d9af8b8b5cd86b Mon Sep 17 00:00:00 2001 From: mattdowle Date: Tue, 11 Dec 2018 16:20:06 -0800 Subject: [PATCH 1/2] fixed segfault and added check --- src/gsumm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gsumm.c b/src/gsumm.c index 951cd0dc47..99d6676dd6 100644 --- a/src/gsumm.c +++ b/src/gsumm.c @@ -73,7 +73,8 @@ SEXP gforce(SEXP env, SEXP jsub, SEXP o, SEXP f, SEXP l, SEXP irowsArg) { } int nb = nbit(ngrp-1); - shift = nb/2; // /2 so that high and low can be uint16_t; MAX(nb-8,0) fails on uint16_t; + shift = nb/2; // /2 so that high and low can be uint16_t, and no limit (even for nb=4) to stress-test. + // shift=MAX(nb-8,0); if (shift>16) shift=nb/2; // TODO: when we have stress-test off mode, do this mask = (1<>shift) + 1; @@ -82,11 +83,15 @@ SEXP gforce(SEXP env, SEXP jsub, SEXP o, SEXP f, SEXP l, SEXP irowsArg) { const int *restrict fp = INTEGER(f); nBatch = MIN((nrow+1)/2, getDTthreads()*2); // 2 to reduce last-thread-home. TODO: experiment. The higher this is though, the bigger is counts[] - batchSize = (nrow-1)/nBatch + 1; + batchSize = MAX(1, (nrow-1)/nBatch); lastBatchSize = nrow - (nBatch-1)*batchSize; - - //Rprintf("ngrp=%d nbit=%d shift=%d highSize=%d nBatch=%d batchSize=%d lastBatchSize=%d\n", ngrp, nb, shift, highSize, nBatch, batchSize, lastBatchSize); - + // We deliberate use, for example, 40 batches of just 14 rows, to stress-test tests. This strategy proved to be a good one as #3204 immediately came to light. + // TODO: enable stress-test mode in tests only (#3205) which can be turned off by default in release to decrease overhead on small data + // if that is established to be biting (it may be fine). + if (nBatch<1 || batchSize<1 || lastBatchSize<1) { + error("Internal error: nrow=%d ngrp=%d nbit=%d shift=%d highSize=%d nBatch=%d batchSize=%d lastBatchSize=%d\n", + nrow, ngrp, nb, shift, highSize, nBatch, batchSize, lastBatchSize); // # nocov + } // initial population of g: #pragma omp parallel for num_threads(getDTthreads()) for (int g=0; g Date: Tue, 11 Dec 2018 16:59:15 -0800 Subject: [PATCH 2/2] nocov needs to be on first of split line --- src/gsumm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gsumm.c b/src/gsumm.c index 99d6676dd6..f178a1e9a0 100644 --- a/src/gsumm.c +++ b/src/gsumm.c @@ -82,15 +82,15 @@ SEXP gforce(SEXP env, SEXP jsub, SEXP o, SEXP f, SEXP l, SEXP irowsArg) { // maybe better to malloc to avoid R's heap. This grp isn't global, so it doesn't need to be R_alloc const int *restrict fp = INTEGER(f); - nBatch = MIN((nrow+1)/2, getDTthreads()*2); // 2 to reduce last-thread-home. TODO: experiment. The higher this is though, the bigger is counts[] + nBatch = MIN((nrow+1)/2, getDTthreads()*2); // *2 to reduce last-thread-home. TODO: experiment. The higher this is though, the bigger is counts[] batchSize = MAX(1, (nrow-1)/nBatch); lastBatchSize = nrow - (nBatch-1)*batchSize; // We deliberate use, for example, 40 batches of just 14 rows, to stress-test tests. This strategy proved to be a good one as #3204 immediately came to light. // TODO: enable stress-test mode in tests only (#3205) which can be turned off by default in release to decrease overhead on small data // if that is established to be biting (it may be fine). if (nBatch<1 || batchSize<1 || lastBatchSize<1) { - error("Internal error: nrow=%d ngrp=%d nbit=%d shift=%d highSize=%d nBatch=%d batchSize=%d lastBatchSize=%d\n", - nrow, ngrp, nb, shift, highSize, nBatch, batchSize, lastBatchSize); // # nocov + error("Internal error: nrow=%d ngrp=%d nbit=%d shift=%d highSize=%d nBatch=%d batchSize=%d lastBatchSize=%d\n", // # nocov + nrow, ngrp, nb, shift, highSize, nBatch, batchSize, lastBatchSize); // # nocov } // initial population of g: #pragma omp parallel for num_threads(getDTthreads())