Skip to content

Commit

Permalink
Merge pull request #2236 from st-pasha/fread_nthreads
Browse files Browse the repository at this point in the history
Parameter `nth` for fread can now be 0 or negative.
  • Loading branch information
mattdowle authored Jun 30, 2017
2 parents bfa0816 + 3ed9b8c commit 0cba833
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,12 @@ int freadMain(freadMainArgs _args) {
}

int nth = args.nth;
if (nth <= 0) STOP("nThreads must be >= 1, received %d", nth);
if (nth > omp_get_max_threads()) {
nth = omp_get_max_threads();
DTPRINT("Limited nth=%d to omp_get_max_threads()=%d\n", args.nth, nth);
{
int maxth = omp_get_max_threads();
if (nth > maxth) nth = maxth;
if (nth <= 0) nth += maxth;
if (nth <= 0) nth = 1;
if (verbose) DTPRINT(" Using %d threads (omp_get_max_threads()=%d, nth=%d)\n", nth, maxth, args.nth);
}

uint64_t ui64 = NA_FLOAT64_I64;
Expand Down
5 changes: 4 additions & 1 deletion src/fread.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ typedef struct freadMainArgs
// If True, then emit progress messages during the parsing.
_Bool showProgress;

// Maximum number of threads (should be >= 1).
// Maximum number of threads. If 0, then fread will use the maximum possible
// number of threads, as determined by omp_get_max_threads(). If negative,
// then fread will use that many threads less than allowed maximum (but
// always at least 1).
int32_t nth;

// Emit extra debug-level information.
Expand Down

0 comments on commit 0cba833

Please sign in to comment.