-
Notifications
You must be signed in to change notification settings - Fork 82
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
[FIX] make a bgzf_thread_count a single variable #2752
[FIX] make a bgzf_thread_count a single variable #2752
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/seqan/seqan3/9deSNYGGQRf4KqYobzvAM3US4DQM |
223728b
to
0c3c2f2
Compare
Codecov Report
@@ Coverage Diff @@
## master #2752 +/- ##
==========================================
- Coverage 98.28% 98.28% -0.01%
==========================================
Files 267 266 -1
Lines 11462 11455 -7
==========================================
- Hits 11265 11258 -7
Misses 197 197
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Seqan2 "solves" this by using a macro/define instead of a global variable. iostream_bgzf.h defines
And then it is similar used similar to seqan3:
|
Core Meeting 25.10.2021 - This is not release critical. |
@@ -38,7 +38,7 @@ namespace seqan3::contrib | |||
/*!\brief A static variable indicating the number of threads to use for the bgzf-streams. | |||
* Defaults to std::thread::hardware_concurrency. | |||
*/ | |||
inline static uint64_t bgzf_thread_count = std::thread::hardware_concurrency(); | |||
inline uint64_t bgzf_thread_count = std::thread::hardware_concurrency(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a hybrid idea: Use SeqAn 2 solution with macro:
#ifndef SEQAN3_BGZF_THREAD_COUNT
#define SEQAN3_BGZF_THREAD_COUNT (std::thread::hardware_concurrency())
#define SEQAN3_BGZF_THREAD_COUNT (bgzf_thread_count)
#endif // SEQAN3_BGZF_THREAD_COUNT
basic_bgzf_streambuf(ostream_reference ostream_,
size_t numThreads = SEQAN3_BGZF_THREAD_COUNT,
size_t jobsPerThread = 8) :
This allows:
- having consistent definition over all translation unit
- making it configurable to a fixed number, to a function, to anything that reduces to a number
- AND: It is a hack and will always be a hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it some thought, but this doesn't really work.
The issue is if I declare -DSEQAN3_BGZF_THREAD_COUNT=(std::thread::hardware_concurrency())
It is required that the header includes #include <thread>
. Same goes if I want to use a user defined variable.
It would require that other headers are being included before. I don't see the advantages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with static: each translation unit gets it's own variable.
- you have to set it in each unit, cannot alter it globally
+ you can alter it for each unit
without static:
+ you set it globally
- different compilation unit cannot use different values
- if you set the variable in multiple places, the compiler chooses the variable at random
@marehr friendly reminder. Would you like to clarify this please? If I see correctly, this change means that I no longer unintentionally occupy all threads on the server with iGenVar, although I have specified much less. |
0c3c2f2
to
646a685
Compare
Core meeting 06.12.2021 - The common use case is that you want the same variable across your translation units. So removing |
bgzf_thread_count was declared `inline static` outside of the scope of a class. In this case the `inline` allows the variable to break the one definition rule. Meaning there can be multiple symbols across different translation that all declare `bgzf_thread_count`. In this case the linker will choose one of the defined symbols. (Without inline it would throw a multiple definition error). The `static` keyword (in this context) means that the created symbol is only visible inside a current translation unit. Meaning, there are no symbols for the linker to work with. This will cause every translation unit to have there own `bgzf_thread_count` variable. This combination leads to every translation unit having there own `bgzf_thread_count` variable, which is not what a user of seqan3 expects. The fix is simple, we remove the `static` keyword. This should have the intended behavior. Thought: maybe it should be declared `thread_local`.
b778975
to
1ec1bba
Compare
bgzf_thread_count was declared
inline static
outside of the scope of aclass.
In this case the
inline
allows the variable to break the onedefinition rule. Meaning there can be multiple symbols across different
translation that all declare
bgzf_thread_count
. In this case thelinker will choose one of the defined symbols. (Without inline it would
throw a multiple definition error).
The
static
keyword (in this context) means that the created symbol isonly visible inside a current translation unit. Meaning, there are no symbols
for the linker to work with. This will cause every translation unit to have there
own
bgzf_thread_count
variable.This combination leads to every translation unit having there own
bgzf_thread_count
variable. The fix is simple, we remove thestatic
keyword. This should have the intended behavior.