From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p82D5nfR026916 for ; Fri, 2 Sep 2011 15:05:49 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqsAAF7UYE5RZ90xkWdsb2JhbABCqGYUAQEBAQkLCwcUAyOBRgEBAQEDJxM/EAIBCBgKFBAyFwENAgQODYdsArdAhgVgBJMskQ0 X-IronPort-AV: E=Sophos;i="4.68,319,1312149600"; d="scan'208";a="118134140" Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]) by mail1-smtp-roc.national.inria.fr with ESMTP; 02 Sep 2011 15:05:34 +0200 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20110902130532.BLAA17535.mtaout03-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com>; Fri, 2 Sep 2011 14:05:32 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20110902130532.XXJQ20122.aamtaout01-winn.ispmail.ntl.com@romulus.metastack.com>; Fri, 2 Sep 2011 14:05:32 +0100 Received: from remus.metastack.local ([172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id p82D5TWs029924 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Fri, 2 Sep 2011 14:05:29 +0100 Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%10]) with mapi id 14.01.0289.001; Fri, 2 Sep 2011 14:05:28 +0100 From: David Allsopp To: malc CC: "caml-list@inria.fr" Thread-Topic: [Caml-list] Cross-platform cpu count Thread-Index: AQHMaQQCqL9GVMyRy0ygM7NDJZwvBJU5Ln4AgACCAFCAAEq+AIAAEYNg Date: Fri, 2 Sep 2011 13:05:27 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.0.7] Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=R50lirqlHffDPPkwUlkuVa99MrvKdVWo//yz83qex8g= c=1 sm=0 a=40hZHaDki8MA:10 a=AdGk3VER0UgA:10 a=cTs9vV391PwA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=w_pzkKWiAAAA:8 a=-AnQz9JOAAAA:8 a=yMhMjlubAAAA:8 a=ZS5TmDaz3WYv6PGVWKcA:9 a=CjuIK1q_8ugA:10 a=EVxY3BY4UIsA:10 a=QWS9I09t1warGvE_:21 a=cICbRGl8AvCsBt8u:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p82D5nfR026916 Subject: RE: [Caml-list] Cross-platform cpu count 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. David