# Reading material / tutorials / resources on threadsafe programming

**URL:** <https://discourse.julialang.org/t/reading-material-tutorials-resources-on-threadsafe-programming/7834>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 18, 2017, 1:47pm UTC](https://discourse.julialang.org/t/reading-material-tutorials-resources-on-threadsafe-programming/7834 "2017-12-18T13:47:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [December 18, 2017, 1:47pm UTC](https://discourse.julialang.org/t/reading-material-tutorials-resources-on-threadsafe-programming/7834/1 "2017-12-18T13:47:20Z")

</div>

I started to use the `Threads` in my code when I realized there are too many things I don’t understand. I know that I need to be careful that one thread does not interfere with another ones operations, which is pretty intuitive. but other than that this is all very abstract for me. I watched the keynote speech of keno fisher on Celeste.jl where he talks about the number of nested loops that could be packed inside each thread (if i remember correctly…), and that sounds like a consideration I should be doing in my case as well. I would just need a bit more guidance. any pointers to relevant material, examples, etc, much appreciated! (also in other languages, if the main principles carry over to julia!)

---

<div class="post-metadata">

**Author:** ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)\
**Post date:** [December 18, 2017, 4:55pm UTC](https://discourse.julialang.org/t/reading-material-tutorials-resources-on-threadsafe-programming/7834/2 "2017-12-18T16:55:12Z")

</div>

3 quick things:

1. Threads in Julia are still quite experimental / in development. Hence the lack of “official” resources.
2. What level are you working at? Are you familiar with basic OpenMP usage of threads? This might help specify resources for your use case.
3. What problem are you working on? Does it make sense to share some code?

If you’re starting bare bones, a good place to start is [these video tutorials by the creator of OpenMP in C.](https://www.google.com.mx/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwji0M-Cg5TYAhWP0YMKHaFlAY0QtwIILjAB&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6jFkNjhJ-Z4&usg=AOvVaw0OZuEvosXiB-2uLIxOsT3j)

At any rate, I found this presentaion by @vchuravy super useful at explaining different types of parallelism in Julia and some worked examples - with some handy tooling tips and packages like [Intel Architecture Compiler Analyzer, IACA.jl](https://github.com/vchuravy/IACA.jl) boot.

[julia-parallelism](http://slides.com/valentinchuravy/julia-parallelism#/1)

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [December 18, 2017, 9:03pm UTC](https://discourse.julialang.org/t/reading-material-tutorials-resources-on-threadsafe-programming/7834/3 "2017-12-18T21:03:25Z")

</div>

hey @miguelraz, that’s a good start I would say! thanks!

1. I am aware of this, yes.
2. I never used OpenMP before except maybe in some hello world context. Zero real world experience. I know my ways decently well around `addprocs` and traditional multicore parallelisms.
3. i have a large codebase where I’d like to split computation **not** at the inner-most loop, but some levels up. so, it does not make much sense to share my code. but i’d be more than happy to contribute to something, if that’s what you had in mind.

I’ll start with the OpenMP tutorial. the slides look top as well. thanks again.

---

<div class="post-metadata">

**Author:** ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)\
**Post date:** [December 20, 2017, 4:37pm UTC](https://discourse.julialang.org/t/reading-material-tutorials-resources-on-threadsafe-programming/7834/4 "2017-12-20T16:37:42Z")

</div>

“Tú hoy, yo mañana.”

No problem.

If you aren’t working on parallelizing the tight loops, perhaps a worthy consideration will be that of co-routines / tasks / green threads. The relevant parts of the manual are [here](https://docs.julialang.org/en/stable/stdlib/parallel/) and [here](https://docs.julialang.org/en/stable/manual/control-flow/#man-tasks-1).

This model is heavily inspired on the C++ Cilk coroutine model - a worthy bibliography might be [this book, Structured Parallel Programming](https://www.amazon.com/Structured-Parallel-Programming-Efficient-Computation/dp/0124159931) by Arch Robinson et al, an early builder in the Julia world.

Feel free to ask questions on the #parallel channel on Slack for specific doubts as well.

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [December 20, 2017, 5:52pm UTC](https://discourse.julialang.org/t/reading-material-tutorials-resources-on-threadsafe-programming/7834/5 "2017-12-20T17:52:30Z")

</div>

Me gusta!

Love the book suggestion. And I didn’t know there is a dedicated channel on slack, so that’s great. See you there! Cheers!
