并行编码与多线程(在单个cpu上)

时间:2022-11-04 13:48:11

can we use interchangeably "Parallel coding" and "Multithreading coding " on single cpu?

我们可以在单个cpu上交替使用“并行编码”和“多线程编码”吗?

i am not much experience in both, but i want to shift my coding style to any one of the above.

我在这两方面都没有多少经验,但我想把我的编码风格转移到上面的任何一个。

As i found now a days many single thred application are obsolete, which would be better for future software industy as a career prospect?

正如我现在发现的那样,许多单一应用程序已经过时,这对于未来的软件产业来说会更好吗?

6 个解决方案

#1


There is definitely overlap between multithreading and parallel coding/computing, with the main differences in the target processing architecture.

多线程和并行编码/计算之间肯定存在重叠,主要区别在于目标处理体系结构。

Multithreading has been used to exploit the benefits of concurrency within a single process on a single CPU with shared memory. Running the same programs on a machine with multiple CPUs may result in significant speedup, but is often a bonus rather than intended (until recently). Many OSes have threading models (e.g. pthreads), which benefit from but do not require multiple CPUs.

多线程已被用于在具有共享内存的单个CPU上利用单个进程内的并发优势。在具有多个CPU的计算机上运行相同的程序可能会导致显着的加速,但通常是奖励而不是预期(直到最近)。许多操作系统都有线程模型(例如pthreads),它们受益但不需要多个CPU。

Multiprocessing is the standard model for parallel programming targeting multiple CPUs, from early SMP machines with many CPUs on a big machine, then to cluster computing across many machines, and now back to many CPUs/cores on a single computer. MPI is a standard that can work across many different architectures.

多处理是针对多个CPU的并行编程的标准模型,从大型机器上具有多个CPU的早期SMP机器,到跨多台机器的集群计算,现在又返回到单台计算机上的多个CPU /核心。 MPI是一种可以在许多不同体系结构中工作的标准。

Of course, one can program a parallel design using threads with language frameworks like OpenMP. I've heard of multicomponent GUIs/applications that rely on separate processing that could theoretically run anywhere. Practically, there's more of the former than the latter.

当然,可以使用具有OpenMP等语言框架的线程来编写并行设计。我听说过依赖于理论上可以在任何地方运行的单独处理的多组件GUI /应用程序。实际上,前者比后者更多。

Probably the main distinction is when the program runs across multiple machines, where it's not practical to use multithreading, and existing applications that share memory will not work.

可能主要区别在于程序在多台机器上运行时,使用多线程是不切实际的,共享内存的现有应用程序将无法运行。

#2


The question is a bit confusing as you can perform parallel operations in multiple threads, but all multi-thread applications are not using parallel computing. In parallel code, you typically have many "workers" that consume a set of data to return results asynchronously. But multithread is used in a broader scope, like GUI, blocking I/O and networking.

问题有点令人困惑,因为您可以在多个线程中执行并行操作,但所有多线程应用程序都不使用并行计算。在并行代码中,通常有许多“工作者”使用一组数据来异步返回结果。但多线程用于更广泛的范围,如GUI,阻止I / O和网络。

Being on a single or many CPU does not change much, as the management depends on how your OS can handle threads and processes.

处于单个或多个CPU上的变化不大,因为管理依赖于操作系统如何处理线程和进程。

Multithreading will be useful everywhere, parallel is not everyday computing paradigm, so it might be a "niche" in a career prospect.

多线程在任何地方都是有用的,并行不是日常计算范例,因此它可能是职业前景中的“利基”。

#3


Some demos I saw in .NET 4.0, the Parallel code changes seem easier then doing threads. There is new syntax for "For Loops" and other things to support parallel processing. So there is a difference.

我在.NET 4.0中看到的一些演示,并行代码更改似乎比执行线程更容易。 “For Loops”和支持并行处理的其他东西有新的语法。所以有区别。

I think in the future you will do both, but I think the Parallel support will be better and easier. You still need threads for background operations and other things.

我认为将来你会做到这两点,但我认为Parallel支持会更好,更容易。你仍然需要线程用于后台操作和其他事情。

#4


The fact is that you cannot achieve "real" parallelism on a single CPU. There are several libraries (such as C's MPI) that help a little bit on this area. But the concept of paralellism it's not that used among developers working on popular solutions.

事实是,您无法在单个CPU上实现“真正的”并行性。有几个库(例如C的MPI)对这个领域有所帮助。但是,在开发流行解决方案的开发人员中并没有使用并行的概念。

Multithreading is common these days thanks to the introduction of multiple cores on a single CPU, it's easy and almost transparent to implement in every language thanks to thread libs and threadsafe types, methods, classes and so on. This way you can simulate paralellism.

多线程现在很常见,因为在单个CPU上引入了多个内核,由于线程库和线程安全类型,方法,类等,在每种语言中实现它都很容易且几乎透明。这样你就可以模拟并行性。

Anyway, if you're starting with this, start by reading about concurrency and threading topics. And of course, threads + parallelism work good together.

无论如何,如果你从这开始,首先阅读有关并发和线程主题的内容。当然,线程+并行性能很好地协同工作。

#5


I'm not sure about what do you think "Parallel coding" is but Parallel coding as I understand it refers to producing code which is executed in parallel by the CPU, and therefore Multithreaded code falls inside that description.

我不确定您认为“并行编码”是什么,但并行编码,据我所知,它指的是生成由CPU并行执行的代码,因此多线程代码属于该描述。

In that way, obviously you can use them interchangeably (as one falls inside the other).

通过这种方式,显然你可以互换使用它们(因为一个落在另一个里面)。

Nonetheless I'll suggest you take it slowly and start learning from the basics. Understand WHY multithreading is becoming important, what's the difference between processes, threads and fibers, how do you synchronize either of them and so on.

尽管如此,我建议你慢慢来,并开始学习基础知识。了解为什么多线程变得越来越重要,进程,线程和光纤之间的区别是什么,如何同步它们中的任何一个等等。

Keep in mind that parallel coding, as you call it, is quite complex, specially compared to sequential coding so be prepared. Also don't just rush into it. Just because you use 3 threads instead of one won't make your program faster, it can even make it slower. You need to understand the hows and the whys. Not every thing can be made parallel and not everthing that can, should.

请记住,并行编码,就像你所说的那样,非常复杂,特别是与顺序编码相比,所以要做好准备。也不要急于进入它。仅仅因为你使用3个线程而不是一个线程不会使你的程序更快,它甚至可以使它更慢。你需要了解方法和方法。并非所有事情都可以并行,而不应该是可以的。

#6


in simple Language multithreading is available in the CPu by itself and parallel programming is an explicit task either done by the compiler or my constructs written by programmers "#pragma"

简单语言多线程在CPu中可用,并行编程是一个明确的任务,由编译器完成或由程序员编写的构造“#pragma”

#1


There is definitely overlap between multithreading and parallel coding/computing, with the main differences in the target processing architecture.

多线程和并行编码/计算之间肯定存在重叠,主要区别在于目标处理体系结构。

Multithreading has been used to exploit the benefits of concurrency within a single process on a single CPU with shared memory. Running the same programs on a machine with multiple CPUs may result in significant speedup, but is often a bonus rather than intended (until recently). Many OSes have threading models (e.g. pthreads), which benefit from but do not require multiple CPUs.

多线程已被用于在具有共享内存的单个CPU上利用单个进程内的并发优势。在具有多个CPU的计算机上运行相同的程序可能会导致显着的加速,但通常是奖励而不是预期(直到最近)。许多操作系统都有线程模型(例如pthreads),它们受益但不需要多个CPU。

Multiprocessing is the standard model for parallel programming targeting multiple CPUs, from early SMP machines with many CPUs on a big machine, then to cluster computing across many machines, and now back to many CPUs/cores on a single computer. MPI is a standard that can work across many different architectures.

多处理是针对多个CPU的并行编程的标准模型,从大型机器上具有多个CPU的早期SMP机器,到跨多台机器的集群计算,现在又返回到单台计算机上的多个CPU /核心。 MPI是一种可以在许多不同体系结构中工作的标准。

Of course, one can program a parallel design using threads with language frameworks like OpenMP. I've heard of multicomponent GUIs/applications that rely on separate processing that could theoretically run anywhere. Practically, there's more of the former than the latter.

当然,可以使用具有OpenMP等语言框架的线程来编写并行设计。我听说过依赖于理论上可以在任何地方运行的单独处理的多组件GUI /应用程序。实际上,前者比后者更多。

Probably the main distinction is when the program runs across multiple machines, where it's not practical to use multithreading, and existing applications that share memory will not work.

可能主要区别在于程序在多台机器上运行时,使用多线程是不切实际的,共享内存的现有应用程序将无法运行。

#2


The question is a bit confusing as you can perform parallel operations in multiple threads, but all multi-thread applications are not using parallel computing. In parallel code, you typically have many "workers" that consume a set of data to return results asynchronously. But multithread is used in a broader scope, like GUI, blocking I/O and networking.

问题有点令人困惑,因为您可以在多个线程中执行并行操作,但所有多线程应用程序都不使用并行计算。在并行代码中,通常有许多“工作者”使用一组数据来异步返回结果。但多线程用于更广泛的范围,如GUI,阻止I / O和网络。

Being on a single or many CPU does not change much, as the management depends on how your OS can handle threads and processes.

处于单个或多个CPU上的变化不大,因为管理依赖于操作系统如何处理线程和进程。

Multithreading will be useful everywhere, parallel is not everyday computing paradigm, so it might be a "niche" in a career prospect.

多线程在任何地方都是有用的,并行不是日常计算范例,因此它可能是职业前景中的“利基”。

#3


Some demos I saw in .NET 4.0, the Parallel code changes seem easier then doing threads. There is new syntax for "For Loops" and other things to support parallel processing. So there is a difference.

我在.NET 4.0中看到的一些演示,并行代码更改似乎比执行线程更容易。 “For Loops”和支持并行处理的其他东西有新的语法。所以有区别。

I think in the future you will do both, but I think the Parallel support will be better and easier. You still need threads for background operations and other things.

我认为将来你会做到这两点,但我认为Parallel支持会更好,更容易。你仍然需要线程用于后台操作和其他事情。

#4


The fact is that you cannot achieve "real" parallelism on a single CPU. There are several libraries (such as C's MPI) that help a little bit on this area. But the concept of paralellism it's not that used among developers working on popular solutions.

事实是,您无法在单个CPU上实现“真正的”并行性。有几个库(例如C的MPI)对这个领域有所帮助。但是,在开发流行解决方案的开发人员中并没有使用并行的概念。

Multithreading is common these days thanks to the introduction of multiple cores on a single CPU, it's easy and almost transparent to implement in every language thanks to thread libs and threadsafe types, methods, classes and so on. This way you can simulate paralellism.

多线程现在很常见,因为在单个CPU上引入了多个内核,由于线程库和线程安全类型,方法,类等,在每种语言中实现它都很容易且几乎透明。这样你就可以模拟并行性。

Anyway, if you're starting with this, start by reading about concurrency and threading topics. And of course, threads + parallelism work good together.

无论如何,如果你从这开始,首先阅读有关并发和线程主题的内容。当然,线程+并行性能很好地协同工作。

#5


I'm not sure about what do you think "Parallel coding" is but Parallel coding as I understand it refers to producing code which is executed in parallel by the CPU, and therefore Multithreaded code falls inside that description.

我不确定您认为“并行编码”是什么,但并行编码,据我所知,它指的是生成由CPU并行执行的代码,因此多线程代码属于该描述。

In that way, obviously you can use them interchangeably (as one falls inside the other).

通过这种方式,显然你可以互换使用它们(因为一个落在另一个里面)。

Nonetheless I'll suggest you take it slowly and start learning from the basics. Understand WHY multithreading is becoming important, what's the difference between processes, threads and fibers, how do you synchronize either of them and so on.

尽管如此,我建议你慢慢来,并开始学习基础知识。了解为什么多线程变得越来越重要,进程,线程和光纤之间的区别是什么,如何同步它们中的任何一个等等。

Keep in mind that parallel coding, as you call it, is quite complex, specially compared to sequential coding so be prepared. Also don't just rush into it. Just because you use 3 threads instead of one won't make your program faster, it can even make it slower. You need to understand the hows and the whys. Not every thing can be made parallel and not everthing that can, should.

请记住,并行编码,就像你所说的那样,非常复杂,特别是与顺序编码相比,所以要做好准备。也不要急于进入它。仅仅因为你使用3个线程而不是一个线程不会使你的程序更快,它甚至可以使它更慢。你需要了解方法和方法。并非所有事情都可以并行,而不应该是可以的。

#6


in simple Language multithreading is available in the CPu by itself and parallel programming is an explicit task either done by the compiler or my constructs written by programmers "#pragma"

简单语言多线程在CPu中可用,并行编程是一个明确的任务,由编译器完成或由程序员编写的构造“#pragma”