Open mikeheddes opened 5 years ago
Hi Mike,
piranha's thread pool is automatically created at program startup. You can disable the use of multithreading after program startup using the set_n_threads()
function, but currently there is no way of avoiding the initial creation of the pool.
I am not opposed to adding a build system option to completely disable multithreading, but I currently do not have the bandwidth to do it myself. The code changes that would be required should not be too hard, because the thread pool is used only (I think) during series multiplication, and eliminating the use of any function from the thread_pool
class should be enough to prevent the initial creation of the global pool.
I can provide you assistance if you decide to go down this road, you can ping me over on the gitter channel:
To expand a bit, the thread pool code is here:
https://github.com/bluescarni/piranha/blob/master/include/piranha/thread_pool.hpp
The inclusion of this header and the use of at least one of its methods will trigger the creation of the global thread pool on startup. In order to make a single-threaded option for piranha, you'd need to look in the source code for all uses of the thread pool class and replace them with serial code bracketed in #if defined(PIRANHA_SINGLE_THREAD)
(or similar).
Hi Francesco, Thanks for your comment. I will try to add the define flags. I'm fairly new to C++ so it might take some time. If I get stuck I will contact you on the gitter channel. Thanks.
I managed to compile piranha single threaded. It was indeed not hard, adding a PIRANHA_SINGLE_THREAD
flag in some files was enough.
I will add the CMake configuration and prepare a pull request.
Note that since dcgp depends on piranha v0.11 I branched from the v0.11 tag. I'm not sure what you have in mind for the PR, which branch it should be merged with, master or other.
@mikeheddes yes, this option should be applied to the stable (0.11) branch. There's a couple of fixes I would like to make to the stable branch as well, so perhaps we can make a 0.12 release.
I'm working on a project within the ACT at ESA for which I try to compile dcgp to WebAssembly with Emscripten. I managed to compile all its dependencies and create a .wasm file which I can use in the browser (see main issue #10). But when running code that uses piranha's polynomial computation it throws an error because it tries to run on multiple threads and WebAssembly by default currently only supports single threaded code.
This error can be resolved by enabling the experimental
#enable-webassembly-threads
flag in chrome://flags (see this comment) but that is not a reasonable solution to ask of the users. A better solution until multi-threading is supported by most browsers by default would be to only use the main thread.I tried using piranha's settings to make piranha run single-threaded:
Which gives a similar error as before:
I think that setting the threads to 1 still creates one thread separate to the main thread. Setting the threads to 0 results in an exception by the piranha implementation.
Is there a way to make piranha single-threaded? And how would that be?
I'm thinking of adding a flag like
THREADING
which can be set in cmake and isON
by default to maintain the current implementation and could be switched toOFF
to disable the threading code and adds the single-threaded alternative.