Created
December 9, 2016 22:49
-
-
Save ryanrhymes/3d9eabec18b9d7fd8140b235fff06f4b to your computer and use it in GitHub Desktop.
number of cores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cpu_count () = | |
try match Sys.os_type with | |
| "Win32" -> int_of_string (Sys.getenv "NUMBER_OF_PROCESSORS") | |
| _ -> | |
let i = Unix.open_process_in "getconf _NPROCESSORS_ONLN" in | |
let close () = ignore (Unix.close_process_in i) in | |
try Scanf.fscanf i "%d" (fun n -> close (); n) with e -> close (); raise e | |
with | |
| Not_found | Sys_error _ | Failure _ | Scanf.Scan_failure _ | |
| End_of_file | Unix.Unix_error (_, _, _) -> 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment