Skip to content

Commit

Permalink
ARROW-8409: [R] Add R wrappers for getting and setting global CPU thr…
Browse files Browse the repository at this point in the history
…ead pool capacity

I needed this while running some benchmarks.

Closes #6906 from wesm/ARROW-8409

Lead-authored-by: Wes McKinney <wesm+git@apache.org>
Co-authored-by: Neal Richardson <neal.p.richardson@gmail.com>
Signed-off-by: Neal Richardson <neal.p.richardson@gmail.com>
  • Loading branch information
wesm and nealrichardson committed Apr 13, 2020
1 parent d0f56ed commit 3ff0c18
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions r/DESCRIPTION
Expand Up @@ -61,6 +61,7 @@ Collate:
'io.R'
'compression.R'
'compute.R'
'config.R'
'csv.R'
'dataset.R'
'filesystem.R'
Expand Down
2 changes: 2 additions & 0 deletions r/NAMESPACE
Expand Up @@ -139,6 +139,7 @@ export(cast_options)
export(chunked_array)
export(codec_is_available)
export(contains)
export(cpu_count)
export(dataset_factory)
export(date32)
export(date64)
Expand Down Expand Up @@ -184,6 +185,7 @@ export(read_table)
export(read_tsv_arrow)
export(record_batch)
export(schema)
export(set_cpu_count)
export(starts_with)
export(string)
export(struct)
Expand Down
30 changes: 30 additions & 0 deletions r/R/config.R
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

#' Manage the global CPU thread pool in libarrow
#'
#' @export
cpu_count <- function() {
GetCpuThreadPoolCapacity()
}

#' @rdname cpu_count
#' @param num_threads integer: New number of threads for thread pool
#' @export
set_cpu_count <- function(num_threads) {
SetCpuThreadPoolCapacity(as.integer(num_threads))
}
3 changes: 3 additions & 0 deletions r/_pkgdown.yml
Expand Up @@ -132,6 +132,9 @@ reference:
- FileInfo
- FileStats
- FileSelector
- title: Configuration
contents:
- cpu_count
- title: Installation helpers
contents:
- arrow_available
Expand Down
11 changes: 11 additions & 0 deletions r/man/cpu_count.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions r/man/set_cpu_count.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions r/tests/testthat/test-thread-pool.R
Expand Up @@ -15,12 +15,12 @@
# specific language governing permissions and limitations
# under the License.

context("CpuThreadPoolCapacity")
context("Global Thread Pool")

test_that("can set/get cpu thread pool capacity", {
old <- GetCpuThreadPoolCapacity()
SetCpuThreadPoolCapacity(19L)
expect_equal(GetCpuThreadPoolCapacity(), 19L)
SetCpuThreadPoolCapacity(old)
expect_equal(GetCpuThreadPoolCapacity(), old)
old <- cpu_count()
set_cpu_count(19)
expect_equal(cpu_count(), 19L)
set_cpu_count(old)
expect_equal(cpu_count(), old)
})

0 comments on commit 3ff0c18

Please sign in to comment.