0

在执行多线程程序期间,我看到 Delphi 事件日志中启动了 8 个线程。

(我的 CPU 是 Intel 7,具有 4 个超线程内核,因此 8 个计算内核)但在我的 TaskManager 中的性能选项卡中,我看到只有 12% 的 CPU 使用率,并且只有一个内核计算性能高达 70-80%。使用 OTL 和 ParallelFor 编译了我的多线程程序,但仍然只有 12% 的性能并且只有一个内核在做这项工作。

在我的 Form1 上,我有一个带有 OTL parallel.ForeEach 的 ButtonClick 过程,它迭代了一个 StingList 的项目。StringList 行包含每个名称、不同数据文件的路径和文件的数据格式。ForEach.execute() 在其他单元上启动一个“EntrySearch”过程,EntrySearch 过程从从字符串列表的适当行中提取信息开始。在“While X < Y 循环”中,是通过 AssignFile 从 DataFile 中提取的数据,而 While not eof,则读取带有数据的行。对数据进行计算,直到“当 X < Y”循环结束

我可以看到在 ButtonClick 过程中启动了 8 个(CPUcount)线程。在 TaskManager 中,我看到只有一个 CPU 内核开始工作,总共大约 12% 的处理器使用率。当计算后 ProcessorUsage 返回 0% 时,.exe 程序挂起,我无法控制该程序。从我可以从 CalculationUnit 中提取的少量数据中,我只从最后一个启动的线程中获取数据,因为最后一个线程使其他线程停止并且无法进行计算并且无法终止。

{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;

出了什么问题?我该如何解决这个问题。多谢。

4

0 回答 0