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
Threads #2130
Threads #2130
Conversation
What if you made it a run time parameter, say -j N? You'd then specify it when calling the executable if you want anything other than the default. |
|
Currently we need to recompile everything to change this, yes. Unfortunately everything else is more complicated, because when parsing our runtime parameters we already need information about the MPI communicator (e.g. -h only outputs on process 0) so MPI_InitFinalize needs to be called before parsing runtime parameters. I could delay executing these commands (and only set a flag when parsing), but that makes the whole parsing code more complicated. Do you have an idea how to work around this? If this breaks PETSc I should probably add a check to CMakeLists that not both are active at the same time. |
So this means it is more annoying to switch than editing main.cc. Hrm.
Hang on: we have an environment variable Wouldn't that be enough? This means we would need to set the value to invalid_unsigned_int for the command line value to work. |
Hmm, I tried exporting DEAL_II_NUM_THREADS=1 and that indeed limits the number of threads to 1. But can we set this environment variable by default to 1? I would like to keep the current behavior (threading disabled until somebody explicitly enables it). Mostly to follow the principle of least surprise to the user. Or do you think we should just enable this by default? I could also ask around on the mailing list what people think about the feature. |
Not easily. Either we enable by default (I don't think this will be a problem) or safer:
|
Yes that seems to work. I like this solution, it is easy for people to set this if they want to, and everything stays as usual if you do nothing. |
I'd still like to advocate for a command line option You can parse command line options before you initialize the MPI system. |
I reorganized main() to parse the command line parameters before MPI initialization and made the parameter a command line option. Looks nicer and more intuitive now. I also removed the print_version() function as all of that information is in the header now and removed some duplication by introducing a new template function. Let's see what the tester says. Anything else? (I will follow up with a PR that further cleans main(), but that is unrelated). |
One of the test fails by producing different output. I haven't looked at the code yet, but suspect you have something like
To restore the previous error (and help the user a bit), just replace the assertion by
Since we're in the |
doc/manual/manual.tex
Outdated
loss you will see in these situations. | ||
|
||
Multithreading is controlled by setting the command line parameter \texttt{-j} | ||
or \texttt{--threads}. If the parameter is not set \aspect{} will create |
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.
comma after "set"
doc/manual/manual.tex
Outdated
Multithreading is controlled by setting the command line parameter \texttt{-j} | ||
or \texttt{--threads}. If the parameter is not set \aspect{} will create | ||
exactly one thread per MPI process, i.e. multithreading is disabled. Appending | ||
it will automatically spawn several threads per MPI process (a typical example |
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.
what is "it" here?
doc/manual/manual.tex
Outdated
exactly one thread per MPI process, i.e. multithreading is disabled. Appending | ||
it will automatically spawn several threads per MPI process (a typical example | ||
is ``2''). Note that the internally used TBB library will determine the number | ||
of threads as a reasonable number, i.e. if you start with 2~MPI processes on a |
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.
comma after "i.e."
source/main.cc
Outdated
<< " --help (for this usage help)" | ||
<< " -h, --help (for this usage help)" | ||
<< std::endl | ||
<< " -j, --threads (to use multi-threading)" |
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.
keep -h
at either the top of the bottom of the list.
source/main.cc
Outdated
default: | ||
AssertThrow((dim >= 2) && (dim <= 3), | ||
AssertThrow(false, | ||
ExcMessage ("ASPECT can only be run in 2d and 3d but a " | ||
"different space dimension is given in the parameter file.")); |
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.
This is where the difference in output comes from. I'd say to just revert to the previous condition -- I know it's duplicative, but it's also instructive.
flow_problem.run(); | ||
} | ||
|
||
run_simulator<3>(input_as_string,output_xml,output_plugin_graph); |
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.
nice simplification of code repetition
Done 😄. |
OK to merge once the tester is happy. |
Implements #59. I decided to make it a cmake variable instead of a input parameter, because we need the value right at the beginning of main.cc:main() before even initializing anything, and we do not know the name of the parameter file at that time. Unfortunately now we need to recompile if we want to change the setting, but at least it is user-controllable. Is this an acceptable solution?