Opened 5 years ago

Closed 4 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 Revisions:

Description

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 http://stackoverflow.com/questions/3704430/why-do-you-have-to-use-both-a-compiler-flag-and-a-run-time-flag-to-get-multicore

Change History (3)

comment:1 Changed 5 years ago by igloo

  • Milestone set to 7.2.1

comment:2 Changed 5 years ago by ezyang

  • Cc ezyang@… added

comment:3 Changed 4 years ago by simonmar

  • difficulty set to Unknown
  • Resolution set to fixed
  • Status changed from new to closed

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.