Skip to content

Commit 637a241

Browse files
authored
Move default number of jobs to its own function (#5)
1 parent 9106148 commit 637a241

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/ParallelTestRunner.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ function runtest(::Type{TestRecord}, f, name)
200200
return res
201201
end
202202

203+
# This is an internal function, not to be used by end users. The keyword
204+
# arguments are only for testing purposes.
205+
"""
206+
default_njobs()
207+
208+
Determine default number of parallel jobs.
209+
"""
210+
function default_njobs(; cpu_threads = Sys.CPU_THREADS, free_memory = Sys.free_memory())
211+
jobs = cpu_threads
212+
memory_jobs = Int64(free_memory) ÷ (2 * 2^30)
213+
return max(1, min(jobs, memory_jobs))
214+
end
215+
203216
"""
204217
runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
205218
@@ -263,7 +276,7 @@ function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
263276
--list List all available tests.
264277
--verbose Print more information during testing.
265278
--quickfail Fail the entire run as soon as a single test errored.
266-
--jobs=N Launch `N` processes to perform tests (default: Sys.CPU_THREADS).
279+
--jobs=N Launch `N` processes to perform tests.
267280
268281
Remaining arguments filter the tests that will be executed."""
269282
)
@@ -340,9 +353,7 @@ function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
340353

341354
# determine parallelism
342355
if !set_jobs
343-
jobs = Sys.CPU_THREADS
344-
memory_jobs = Int64(Sys.free_memory()) ÷ (2 * 2^30)
345-
jobs = max(1, min(jobs, memory_jobs))
356+
jobs = default_njobs()
346357
end
347358
@info "Running $jobs tests in parallel. If this is too many, specify the `--jobs=N` argument to the tests, or set the `JULIA_CPU_THREADS` environment variable."
348359

0 commit comments

Comments
 (0)