Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b796427
Fix and extend parallel_reduce functionality, including
paciorek Mar 11, 2026
1ea9d21
redesign nClass so that compiled inherits from uncompiled, C componen…
perrydv Mar 1, 2026
0a04ff3
Trap missing argType cleanly (issue 107).
paciorek Mar 5, 2026
f3ed370
Add R version of nSeq with tests.
paciorek Mar 5, 2026
f86d15a
Rework parallel_for handling to auto detect shared vars.
paciorek Mar 14, 2026
9cca315
Handle local vars in body of parallel_for.
paciorek Mar 16, 2026
6373c4b
Handle use of class method in parallel_for.
paciorek Mar 18, 2026
489deab
Support multiple sequential parfor loops.
paciorek Mar 19, 2026
40f7979
Fix handling of multiple loops to give all
paciorek Mar 19, 2026
17236b4
Extend parallel_reduce:
paciorek Mar 22, 2026
18e1d08
Make various tricky fixes for parallel_reduce, including:
paciorek Mar 25, 2026
cf7d6c7
Move some processing from labelAbstractTypes to finalTransformations.
paciorek Mar 31, 2026
52b4f22
Fix normalizeCalls handling of reduce operator.
paciorek Mar 31, 2026
d210641
Fix the fix to normalizeCalls handling of reduce operator.
paciorek Apr 2, 2026
472b176
Add full draft of setting TBB num of threads.
paciorek Apr 2, 2026
923278e
Remove stray .DS_Store.
paciorek Apr 3, 2026
03784c5
Fix issue with parallel_reduce arg matching.
paciorek Apr 3, 2026
73e0d9f
Add tests for setting number of threads.
paciorek Apr 3, 2026
5301edb
Make partial draft of testing for parallel_reduce.
paciorek Apr 3, 2026
ba8d6cf
Fix some bugs with parallel_reduce use cases.
paciorek Apr 20, 2026
4ec91c2
Actually finalize parallel_reduce tests.
paciorek Apr 20, 2026
bae12d2
Make comment in tbb test.
paciorek Apr 20, 2026
d4d8242
Inline function in utils.h.
paciorek Apr 21, 2026
0beb47a
Add tests for parallel_for.
paciorek Apr 26, 2026
b0098b4
Remove unneeded local vars from method calling par_reduce.
paciorek Apr 29, 2026
b53840e
Fix merge conflict from tbb-pkging.
paciorek May 17, 2026
03611fe
Avoid threaded R API calls with getNumThreads.
paciorek May 17, 2026
b4886ba
Take different approach to avoiding threaded R API calls.
paciorek May 29, 2026
f988ccf
Remove depth counter code from global_R_interface_cppDef.
paciorek May 29, 2026
1c0a533
Fix and extend parallel_reduce functionality, including
paciorek Mar 11, 2026
5f553d3
Add R version of nSeq with tests.
paciorek Mar 5, 2026
0fc8d3a
Rework parallel_for handling to auto detect shared vars.
paciorek Mar 14, 2026
0bd8342
Handle local vars in body of parallel_for.
paciorek Mar 16, 2026
508da94
Handle use of class method in parallel_for.
paciorek Mar 18, 2026
8c98793
Support multiple sequential parfor loops.
paciorek Mar 19, 2026
2fce1a6
Fix handling of multiple loops to give all
paciorek Mar 19, 2026
ccd5f64
Extend parallel_reduce:
paciorek Mar 22, 2026
91c9160
Make various tricky fixes for parallel_reduce, including:
paciorek Mar 25, 2026
ab777ec
Move some processing from labelAbstractTypes to finalTransformations.
paciorek Mar 31, 2026
ce510bf
Fix normalizeCalls handling of reduce operator.
paciorek Mar 31, 2026
a397f90
Fix the fix to normalizeCalls handling of reduce operator.
paciorek Apr 2, 2026
e127be8
Add full draft of setting TBB num of threads.
paciorek Apr 2, 2026
ddef831
Remove stray .DS_Store.
paciorek Apr 3, 2026
af0fa19
Fix issue with parallel_reduce arg matching.
paciorek Apr 3, 2026
76e3f3c
Add tests for setting number of threads.
paciorek Apr 3, 2026
bbfabf0
Make partial draft of testing for parallel_reduce.
paciorek Apr 3, 2026
a775568
Fix some bugs with parallel_reduce use cases.
paciorek Apr 20, 2026
f786fb3
Actually finalize parallel_reduce tests.
paciorek Apr 20, 2026
f12ff34
Make comment in tbb test.
paciorek Apr 20, 2026
cd941af
Inline function in utils.h.
paciorek Apr 21, 2026
1eb1bec
Add tests for parallel_for.
paciorek Apr 26, 2026
fd8c6b4
Remove unneeded local vars from method calling par_reduce.
paciorek Apr 29, 2026
602f338
Fix bug in removing parallel_reduce loop_var from symbolTable.
paciorek May 30, 2026
27d16b2
Support `self` in parallelFor body and for parallel reduction function.
paciorek Jul 15, 2026
46ddbf3
Fix a couple small bugs introduced in tbb reworking.
paciorek Jul 15, 2026
fe59bef
Finalize tbb reduce tests. Noting that they seem fragile when run ful…
paciorek Jul 16, 2026
845a56a
Avoid TBB includes if not needed.
paciorek Jul 16, 2026
0b9621f
Remove incorrect/fixed TODO.
paciorek Jul 16, 2026
8b8226e
Resolve merge conflicts from nested-tbb.
paciorek Jul 17, 2026
ec4d2d2
Remove stray merge conflict lines.
paciorek Jul 17, 2026
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
Binary file removed UserManual/.DS_Store
Binary file not shown.
Binary file removed nCompiler/.DS_Store
Binary file not shown.
31 changes: 21 additions & 10 deletions nCompiler/R/Rexecution.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ parallel_for <- function(index, range, body, ...) {

#' @export
parallel_reduce <- function(f, x, init, ...) {
if(is.character(f)) { # Not clear how to convert to char ...
operatorDef <- operatorDefEnv[[f]]
if(!is.null(operatorDef) && is.null(operatorDef$reduction))
stop("`", f, "` is not a valid reduction function/operator")
}
if(missing(init)) {
if(!is.character(f) || is.null(operatorDef) || is.null(operatorDef$reduction))
stop("`init` argument is missing and no default value provided for reduction function/operator")
init <- operatorDef$reduction
}
if(identical(f, "pairmin")) f <- "pmin"
if(identical(f, "pairmax")) f <- "pmax"
Reduce(f, x, init)
}

Expand Down Expand Up @@ -406,18 +418,18 @@ nRep <- function(x, ...) {
}

#' Sequence Generation
#'
#'
#' In a \code{nFunction}, \code{nSeq} is (mostly) equivalent to \code{base::seq}
#'
#' @details This function is similar to R's \code{\link{seq}} function, but
#' can be used in a nFunction and compiled using \code{nCompile}.
#'
#' @details This function is similar to R's \code{\link{seq}} function, but
#' can be used in a nFunction and compiled using \code{nCompile}.
#'
#' @param from the starting value of the sequence.
#'
#'
#' @param to the ending value of the sequence.
#'
#'
#' @param by increment of the sequence
#'
#'
#' @param length.out desired length of the sequence
#'
#' @details
Expand All @@ -428,7 +440,6 @@ nRep <- function(x, ...) {
#' There are no nCompiler versions of \code{seq.int}, \code{seq_along} or \code{seq_len}.

#' @export
#'
nSeq <- function(...) {
base::seq(...)
}
Expand Down Expand Up @@ -513,6 +524,6 @@ nVar <- function(x) {
#' Wrapper for sd
#'
#' @export
nSd <- function(x) {
sd(x)
nSd <- function(x) {
sd(x)
}
39 changes: 33 additions & 6 deletions nCompiler/R/compile_aaa_operatorLists.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ returnTypeCodes <- list(
promoteToDoubleOrAD = 6L,
promoteNoLogical = 7L)

liftedBlockOperatorsArg <- c("parallel_for" = 3, "parallel_reduce" = 1) # These are used for flagging when methods in lifted code block will need to have their object reference them explicitly via `obj__.<methodname>`. The values are the argID where the method needs to occur.

returnTypeString2Code <- function(returnTypeString) {
if(is.character(returnTypeString))
do.call('switch', c(list("double"), returnTypeCodes))
Expand Down Expand Up @@ -162,6 +164,16 @@ assignOperatorDef(
)
)

assignOperatorDef(
'nClass_method_in_lifted', # This is used for local method calls in the body of lifted code blocks (currently `parallel_{for,reduce}`).
list(
labelAbstractTypes = list(
handler = 'nFunction_or_method_call'),
cppOutput = list(
handler = 'nClass_method_in_lifted')
)
)

assignOperatorDef(
'custom_default',
list(
Expand Down Expand Up @@ -238,6 +250,10 @@ updateOperatorDef(
c('nMatrix', 'nArray'),
'labelAbstractTypes', 'returnTypeCode', returnTypeCodes$promote
)
updateOperatorDef(
'nMatrix',
'matchDef', val = function(value = 0, nrow = NA, ncol = NA, init = TRUE, fillZeros = TRUE, recycle = TRUE, type = 'double') {}
)

assignOperatorDef(
'type_is',
Expand Down Expand Up @@ -301,20 +317,26 @@ assignOperatorDef(
assignOperatorDef(
c('parallel_for'),
list(
matchDef = function(index, range, body, copyVars, shareVars, nThreads=0) {},
labelAbstractTypes = list(
handler = 'ParallelFor'),
finalTransformations = list(
handler = "ParallelFor") ## Creates GeneralFor in the parallel_loop_body class
handler = "ParallelFor"), ## Creates GeneralFor in the parallel_loop_body class
cppOutput = list(
handler = 'ParallelExpr')
)
)

assignOperatorDef(
c('parallel_reduce'),
list(
list(
matchDef = function(operator, object, init, nThreads=0) {},
labelAbstractTypes = list(
handler = 'ParallelReduce'),
finalTransformations = list(
handler = 'ParallelReduce')
handler = 'ParallelReduce'),
cppOutput = list(
handler = 'ParallelExpr')
)
)

Expand Down Expand Up @@ -554,9 +576,11 @@ assignOperatorDef(
)
),
cppOutput = list(
handler = 'BinaryOrUnary')
handler = 'BinaryOrUnary'),
reduction = 0
)
)
updateOperatorDef('-', 'reduction', val = NULL)

assignOperatorDef(
c('inprod'),
Expand Down Expand Up @@ -603,11 +627,13 @@ assignOperatorDef(
labelAbstractTypes = list(
handler = 'BinaryCwise',
returnTypeCode = returnTypeCodes$promoteNoLogical),
cppOutput = list()
cppOutput = list(),
reduction = Inf
)
)
updateOperatorDef('pairmax', 'cppOutput', 'cppString', 'std::max')
updateOperatorDef('pairmin', 'cppOutput', 'cppString', 'std::min')
updateOperatorDef('pairmax', 'reduction', val = -Inf)

assignOperatorDef(
c('pmin', 'pmax'),
Expand Down Expand Up @@ -984,7 +1010,8 @@ assignOperatorDef(
)
),
cppOutput = list(
handler = 'MidOperator')
handler = 'MidOperator'),
reduction = 1
)
)

Expand Down
3 changes: 2 additions & 1 deletion nCompiler/R/compile_eigenization.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
eigenizeUseArgs <- c(
list(
setWhich = c(FALSE, TRUE),
setRepVectorTimes = c(FALSE, TRUE, TRUE)
setRepVectorTimes = c(FALSE, TRUE, TRUE),
parallel_reduce = c(FALSE, TRUE, TRUE)
))

eigenizeEnv <- new.env()
Expand Down
1 change: 1 addition & 0 deletions nCompiler/R/compile_exprClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ wrapExprClassOperator <- function(code, funName, isName = FALSE, isCall = TRUE,
newExpr
}


insertIndexingBracket <- function(code, argID, index) {
insertExprClassLayer(code, argID, 'index[')
setArg(code$args[[argID]], 2, index)
Expand Down
Loading