Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-11

number of cpu cores

13 messages · 11 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

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.

Mattias

Reply by email

Florian Klaempfl
to Mattias Gaertner
Show quoted text 6 lines
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.

Reply by email

Dariusz Mazur
to Mattias Gaertner: I need a default value of the number of maximum threads. Is there already some RTL…

Mattias Gaertner pisze:

Show quoted text 9 lines
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

Reply by email

Michalis Kamburelis
to Florian Klaempfl: No, but having some functions returning information about the CPUs would be nice.
Florian Klaempfl wrote 10 lines
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

Reply by email

Marco van de Voort
to Michalis Kamburelis

In our previous episode, Michalis Kamburelis said: [ Charset ISO-8859-1 unsupported, converting... ]

Show quoted text 22 lines
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 K&R 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.

Reply by email

Florian Klaempfl
to Mattias Gaertner: I need a default value of the number of maximum threads. Is there already some RTL…
Show quoted text 6 lines
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?

Reply by email

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote 16 lines
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

Reply by email

Mattias Gaertner
to Marco van de Voort: In our previous episode, Michalis Kamburelis said: [ Charset ISO-8859-1 unsupported,…
Show quoted text 42 lines
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 K&R 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

Reply by email

JoshyFun
to Mattias Gaertner

Hello Mattias,

Saturday, December 13, 2008, 5:17:31 PM, you wrote:

MG> At the moment I have the attached function.
MG> It returns only 4 on a 2 x quad core Mac.
MG> Maybe someone can test under windows?

Windows XP running P3000 hyperthreading returns 2 cores (as expected) but using FPC 2.2.2 the line:

Mask := 1 shl i;

must be changed by

Mask := DWORD(1) shl i;

or it raises a runtime 201 error when i = 31.

Best regards, JoshyFun

Reply by email

Robert Wolfe
to Mattias Gaertner: On Sat, 29 Nov 2008 19:14:39 +0100 (CET) Thanks for all the hints. At the moment I have…
Mattias Gaertner wrote 64 lines
On Sat, 29 Nov 2008 19:14:39 +0100 (CET) (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 K&R 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 - 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:\lazarus>ppcx64 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:\lazarus>test

2 CPUs online.

Reply by email

Inoussa OUEDRAOGO
to Marc Weustink

2008/12/14 Marc Weustink :

Show quoted text 5 lines
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.

Reply by email