Jump to content
bluesum

tparallel.for/TTask only run one thread in Min/Max of chess?

Recommended Posts

I am using delphi 11.2 in windows

 

Full source 

attached

 

Either one only run 1 thread,please help me,thanks.

====================================================

procedure TForm1.btnParallelForClick(Sender: TObject);

TParallel.For(0,System.CPUCount,procedure(I:Int64)

var thinkstep: string;

begin

MinMax(board,mutiSideisRed,8,thinkstep);

end;

end);

=====================================================

procedure TForm1.btnTTaskClick(Sender: TObject);

var

tasks: array of ITask;

thinkstep : array of string;

SW: TStopwatch;

a:integer;

begin

Setlength (tasks ,System.CPUCount);

Setlength (thinkstep ,System.CPUCount+1);

ReInitboard;

SW :=TStopWatch.Create;

for a := 0 to System.CPUCount-1 do

begin

thinkstep[a+1] := '';

tasks[a] := TTask.Create (procedure ()

begin

PMinMax(board,mutiSideisRed,8,thinkstep[a]);

end);

end;

for a := 0 to System.CPUCount-1 do

tasks[a].Start;

TTask3.zip

Edited by bluesum

Share this post


Link to post
36 minutes ago, bluesum said:

I am using delphi 12.2 in windows

I want Delphi too:classic_rolleyes: Sure, it's a typo 11.2

Share this post


Link to post
4 minutes ago, Stano said:

I want Delphi too:classic_rolleyes: Sure, it's a typo 11.2

Yes,I corrected the message

Share this post


Link to post

embarcadero reply that "Each Task runs on a core and the scheduling of each task is decided by an internal code that understands which core is relatively free and gives that core the load. There's no guarantee that all cores are going to be used for every task."

original reply message picture:

https://ibb.co/K5jd9bk

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×