How to find the number of cores at runtime in Haskell

前端 未结 5 871
终归单人心
终归单人心 2021-02-13 06:16

Does Haskell have a method for determining the number of CPU cores present on a machine at runtime?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 06:32

    Yes, there is such a method. Code from "Real World Haskell": http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html

    import GHC.Conc (numCapabilities)
    
    main = putStrLn $ "number of cores: " ++ show numCapabilities
    

提交回复
热议问题