Parallel coding Vs Multithreading (on single cpu)

前端 未结 7 1341
忘掉有多难
忘掉有多难 2020-12-30 13:11

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

i am not much experience in both, but i want to shift my coding style t

相关标签:
7条回答
  • 2020-12-30 13:17

    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"

    0 讨论(0)
  • 2020-12-30 13:21

    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.

    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.

    0 讨论(0)
  • 2020-12-30 13:27

    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.

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

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

    0 讨论(0)
  • 2020-12-30 13:27

    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.

    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.

    0 讨论(0)
  • 2020-12-30 13:27

    Parallel coding is the concept of executing multiple actions in parallel(Same time).

    Multi-threaded Programming on a Single Processor

    Multi-threading on a single processor gives the illusion of running in parallel. Behind the scenes, the processor is switching between threads depending on how threads have been prioritized.

    Multi-threaded Programming on Multiple Processors

    Multi-threading on multiple processor cores is truly parallel. Each microprocessor is running a single thread. Consequently, there are multiple parallel, concurrent tasks happening at once.

    0 讨论(0)
  • 2020-12-30 13:31

    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.

    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.

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

    0 讨论(0)
提交回复
热议问题