Re: [fpc-pascal] number of cpu cores
2008/12/14 Marc Weustink m...@dommelstein.net: Mattias Gaertner wrote: At the moment I have the attached function. It returns only 4 on a 2 x quad core Mac. Maybe someone can test under windows? Return 2 on Intel Core Duo -- Inoussa O. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
On 12/13/2008 11:17 AM, Mattias Gaertner wrote: On Sat, 29 Nov 2008 19:14:39 +0100 (CET) mar...@stack.nl (Marco van de Voort) wrote: In our previous episode, Michalis Kamburelis said: [ Charset ISO-8859-1 unsupported, converting... ] Florian Klaempfl wrote: Mattias Gaertner schrieb: I need a default value of the number of maximum threads. Is there already some RTL function that can be used for that? For example if the program runs on a 2 x quad core it would be nice to get 8. Hyperthreading multipliers should be applied. No, but having some functions returning information about the CPUs would be nice. Blender (http://www.blender.org/) source code has function to do that (they needed this to set the default number of threads for renderer). So you could try converting to Pascal the code of BLI_system_thread_count function from: https://svn.blender.org/svnroot/bf-blender/trunk/blender/source/blender/blenlib/intern/threads.c Doesn't seem that complicated on 1st look. It's basically appropriate GetSystemInfo call on Windows, sysctl on Mac OS, and sysconf (from Libc) call on most Unixes. Sysconf is not standarized yet. Unit libc is linux/x86 only. On freebsd, the sysctl modeled works, but note the typecast. (probably a KR void*- char* problem) uses ctypes,sysctl; var mib : array[0..1] of cint; len:cint; t :cint; begin mib[0] := CTL_HW; mib[1] := HW_NCPU; len := sizeof(t); fpsysctl(pchar(@mib), 2, @t, @len, Nil, 0); writeln(t); // prints 2 on our dual CPU (Athlon MPs) end. Thanks for all the hints. At the moment I have the attached function. It returns only 4 on a 2 x quad core Mac. Maybe someone can test under windows? Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal I tested this out on my Windows 7-based laptop (running the 64 bit edition) and this is what I get: E:\lazarusppcx64 test Free Pascal Compiler version 2.2.2 [2008/10/05] for x86_64 Copyright (c) 1993-2008 by Florian Klaempfl Target OS: Win64 for x64 Compiling test.pas Linking test.exe 7 lines compiled, 0.6 sec , 39984 bytes code, 1648 bytes data E:\lazarustest 2 CPUs online. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
Mattias Gaertner wrote: At the moment I have the attached function. It returns only 4 on a 2 x quad core Mac. Maybe someone can test under windows? returns 4 on a quadcore xp64 Marc ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
Mattias Gaertner schrieb: I need a default value of the number of maximum threads. Is there already some RTL function that can be used for that? For example if the program runs on a 2 x quad core it would be nice to get 8. Hyperthreading multipliers should be applied. If we implement something like this, I propose we do it properly. There are different numbers important: - numa nodes - physical cpus - cache sharing cores - logical/execution unit sharing cores Which one are considered important? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
On 30 Nov 2008, at 18:15, Florian Klaempfl wrote: Mattias Gaertner schrieb: I need a default value of the number of maximum threads. Is there already some RTL function that can be used for that? For example if the program runs on a 2 x quad core it would be nice to get 8. Hyperthreading multipliers should be applied. If we implement something like this, I propose we do it properly. There are different numbers important: - numa nodes - physical cpus - cache sharing cores - logical/execution unit sharing cores - Completely different kinds of cores, e.g., on the Cell you have a hyper-threaded ppc64 and 6 to 8 available SPU vector processors. - And then there's stuff like CUDA (and its Open* variant) coming up, of course. Which one are considered important? I personally don't think it's possible to generally deal with this at the application level, there's too much variety and complexity. It's also only going to get worse in the future, as reconfigurable computing is a very hot topic. And so are heterogenous multicores, and not just the Cell way; e.g. different cores implementing the same ISA, but with different pipeline and functional unit designs so they are all better suited at different kinds of tasks/threads (and simulations indicate that such designs give much better overall power/performance than the current crop of homogeneous multi-core desktop server cpus if you use some fairly simple performance counter based heuristics in your scheduler). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
Mattias Gaertner schrieb: I need a default value of the number of maximum threads. Is there already some RTL function that can be used for that? For example if the program runs on a 2 x quad core it would be nice to get 8. Hyperthreading multipliers should be applied. No, but having some functions returning information about the CPUs would be nice. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
Mattias Gaertner pisze: I need a default value of the number of maximum threads. Is there already some RTL function that can be used for that? For example if the program runs on a 2 x quad core it would be nice to get 8. Hyperthreading multipliers should be applied. I've found something on: http://blogs.msdn.com/oldnewthing/archive/2005/12/16/504659.aspx function AvailableProcessorCount: DWORD; //returns total number of processors available to system including logical hyperthreaded processors var i: Integer; ProcessAffinityMask, SystemAffinityMask: DWORD; Mask: DWORD; begin if GetProcessAffinityMask(GetCurrentProcess, ProcessAffinityMask, SystemAffinityMask) then begin Result := 0; for i := 0 to 31 do begin Mask := 1 shl i; if (ProcessAffinityMask and Mask)0 then begin inc(Result); end; end; end else begin //can't get the affinity mask so we just report the total number of processors Result := OperatingSystemInfo.ProcessorCount; end; end; (* AvailableProcessorCount *) -- Darek ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
Florian Klaempfl wrote: Mattias Gaertner schrieb: I need a default value of the number of maximum threads. Is there already some RTL function that can be used for that? For example if the program runs on a 2 x quad core it would be nice to get 8. Hyperthreading multipliers should be applied. No, but having some functions returning information about the CPUs would be nice. Blender (http://www.blender.org/) source code has function to do that (they needed this to set the default number of threads for renderer). So you could try converting to Pascal the code of BLI_system_thread_count function from: https://svn.blender.org/svnroot/bf-blender/trunk/blender/source/blender/blenlib/intern/threads.c Doesn't seem that complicated on 1st look. It's basically appropriate GetSystemInfo call on Windows, sysctl on Mac OS, and sysconf (from Libc) call on most Unixes. HTH, Michalis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] number of cpu cores
In our previous episode, Michalis Kamburelis said: [ Charset ISO-8859-1 unsupported, converting... ] Florian Klaempfl wrote: Mattias Gaertner schrieb: I need a default value of the number of maximum threads. Is there already some RTL function that can be used for that? For example if the program runs on a 2 x quad core it would be nice to get 8. Hyperthreading multipliers should be applied. No, but having some functions returning information about the CPUs would be nice. Blender (http://www.blender.org/) source code has function to do that (they needed this to set the default number of threads for renderer). So you could try converting to Pascal the code of BLI_system_thread_count function from: https://svn.blender.org/svnroot/bf-blender/trunk/blender/source/blender/blenlib/intern/threads.c Doesn't seem that complicated on 1st look. It's basically appropriate GetSystemInfo call on Windows, sysctl on Mac OS, and sysconf (from Libc) call on most Unixes. Sysconf is not standarized yet. Unit libc is linux/x86 only. On freebsd, the sysctl modeled works, but note the typecast. (probably a KR void* - char* problem) uses ctypes,sysctl; var mib : array[0..1] of cint; len:cint; t :cint; begin mib[0] := CTL_HW; mib[1] := HW_NCPU; len := sizeof(t); fpsysctl(pchar(@mib), 2, @t, @len, Nil, 0); writeln(t); // prints 2 on our dual CPU (Athlon MPs) end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal