concurrency-in-scala-with-ce
concurrency-in-scala-with-ce copied to clipboard
Parallelism or parallel execution?
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! 🙂
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