From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p82DgHi6028303 for ; Fri, 2 Sep 2011 15:42:17 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgcCABXcYE5N6B+llGdsb2JhbABCqHkBAQEBBwsLCRIogUYBAQQBJxM/BQsLDgonB0YDAQ0GE4dyAgK4IYZlBIdjhFaMAowD X-IronPort-AV: E=Sophos;i="4.68,319,1312149600"; d="scan'208";a="107506543" Received: from fe02x03-cgp.akado.ru (HELO akado.ru) ([77.232.31.165]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Sep 2011 15:42:11 +0200 Received: from [10.0.66.9] ([10.0.66.9] verified) by fe02-cgp.akado.ru (CommuniGate Pro SMTP 5.2.13) with ESMTPS id 228006117; Fri, 02 Sep 2011 17:42:10 +0400 Date: Fri, 2 Sep 2011 17:42:04 +0400 (MSD) From: malc X-X-Sender: malc@linmac To: David Allsopp cc: "caml-list@inria.fr" In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: RE: [Caml-list] Cross-platform cpu count On Fri, 2 Sep 2011, David Allsopp wrote: > malc wrote: > > On Fri, 2 Sep 2011, David Allsopp wrote: > > > > > malc wrote: > > > > On Fri, 2 Sep 2011, Daniel B?nzli wrote: > > > > > > > > > Hello, > > > > > > > > > > Can anybody confirm me that the following code works on cygwin : > > > > > > It won't - Sys.os_type returns "Cygwin" and getconf isn't in Cygwin > > > either - http://cygwin.com/ml/cygwin/2010-12/msg00435.html (actually, > > > it may be now - I haven't upgraded my Cygwin in a while - but it'll be > > > a recent addition) > > > > > > > > > > > > > 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 > > > > > > > > > > Thanks, > > > > > > > > > > > > > > > http://repo.or.cz/w/apc.git/blob/55de75ccb853f5e4443fd484e5eb95e1342e72bd > > : > > > > /ml_apc.c > > > > > > The C code here uses a deprecated API call (probably for Windows NT 4 > > > compatibility). If you do end up using a C stub, use GetSystemInfo > > > (http://msdn.microsoft.com/en-us/library/ms724381(v=vs.85).aspx) - > > > it's easier to call. It's used in the OCaml runtime - see > > byterun/win32.c. > > > Personally, even for something where it's unimportant, I'd be nervous > > > relying on an environment variable (which can be edited...) > > > > Uhm, no, it uses native API which was never publically documented to > > begin with, and the reason for that that it provides other information > > which is unavailable via other means. > > It is documented and it is deprecated for this usage (see > http://msdn.microsoft.com/en-us/library/ms725506(v=VS.85).aspx) making > it a poor example for the specific question of querying logical > processor count. Well, okay, not however that the substitute for SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION is only available starting with XP SP1, in any case the times provided by the kernel are wrong anyway. All that said, Get[Native]SystemInfo (possibly with GetLogicalProcessorInfomration[Ex]) is better in this particular case. -- mailto:av1474@comtv.ru