0

During Executing of a Multithreading program I see 8 threads starting in the Delphi Event log.

(My CPU is a Intel 7 with 4 cores HyperThreaded so 8 Calculation Cores) but in my TaskManager at the Performance tab I see only 12% CPU usage and only one core calculating with performance up to about 70 - 80 %. Did compile my multithreading program with OTL usage and with ParallelFor usage, But still only 12% performance and only One core doing the work.

On my Form1 I have a ButtonClick procedure with the OTL parallel.ForeEach which iterates over items of a StingList. The StringList lines contains each a Name, a Path to a differend DataFile and a DataFormat of the File. The ForEach.execute() Starts a 'EntrySearch'procedure on other Unit, The EntrySearch procedure starts with the extraction of the info from the appropiate line of the Stringlist. In a 'While X < Y loop' is the data extracted from the DataFile through a AssignFile and While not eof,read the lines with data. Calcuclations are made on the Data until the 'While X < Y' loop ends

I can see that 8 (CPUcount) Threads are started at the ButtonClick procedure. In the TaskManager I see only one CPU core start working total of about 12% ProcessorUsage. When after the calculations the ProcessorUsage returns to 0% the .exe program is hanging and I have no controlover the program. From the little data I can extract out of the CalculationUnit I getonly data from the last started thread, as of this last thread makes the other threads stop and cannot make their caculations and can not terminate.

{the OTL in the ButtonClick procedure}
       Parallel.ForEach(0, StrList.Count-1)
       .PreserveOrder
       .NumTasks(CPUCount)
       .NoWait
       .Execute(
        procedure(const value: integer)
         begin
           CalcUnit.EntrySearch(value);
         end);

    {procedure on CalcUnit} 
    procedure EntrySearch(value: integer);
    begin 
     {extract Name, Path DataFile and DataFormat from StringList}
      While X < Y do begin
        AssignFile(qMSInputFile7, Path);
        {$I-} reset(qMSInputFile7); {$I+}
        While Not eof(qMSInputFile7) do Begin
          with qMetaRec7 do begin
            Read (qMSInputFile7, qMetaRec7);
             { Extract the Data}
           end; // While not eof
        {Make calculations}   
      end; // While X<Y 
    end;

What goes wrong? and how can I solve this. Thanks A lot.

18
  • 2
    The first sentence is misleading. You mean during execution of your program rather than during compilation. Why is your program not being executed in parallel? The answer can be found in your program. Commented Oct 24, 2014 at 8:10
  • 1
    You will need to show an MVCE Commented Oct 24, 2014 at 8:34
  • @David Hefferman, Thank you, changed compiling to execution. Commented Oct 24, 2014 at 10:31
  • 2
    Try using a different memory manager, e.g. scalemm or synscalemm. Also try using a thread pool and IOCP on Windows. Commented Oct 24, 2014 at 10:44
  • 1
    @LU RD Your comments where very helpful! Thank you. through the debugging link you gave I found indeed that my problem were the Global variables. My Calculation procedure is on a separate Unit, thinking that the whole unit was taken into the Thread. Now I placed the variables all inside the procedure My problem is solved. I learned a lot! Thanks Again Best regards Frits Commented Oct 31, 2014 at 15:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.