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 p827dnkE014596 for ; Fri, 2 Sep 2011 09:39:49 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArYAAFyHYE5RZ90vkWdsb2JhbABCp2hxFAEBAQEJCwsHFAMjgUYBAQEBAydiAgEIGAokMhcBDQIEG4dsArdphgVgBIc6i3KRDA X-IronPort-AV: E=Sophos;i="4.68,317,1312149600"; d="scan'208";a="107459913" Received: from mtaout01-winn.ispmail.ntl.com ([81.103.221.47]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Sep 2011 09:39:43 +0200 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20110902073942.OLIS9871.mtaout01-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Fri, 2 Sep 2011 08:39:42 +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 <20110902073942.URTT20122.aamtaout01-winn.ispmail.ntl.com@romulus.metastack.com> for ; Fri, 2 Sep 2011 08:39:42 +0100 Received: from remus.metastack.local ([172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id p827ddLI028238 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL) for ; Fri, 2 Sep 2011 08:39:39 +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 08:39:38 +0100 From: David Allsopp To: "caml-list@inria.fr" Thread-Topic: [Caml-list] Cross-platform cpu count Thread-Index: AQHMaQQCqL9GVMyRy0ygM7NDJZwvBJU5Ln4AgACCAFA= Date: Fri, 2 Sep 2011 07:39:36 +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.11] Content-Type: text/plain; charset="iso-8859-1" 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=oL5oDnsraXEA:10 a=AdGk3VER0UgA:10 a=cTs9vV391PwA:10 a=8nJEP1OIZ-IA:10 a=xqWC_Br6kY4A:10 a=w_pzkKWiAAAA:8 a=-AnQz9JOAAAA:8 a=yMhMjlubAAAA:8 a=nuRFzWJcpOH3r7WDV3EA:9 a=wPNLvfGTeEIA:10 a=EVxY3BY4UIsA:10 a=HAT99K0pjeerP17S:21 a=h3OV6-cMmLAS4SMz:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p827dnkE014596 Subject: RE: [Caml-list] Cross-platform cpu count 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...) David