Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ gains numeric sum_with_threads #25

Merged
merged 6 commits into from
Dec 16, 2024
Merged

✨ gains numeric sum_with_threads #25

merged 6 commits into from
Dec 16, 2024

Conversation

jibarozzo
Copy link
Contributor

This PR enhances the functionality of the sum_with_threads function to support both integer and double numeric types.

Initially, the approach of handling both types via NumericSexp was considered, but this was not feasible due to the fact that NumericSexp does not implement the to_vec() method, which is necessary for the operation. Following the compiler suggestions, the solution was to use a match expression within sum_with_threads to explicitly handle two distinct types of numeric data: IntegerSexp for integers and RealSexp for doubles. This enables the function to process both types separately via two implementation.

@jibarozzo jibarozzo added the feature a feature request or enhancement label Dec 15, 2024
@jonocarroll
Copy link

I don't know where better to put this - I was curious about the difference between thread and rayon and had a go at building a comparison myself. Rayon seems easier to set up, unless you want to specify the number of threads and re-use a thread pool, but even then it wasn't so bad.

What surprised me was that compared to just doing x.iter().sum() it's a lot more overhead and it's not clear that it's worth it, at least for the 'sum this random data' test case I implemented

> cargo run --release

567270539
Sum with single thread: 56.96µs
567270539
Sum with 2 threads: 229.21µs
567270539
Sum with rayon (2 threads): 173.04µs
567270539
Sum with 4 threads: 185.79µs
567270539
Sum with rayon (4 threads): 101.29µs
567270539
Sum with 8 threads: 229.67µs
567270539
Sum with rayon (8 threads): 276.13µs

Maybe I implemented something wrong - I haven't played with multithreading in Rust before, so this is a great opportunity for me to learn.

Copy link
Member

@jdhoffa jdhoffa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tiny NIT comment on style, but functionally looks great!

I tested this by:

  • Reviewing the added unit test to ensure we are testing for the new behavious
  • Syntactically reviewing the code
  • Pulling and building locally, and testing out the functionality in a live R session

src/rust/Cargo.toml Outdated Show resolved Hide resolved
src/rust/src/lib.rs Outdated Show resolved Hide resolved
@jdhoffa
Copy link
Member

jdhoffa commented Dec 16, 2024

@jonocarroll I extracted your comment into this discussion post for posterity so that we don't lose track of it once this PR is merged 😊 I will respond there.

jibarozzo and others added 2 commits December 16, 2024 13:34
Co-authored-by: Jackson Hoffart <jackson.hoffart@gmail.com>
Co-authored-by: Jackson Hoffart <jackson.hoffart@gmail.com>
@jibarozzo jibarozzo merged commit b0884dc into main Dec 16, 2024
14 checks passed
@jibarozzo jibarozzo deleted the sum_threads_numeric branch December 16, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
Development

Successfully merging this pull request may close these issues.

3 participants