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

Add Support for Parallelization Using Rayon Library #72

Closed
soumyasen1809 opened this issue Sep 30, 2024 · 4 comments
Closed

Add Support for Parallelization Using Rayon Library #72

soumyasen1809 opened this issue Sep 30, 2024 · 4 comments

Comments

@soumyasen1809
Copy link
Contributor

Hi @Axect ,

I want to know if you are interested or have any plans regarding adding support for parallelization. The Rayon library can be used for that. I have been playing around with parallelizing some methods in this library. Although I have not benchmarked the results, this might be a nice option to have. What do you think?

Some methods can be easily parallelized, while some might require special algorithms. For example:

OLD:
pub fn col(&self, index: usize) -> Vec<f64> {
        assert!(index < self.col);
        let mut container: Vec<f64> = vec![0f64; self.row];
        for i in 0..self.row {
            container[i] = self[(i, index)];
        }


NEW:
pub fn col(&self, index: usize) -> Vec<f64> {
        assert!(index < self.col);
        let container = (0..self.row)
            .into_par_iter()
            .map(|i| self[(i, index)])
            .collect::<Vec<f64>>();
        container
    }

If you have a new branch for this item where I can push my changes, please let me know. Maybe it will give you a better overview.

@Axect
Copy link
Owner

Axect commented Sep 30, 2024

Thank you for your interest in improving Peroxide with parallelization. I appreciate your suggestion and the example code you provided. Here are my thoughts on this:

  1. I agree that Rayon is an excellent parallel computing library that I use frequently as well.

  2. There are likely many functions in Peroxide that could benefit from parallelization using Rayon, potentially leading to significant performance improvements.

  3. However, I have some concerns about directly replacing the default implementations with parallel versions. This could potentially cause issues for users who need to perform more critical parallel computations.

  4. To address this, I suggest we use different method names for the parallel versions, rather than overriding the existing ones.

  5. An interesting approach could be to implement a separate trait for parallel computing, such as a ParallelMatrix trait. This could include methods like par_col, par_row, etc.

  6. What are your thoughts on this approach? I find your proposal very intriguing and believe we could develop it further through discussion.

If you'd like to contribute to this, I can create a new branch for you to push your changes. This would allow us to review and iterate on the implementation together. Let me know if you're interested in proceeding this way.

@soumyasen1809
Copy link
Contributor Author

Hi @Axect

  1. However, I have some concerns about directly replacing the default implementations with parallel versions. This could potentially cause issues for users who need to perform more critical parallel computations.

I agree with this one.

  1. To address this, I suggest we use different method names for the parallel versions, rather than overriding the existing ones.
  2. An interesting approach could be to implement a separate trait for parallel computing, such as a ParallelMatrix trait. This could include methods like par_col, par_row, etc.
  3. What are your thoughts on this approach? I find your proposal very intriguing and believe we could develop it further through discussion.

I was thinking - we can also have like a feature=parallel thing and have the parallel implementation behind the feature. One disadvantage with this is however that once the feature is enabled, all the computations will be in parallel. So, the user can not choose which parts to run in parallel and which not to.
However, your solution seems better and more flexible for the user.

If you'd like to contribute to this, I can create a new branch for you to push your changes. This would allow us to review and iterate on the implementation together. Let me know if you're interested in proceeding this way.

Yes, please create a branch for this and share it with me. I can push my current changes there.

@Axect
Copy link
Owner

Axect commented Sep 30, 2024

Thank you for your feedback and interest in contributing to this parallelization effort. I appreciate your thoughts on the different approaches we could take.

I've created a new branch for this feature. The branch is named:

72-add-support-for-parallelization

You can now push your current changes to this branch. This will allow us to review the implementation together and iteratively improve it.

I look forward to seeing your work and discussing further how we can best implement parallelization in Peroxide. Please let me know if you need any assistance with accessing the branch or have any questions as you proceed with your contributions.

@soumyasen1809
Copy link
Contributor Author

Hi @Axect
I have a PR for an initial discussion. ( See #74 )
There is still quite left to be parallelized. I have only done a part of it (and the low-hanging items)

Axect added a commit that referenced this issue Oct 31, 2024
- complex support (#35)
- parallel support (#72)
- More generic matrix
- Update puruspe
- Add some polynomials
Axect added a commit that referenced this issue Oct 31, 2024
- complex support (#35)
- parallel support (#72)
- More generic matrix
- Update puruspe
- Add some polynomials
@Axect Axect closed this as completed Oct 31, 2024
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

When branches are created from issues, their pull requests are automatically linked.

2 participants