set_num_threads: Set the number of OpenMP threads used by the functions of...

View source: R/ctools.R

set_num_threadsR Documentation

Set the number of OpenMP threads used by the functions of package cpgen

Description

This function sets the value of the global variable stored in options()$cpgen.threads to the assigned integer. Note_1: The assigned value may exceed the number of physical cores present but that might lead to dramatical decrease in performance. Note_2: The function can override the global variable 'OMP_NUM_THREADS' (if global=TRUE and hence also other non-cpgen functions are affected by a call to set_num_threads().

Usage

set_num_threads(x,silent=FALSE, global=FALSE)

Arguments

x

Integer scalar that specifies the number of threads to be used by cpgen-functions

silent

boolean, controls whether to print a message

global

boolean, change openmp threads globally (might effect other libraries)

Value

Changes the global variable cpgen.threads to the value in x

See Also

get_num_threads, get_max_threads, check_openmp

Examples


# Control the number of threads being used in an R-session:

# set the number of threads to 1
set_num_threads(1)

#### Use a parallelized cpgen-function

# generate random data
rand_data(100,500)

# check single-threaded performance
system.time(W <- M%c%t(M))

# set number of threads to 2

set_num_threads(2)

# check multi-threaded performance
system.time(W <- M%c%t(M))

cheuerde/cpgen documentation built on July 27, 2023, 11:34 a.m.