Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/gsumm.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,25 @@ 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;
highSize = ((ngrp-1)>>shift) + 1;

grp = (int *)R_alloc(nrow, sizeof(int)); // TODO: use malloc and made this local as not needed globally when all functions here use gather
// 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[]
batchSize = (nrow-1)/nBatch + 1;
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;

//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", // # nocov
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<ngrp; g++) {
Expand Down