views:

1423

answers:

5

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?

A: 

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.

Jorge Córdoba
+1  A: 

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.

+2  A: 

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.

eschneider
http://channel9.msdn.com/posts/VisualStudio/Using-the-Parallel-Extensions-to-the-NET-Framework/
eschneider
+1  A: 

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.

Rigo Vides
Multithreading is not easy in practically any language except maybe in erlang.
Jorge Córdoba
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.
Rigo Vides
@Jorge - I don't think erlang uses threads, but lightweight processes that do not share memory
bubaker
-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.
Jørgen Fogh
+3  A: 

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.

bubaker