Skip to content

[MISC] Config parallel with member thread_count - #1917

Merged
smehringer merged 6 commits into
seqan:masterfrom
joergi-w:config_parallel
Jun 26, 2020
Merged

[MISC] Config parallel with member thread_count#1917
smehringer merged 6 commits into
seqan:masterfrom
joergi-w:config_parallel

Conversation

@joergi-w

@joergi-w joergi-w commented Jun 17, 2020

Copy link
Copy Markdown
Member

This PR adds a member variable thread_count to the parallel config (it replaces the old value member). It influences both seqan3::align_cfg::parallel and seqan3::search_cfg::parallel.

Documentation and tests are included in the second commit.

Closes seqan/product_backlog#68 and contributes to seqan/product_backlog#131.

@joergi-w
joergi-w requested review from a team and simonsasse and removed request for a team June 17, 2020 11:22
@codecov

codecov Bot commented Jun 17, 2020

Copy link
Copy Markdown

Codecov Report

Merging #1917 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #1917    +/-   ##
========================================
  Coverage   97.76%   97.76%            
========================================
  Files         253      258     +5     
  Lines        9560     9684   +124     
========================================
+ Hits         9346     9468   +122     
- Misses        214      216     +2     
Impacted Files Coverage Δ
...clude/seqan3/alignment/pairwise/align_pairwise.hpp 100.00% <100.00%> (ø)
.../algorithm/configuration_element_parallel_mode.hpp 100.00% <100.00%> (ø)
.../seqan3/alignment/pairwise/alignment_algorithm.hpp 98.50% <0.00%> (-1.50%) ⬇️
include/seqan3/range/views/drop.hpp 100.00% <0.00%> (ø)
include/seqan3/io/stream/iterator.hpp 98.55% <0.00%> (ø)
include/seqan3/range/views/repeat.hpp 100.00% <0.00%> (ø)
include/seqan3/alphabet/nucleotide/dna4.hpp 100.00% <0.00%> (ø)
include/seqan3/core/detail/debug_stream_tuple.hpp 100.00% <0.00%> (ø)
...ude/seqan3/alignment/pairwise/alignment_result.hpp 100.00% <0.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f799c0...068f50a. Read the comment docs.

//!\}

//!\brief The maximum number of threads the algorithm can use.
uint32_t thread_count{1u};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Question: Do we want std::thread::hardware_concurrency as a default here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm good question. I would vote for yes. I'll ask @seqan/core

@simonsasse simonsasse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the explanation ! Just found two lines which are slightly too long. :)

Comment thread test/unit/alignment/configuration/align_config_parallel_test.cpp Outdated
Comment thread test/unit/alignment/configuration/align_config_parallel_test.cpp Outdated
@joergi-w
joergi-w requested a review from simonsasse June 22, 2020 11:18
@joergi-w

Copy link
Copy Markdown
Member Author

Rebased on master.

@simonsasse simonsasse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks :)

@joergi-w
joergi-w requested review from a team and smehringer and removed request for a team June 24, 2020 07:08

@smehringer smehringer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some small stuff :)

Comment on lines +43 to +45
* \param[in] thread_c The maximum number of threads to be used by the algorithm.
*/
explicit parallel_mode(uint32_t thread_c) noexcept : thread_count{thread_c}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* \param[in] thread_c The maximum number of threads to be used by the algorithm.
*/
explicit parallel_mode(uint32_t thread_c) noexcept : thread_count{thread_c}
* \param[in] thread_count_ The maximum number of threads to be used by the algorithm.
*/
explicit parallel_mode(uint32_t thread_count_) noexcept : thread_count{thread_count_}
:nail_care:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok!

Comment on lines +37 to +39
parallel_mode(parallel_mode &&) noexcept = default; //!< Defaulted.
parallel_mode & operator=(parallel_mode const &) = default; //!< Defaulted.
parallel_mode & operator=(parallel_mode &&) noexcept = default; //!< Defaulted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
parallel_mode(parallel_mode &&) noexcept = default; //!< Defaulted.
parallel_mode & operator=(parallel_mode const &) = default; //!< Defaulted.
parallel_mode & operator=(parallel_mode &&) noexcept = default; //!< Defaulted.
parallel_mode(parallel_mode &&) = default; //!< Defaulted.
parallel_mode & operator=(parallel_mode const &) = default; //!< Defaulted.
parallel_mode & operator=(parallel_mode &&) = default; //!< Defaulted.

or did you define this on purpose? because usually for = default constructors this is added automatically.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added noexcept on purpose, because when I left it away, CLion told me:

Clang-Tidy: Move constructors should be marked noexcept.
Clang-Tidy: Move assignment operators should be marked noexcept.

If it's our policy I can remove them now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes :)
See here: https://en.cppreference.com/w/cpp/language/noexcept_spec that they are noexcept if they can.

//!\}

//!\brief The maximum number of threads the algorithm can use.
uint32_t thread_count{1u};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm good question. I would vote for yes. I'll ask @seqan/core

Comment thread include/seqan3/search/configuration/all.hpp
@rrahn

rrahn commented Jun 24, 2020

Copy link
Copy Markdown
Contributor

What should be the default thread count if the user does not specifies anything?

Resolution 24.06.2020

The option should default to std::nullopt if default constructed and throws in the configuration if not set by the user explicitly.

@joergi-w

Copy link
Copy Markdown
Member Author

I cannot assign std::nullopt to a uint32_t type. A solution is to make the thread_count variable of type std::optional<uint32_t> and then we have to access the variable as config.thread_count.value or config->thread_count. Is this intended or do you have another solution in mind?

@eseiler

eseiler commented Jun 24, 2020

Copy link
Copy Markdown
Member

I cannot assign std::nullopt to a uint32_t type. A solution is to make the thread_count variable of type std::optional<uint32_t> and then we have to access the variable as config.thread_count.value or config->thread_count. Is this intended or do you have another solution in mind?

Yes, std::optional was the intention

@joergi-w
joergi-w requested a review from smehringer June 25, 2020 07:31

@smehringer smehringer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

two small things. thanks for the change to std::optional

Comment on lines +53 to +55
else if constexpr (std::same_as<type_param_t, seqan3::align_cfg::parallel>)
{
auto && config = cfg | type_param_t{};
auto && config = cfg | seqan3::align_cfg::parallel{4};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

type_param_t is either void or seqan3::align_cfg::parallel, because we want to test the serial and the parallel version. And if it is parallel, we do not want to use the default initialisation, because half of the tests would fail with the std::bad_optional_access exception. So I initialise the parallel tests with 4.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you for the explanation :)

Comment on lines 191 to 193
return execution_handler_t{get<align_cfg::parallel>(complete_config).thread_count.value()};
else
return execution_handler_t{};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return execution_handler_t{get<align_cfg::parallel>(complete_config).thread_count.value()};
else
return execution_handler_t{};
{
if (!get<align_cfg::parallel>(complete_config).thread_count.has_value())
throw std::runtime_error{"You must configure the number of threads in seqan3::align_cfg::parallel."};
return execution_handler_t{get<align_cfg::parallel>(complete_config).thread_count.value()};
}
else
{
return execution_handler_t{};
}

I think this will be more easy to understand for the user than a std::bad_optional_acces ?
Maybe rephrase the sentence, it's just a proposal :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I like this suggestion :)

@joergi-w
joergi-w requested a review from smehringer June 25, 2020 14:52
@smehringer
smehringer merged commit 39ee4a2 into seqan:master Jun 26, 2020
@joergi-w
joergi-w deleted the config_parallel branch June 30, 2020 08:39
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.

search configuration parallel

5 participants