Questions tagged [parallel-processing]

Parallel processing is, in sharp contrast to just a Concurrent processing, guaranteed to start / perform / finish all thread-level and/or instruction-level tasks executed in a parallel fashion and provides a guaranteed finish of the simultaneously executed code-paths.

Parallel processing is a stricter mode of execution of the code-units (tasks, threads...) than just a concurrent run of code-execution simultaneously (just by coincidence), using more than one CPU or processor core and other shared resources to execute a program or multiple (but mutually absolutely independent) computational units.

Parallel processing has means more than just a wish/expectation to "make a program run faster", but concentrates, from a design phase down to implementation, on orchestrating true-parallel execution on available computing architecture (CPUs, cores, RAMs, IOs, GPUs, MPPAs, &c), providing a warranty for parallelism from start, during processing and parallel-finish of the unit of code.

A professional & principled disambiguation between [PARALLEL] and [CONCURRENT] is needed, as true parallel code-execution requires much more than just having a few cores and a fan-out of a hord of (uncoordinated) threads, hunting for time-sharing access to a pool of system-reserved resources. Concurrent execution is simply by far not a parallel-processing. (Link)

Rob Pike has a good speech on common misunderstandings of this subject.

21345 questions
1541
votes
41 answers

What is the difference between concurrency and parallelism?

What is the difference between concurrency and parallelism?
StackUnderflow
  • 24,080
  • 14
  • 54
  • 77
648
votes
6 answers

Should I always use a parallel stream when possible?

With Java 8 and lambdas it's easy to iterate over collections as streams, and just as easy to use a parallel stream. Two examples from the docs, the second one using parallelStream: myShapesCollection.stream() .filter(e -> e.getColor() ==…
Matsemann
  • 21,083
  • 19
  • 56
  • 89
480
votes
16 answers

Custom thread pool in Java 8 parallel stream

Is it possible to specify a custom thread pool for Java 8 parallel stream? I can not find it anywhere. Imagine that I have a server application and I would like to use parallel streams. But the application is large and multi-threaded so I want to…
Lukas
  • 13,606
  • 9
  • 31
  • 40
479
votes
15 answers

How do I parallelize a simple Python loop?

This is probably a trivial question, but how do I parallelize the following loop in python? # setup output lists output1 = list() output2 = list() output3 = list() for j in range(0, 10): # calc individual parameter value parameter = j *…
memyself
  • 11,907
  • 14
  • 61
  • 102
470
votes
19 answers

How do you run multiple programs in parallel from a bash script?

I am trying to write a .sh file that runs many programs simultaneously I tried this prog1 prog2 But that runs prog1 then waits until prog1 ends and then starts prog2... So how can I run them in parallel?
Betamoo
  • 14,964
  • 25
  • 75
  • 109
456
votes
27 answers

How to wait for all threads to finish, using ExecutorService?

I need to execute some amount of tasks 4 at a time, something like this: ExecutorService taskExecutor = Executors.newFixedThreadPool(4); while(...) { taskExecutor.execute(new MyTask()); } //...wait for completion somehow How can I get notified…
serg
  • 109,619
  • 77
  • 317
  • 330
439
votes
2 answers

What is the difference between asynchronous programming and multithreading?

I thought that they were basically the same thing — writing programs that split tasks between processors (on machines that have 2+ processors). Then I'm reading this, which says: Async methods are intended to be non-blocking operations. An…
410
votes
22 answers

What is the difference between concurrent programming and parallel programming?

What is the difference between concurrent programming and parallel programing? I asked google but didn't find anything that helped me to understand that difference. Could you give me an example for both? For now I found this explanation:…
matekm
  • 5,990
  • 3
  • 26
  • 31
352
votes
13 answers

Optimal number of threads per core

Let's say I have a 4-core CPU, and I want to run some process in the minimum amount of time. The process is ideally parallelizable, so I can run chunks of it on an infinite number of threads and each thread takes the same amount of time. Since I…
Juliet
  • 80,494
  • 45
  • 196
  • 228
316
votes
3 answers

Is there an equivalent to 'continue' in a Parallel.ForEach?

I am porting some code to Parallel.ForEach and got an error with a continue I have in the code. Is there something equivalent I can use in a Parallel.ForEach functionally equivalent to continue in a foreach loop? Parallel.ForEach(items,…
222
votes
12 answers

No ConcurrentList in .Net 4.0?

I was thrilled to see the new System.Collections.Concurrent namespace in .Net 4.0, quite nice! I've seen ConcurrentDictionary, ConcurrentQueue, ConcurrentStack, ConcurrentBag and BlockingCollection. One thing that seems to be mysteriously missing…
Alan
  • 2,574
  • 2
  • 18
  • 16
208
votes
6 answers

What are the differences between the threading and multiprocessing modules?

I am learning how to use the threading and the multiprocessing modules in Python to run certain operations in parallel and speed up my code. I am finding this hard (maybe because I don't have any theoretical background about it) to understand what…
197
votes
10 answers

How to do parallel programming in Python?

For C++, we can use OpenMP to do parallel programming; however, OpenMP will not work for Python. What should I do if I want to parallel some parts of my python program? The structure of the code may be considered as: solve1(A) solve2(B) Where…
ilovecp3
  • 2,825
  • 5
  • 18
  • 19
183
votes
6 answers

Why should I prefer single 'await Task.WhenAll' over multiple awaits?

In case I do not care about the order of task completion and just need them all to complete, should I still use await Task.WhenAll instead of multiple await? e.g, is DoWork2 below a preferred method to DoWork1 (and why?): using System; using…
avo
  • 10,101
  • 13
  • 53
  • 81
172
votes
13 answers

How to articulate the difference between asynchronous and parallel programming?

Many platforms promote asynchrony and parallelism as means for improving responsiveness. I understand the difference generally, but often find it difficult to articulate in my own mind, as well as for others. I am a workaday programmer and use async…
Matt Sherman
  • 8,298
  • 4
  • 37
  • 57
1
2 3
99 100