gpt4 book ai didi

java - "basic computational steps"在 Java 类 ForkJoinTask 的规范中意味着什么?

转载 作者:搜寻专家 更新时间:2023-11-01 03:38:47 25 4
gpt4 key购买 nike

我一直在使用Java7的Fork/Join并发框架,效果不错。我终于开始阅读 ForkJoinTask 的 API 的 javadoc,它包含以下段落:

ForkJoinTasks should perform relatively small amounts of computation. Large tasks should be split into smaller subtasks, usually via recursive decomposition. As a very rough rule of thumb, a task should perform more than 100 and less than 10000 basic computational steps, and should avoid indefinite looping. If tasks are too big, then parallelism cannot improve throughput. If too small, then memory and internal task maintenance overhead may overwhelm processing.

除了粗体字外,我都明白了。到底什么是“基本计算步骤”?它是一个通用的计算机科学术语,还是特定于 Java?它与字节码、源代码行、源代码语句等有什么关系?

示例可能与正式定义一样有用。谁能想出几行 Java,然后将其分解为相关的“基本计算步骤”?

最佳答案

可以直接评估的基本步骤,而不是要求您在评估之前解决 10 个其他问题的说明。或者,最简单的工作单元。我猜从字面上看,计算步骤是指 Java 字节码中的简单指令。正如这解释的那样,这只是描述工作量有多大的通用方法:

来自 http://coopsoft.com/ar/CalamityArticle.html

Java™ Fork-Join 灾难

您想知道为什么 > 100, < 10k 计算步骤吗?

100 has to do with the work stealing problem. All forked Tasks go into the same deque making other threads search for work. When the threads encounter contention they back off and look somewhere else. Since there is no work anywhere else they try the same deque again, and again, and again until the forking thread finally finishes the work all by itself. You can see the proof by downloading the source code for Class LongSum.java below. Hence, run slow or there will be no parallelism.

10k has to do with the join() problem. Since the F/J framework cannot do pure Task Management (see Faulty Task Manager, above) with Tasks actually waiting independently of threads when they call join(), the framework has to create “continuation threads” to avoid a halt. There can only be a limited time before it all falls apart. Hence, run fast or die.

关于java - "basic computational steps"在 Java 类 ForkJoinTask 的规范中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20670751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com