<p>An easy way to parallelize a path tracer is to have different threads (or machines!) work on different parts of the image.</p>

<p>For instance, you could break the image into a 20x20 grid and have each thread grab a tile, render it, and try to grab another tile.</p>

<p>A way I like to divy out this work is to use an atomic integer. Each thread atomically increments the integer and uses the value as an index into the work to do. They repeat this process until the atomic integer goes out of bounds.</p>

CC BY-SA 4.0
2019-11-14T05:26:09.723Z
2019-11-14T05:26:09.723Z
Alan Wolfe
<p>Where can I find a pseudocode to parallelize a path tracer using multiple cpu threads? How should I change the normal path tracer to be capable of parallelization?  </p>

CC BY-SA 4.0
2019-11-08T21:03:01.680Z
`#pragma omp parallel for`, you'll have to provide separate prngs. You can refer to my modification of inoneweekend: https://github.com/vchizhov/InOneWeekend-1/blob/master/src/main.cc
lightxbulb
<raytracing><multithreading>
A pseudocode to parallelize a path tracer?
bitWise
# A pseudocode to parallelize a path tracer?

(Asked by: username_0 on 2019-11-08)

Where can I find a pseudocode to parallelize a path tracer using multiple cpu threads? How should I change the normal path tracer to be capable of parallelization?

**Tags:** raytracing, multithreading

> **Comments:**
> **username_1**: `#pragma omp parallel for`, you'll have to provide separate prngs. You can refer to my modification of inoneweekend: https://github.com/vchizhov/InOneWeekend-1/blob/master/src/main.cc  

---

## 1 answers

### Answer by username_2 on 2019-11-14. Score: 5

An easy way to parallelize a path tracer is to have different threads (or machines!) work on different parts of the image.

For instance, you could break the image into a 20x20 grid and have each thread grab a tile, render it, and try to grab another tile.

A way I like to divy out this work is to use an atomic integer. Each thread atomically increments the integer and uses the value as an index into the work to do. They repeat this process until the atomic integer goes out of bounds.


---

