Opened 6 years ago

Closed 5 years ago

#4319 closed feature request (fixed)

Default to all cores for executables compiled with new flag -multicore

Reported by: tim.v2.0 Owned by:
Priority: normal Milestone: 7.4.1
Component: Runtime System Version: 6.12.3
Keywords: Cc: ezyang@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I propose a new flag -multicore, be added to the compiler which will generate an executable that will use all available cores by default. Runtime tuning can remain using the +RTS -Nx -RTS.

Currently, the Haskell wiki shows that you need to both set a compilation flag and a run-time flag to get multi-core support. The compiler flag -threaded is used to enable several disparate behaviors: multi-core support, interact with multi-threaded foreign code and make foreign calls without blocking other Haskell threads. Because of this, it is not always reasonable to use multiple cores for code compiled with -threaded.

Addition of a new flag will tell the compiler, "yes, make code that uses all the cores".

If this is considered too lenient, perhaps it could take an argument. -multicore 50 would use 50% of available cores. -multicore 75 would use 75% of available cores. Etc.

I find Haskell's requirement that I set both compile time and run time flags to use multiple cores obscure and annoying. It is hardly onerous, but it could definitely be improved.

This is filed in response to ticket 4307 being closed. Further, it is filed in response to StackOverflow post

Change History (3)

comment:1 Changed 6 years ago by igloo

Milestone: 7.2.1

comment:2 Changed 6 years ago by ezyang

Cc: ezyang@… added

comment:3 Changed 5 years ago by simonmar

difficulty: Unknown
Resolution: fixed
Status: newclosed

You can do this with -with-rtsopts=-N, and in 7.4 you can also do it programmatically like so:

import GHC.Conc
main = do setNumCapabilities =<< getNumProcessors

Note: See TracTickets for help on using tickets.