Parallel coding Vs Multithreading (on single cpu)
Asked Answered
T

7

8

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 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?

Turmeric answered 2/7, 2009 at 8:6 Comment(0)
L
13

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.

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.

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.

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.

Leena answered 2/7, 2009 at 9:2 Comment(0)
A
3

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.

Autoplasty answered 16/11, 2019 at 22:14 Comment(0)
E
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.

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.

Embryogeny answered 2/7, 2009 at 8:18 Comment(0)
A
2

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.

Abott answered 2/7, 2009 at 8:20 Comment(1)
channel9.msdn.com/posts/VisualStudio/…Abott
M
1

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.

Martel answered 2/7, 2009 at 8:37 Comment(4)
Multithreading is not easy in practically any language except maybe in erlang.Poliard
I've heard a lot about erlang and paralellism over erlang. Unfortunately I don't know this language. By easy Multithreading, I mean creating multiple threads and making them work coherently. I know it's not trivial, but it's not that hard to consider looking for another solution to your problem instead of threading.Martel
@Jorge - I don't think erlang uses threads, but lightweight processes that do not share memoryLeena
-1 for writing multi-threaded programming is easy. In my experience, most people are better off improving their single-threaded code or spawning more instances of single-threaded web-apps.Duprey
P
0

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.

Pierce answered 2/7, 2009 at 8:16 Comment(0)
P
0

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"

Pleistocene answered 17/8, 2013 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.