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

[Environment] little Runner refactorings #31

Merged
merged 4 commits into from
Aug 22, 2017

Conversation

mackwic
Copy link
Member

@mackwic mackwic commented Aug 20, 2017

  • Extract rayon initialization
  • Rename inner collections of functions
  • Remove useless _with variants in the Runner

@mackwic mackwic requested a review from regexident August 20, 2017 14:18
@mackwic
Copy link
Member Author

mackwic commented Aug 20, 2017

This will be merged in PR #30 when approved

Copy link
Collaborator

@regexident regexident left a comment

Choose a reason for hiding this comment

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

Looking good.

I just realized that fn run_with(…) does in fact not make any sense. It used to, when Configuration was still passed to it instead of fn new(…). Mea culpa. 😇

}));
let threads = if self.configuration.parallel { 0 } else { 1 }; // 0 is rayon default
let rayon_config = rayon::Configuration::new().num_threads(threads);
let _ = rayon::initialize(rayon_config);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might want to only call rayon::initialize(…) if threads is 1, if it is we might want to check for the function's result and log an error message if appropriate?

/// If you do not call this function, the thread pool
/// will be automatically initialized with the default
/// configuration.

/// Initialization of the global thread pool happens exactly
/// once. Once started, the configuration cannot be
/// changed. Therefore, if you call `initialize` a second time, it
/// will return an error. An `Ok` result indicates that this
/// is the first initialization of the thread pool.

(Source)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Reasoning being that more than a single runner can be created via rspec, each calling into rayon::initialize(…). 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Frankly, I didn't touched it because I don't want to break anything, but I'd much rather don't call rayon at all when parallelism is disabled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

By moving the block within par_iter() into a dedicated method we should be able to simply use an if self.configuration.parallel { … } else { … }. 🤔

@regexident regexident force-pushed the runner_extract_and_rename branch 2 times, most recently from 0dc2019 to c324419 Compare August 21, 2017 09:08
@regexident
Copy link
Collaborator

Commit c324419 removes the need for rayon::initialize(…). 💪

@regexident regexident force-pushed the runner_extract_and_rename branch from 33cb3f7 to cc6d121 Compare August 21, 2017 20:12
@regexident regexident force-pushed the runner_extract_and_rename branch from cc6d121 to 8980978 Compare August 21, 2017 20:17
@regexident regexident merged commit 091cfa5 into environment Aug 22, 2017
@regexident regexident deleted the runner_extract_and_rename branch August 22, 2017 13:22
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.

3 participants