Skip to content

Fix and extend parallel_reduce functionality#141

Open
paciorek wants to merge 11 commits intomainfrom
tbb-reduce
Open

Fix and extend parallel_reduce functionality#141
paciorek wants to merge 11 commits intomainfrom
tbb-reduce

Conversation

@paciorek
Copy link
Copy Markdown
Contributor

This addresses various aspects of parallel_reduce, with a fair amount of testing. I generally tried to work within the system, but there may be cases where @perrydv may think we should do it differently or at a different stage.

  • This enables built-in reduction operators of +, *, pairmin, pairmax, with error trapping for use of other nCompiler operators.
  • The init arg is now optional, and default values are built into the handler lists, via reduction = <some_init>. The existence of this is used for error trappling for valid reduction operators (perhaps this is trying to be too concise by combining the idea of a valid operator with the default init).
  • The output type is determined from the type of the input vector (2nd arg). Perry's original code used the type of the init value. And Perry and Chris discussed generating dummy code: reduction_op(x,y) to determine type, but it seemed most natural to me to use the type of the vector.
  • User-defined reduction operators now work when provided as nFunctions (but not as other methods of the same class [see issue 133]). If no init is provided by the user we error trap. I have not tested having a user-defined operator in which the default init is provided.
  • I've added some additional checking for uncompiled execution but there are problably corner cases.
  • Inf and negative values for initial value now works.
  • A user can provide the user-defined reduction function either as a char or as a function. In principle this would be fine for non-user-defined but there are no R pairmin/pairmax functions.
  • Some work was needed to fix up C++ generation of the join for various situations.
  • Use of parallel_reduce in a standalone nFunction is trapped, but in an awkward stage and awkward way.

The following are still issues:

  • Using a method of another class as the reduction operator does not work.
  • For min/max, one needs to use pair{min,max} as these are the actual relevant binary operators. We should discuss if we want to automatically convert {min,max} to these for the user.
  • Per issue using expressions as the input vector in parallel_reduce #137 , using an expression as the input vector does not work.
  • Per issue type awkwardness with parallel_reduce #136 there are still some type issues when using integer types.
  • Should we rename to parallelReduce for consistency with other user-facing naming?

paciorek and others added 11 commits March 11, 2026 10:18
- handling user-defined reduction functions
- error-trapping non-user defined invalid reduction functions
- setting default init values
- fixing up handling of inf and negative init values
- allowing a user to specify the reduction fun as char or actual function.
…ts are contained in private, and packaged names can be managed (#125)

* initial redesign of nClass to hold a private Cpublic_obj and use it by active bindings

* Add basic nClass_uncompiled tests

* major work towards redesigning nClass generation and hierarchy

* fix C++ handling (Exporter and generic interface set) of new nClass structure

* close to finished with updated class naming issues within packages

* updated tests after new packingNames and nCompile naming schemes

* update predefineds. fix nimbleModels. fix package class generation with R fields.

* fix StridedTensorMap operator() for single index

* fix cpp_tests crash

* test trials

* give each case in test-argumentPassing unique package naming

* Fix test-tensorCreation for old style
Also handle missing shareVars or copyVars args.
Also handle use of external object in parallel_for.
parallel_loop_body cases a unique ID.
This addresses problems with different parfors in different methods of a class.
- allow multiple parallel_reduce operations
- handle local method as the reduction operator.
- use without assignment or in return()
- use in return()
- multiple calls to parallel_reduce at same level of AST.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants