gpt4 book ai didi

multithreading - 没有并发怎么能有并行呢?

转载 作者:行者123 更新时间:2023-12-04 06:41:10 25 4
gpt4 key购买 nike

我读到可以在没有并发的情况下实现并行。这样对吗?

假设您有两个任务 A 和 B,每个任务都需要两个步骤才能完成:A1、A2、B1、B2。此外,进程由线程组成。

在这里我是如何看待并发和并行的:

顺序的

          Time ----->
Thread 1: A1 A2 B1 B2

同时
          Time ----->
Thread 1: A1 A2
Thread 2: B1 B2

并行(和并发)
          Time ----->
Thread 1: A1 A2
Thread 2: B1 B2

如果这是正确的,那么没有并发就不可能有并行性。

另外,如果这个模型是正确的,你可以有以下内容:

顺序(和并发)
          Time ----->
Thread 1: A1 B1
Thread 2: A2 B2

这可能不是一个好主意,但它在概念上似乎是可能的。

最佳答案

来自 wikipedia

Parallel computing is closely related to concurrent computing—they are frequently used together, and often conflated, though the two are distinct: it is possible to have parallelism without concurrency (such as bit-level parallelism), and concurrency without parallelism (such as multitasking by time-sharing on a single-core CPU). In parallel computing, a computational task is typically broken down in several, often many, very similar subtasks that can be processed independently and whose results are combined afterwards, upon completion. In contrast, in concurrent computing, the various processes often do not address related tasks; when they do, as is typical in distributed computing, the separate tasks may have a varied nature and often require some inter-process communication during execution.



使用该解释作为指导,我认为您的评估是准确的,但它缺少没有并发的并行性,这在上面的引用中有所提及。

关于multithreading - 没有并发怎么能有并行呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37370911/

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