concurrency-in-scala-with-ce icon indicating copy to clipboard operation
concurrency-in-scala-with-ce copied to clipboard

Parallelism or parallel execution?

Open marcraminv opened this issue 3 years ago • 1 comments

Hey 🤗,

I am a bit newer about concurrency and parallelism and I would like to make an open question. Which is the different between parallel execution and parallelism in the docs? Reading the repository I don't really know if we are threatening the concept like one. There is any specific example I can check to visualise how a task is subdivided in subtask and paralleled?

Thank you! 🙂

marcraminv avatar Jul 14 '21 14:07 marcraminv

Hi!

You can think of parallelism as a property of a program, achieved with a particular program design. Simple example would be using parTraverse or similar function from cats-effect, where you enable a set of operations to be executed independent of each other, which makes them eligible for parallel execution.

It is then up to your hardware (CPU -> cores -> threads) to physically perform those operations in parallel (thus achieving parallel execution), or not (perhaps all cores are currently busy doing other stuff, so your parallel-designated chunks of code could still theoretically end up being done in sequence).

Parallel concurrent execution is parallel execution in which chunks get interleaved, e.g.

Core1:  A1 -> A2 -> B3 -> B4 -> A5
Core2:  B1 -> B2 -> A3 -> A4 -> B5

slouc avatar Jul 29 '21 08:07 slouc