0

I am interested about the difference between process and thread in openmp. I found this answer of Scott Langham quite interesting about the difference between thread and process in general.

So here comes my question : In the case of openmp parallel for where "thread" are fork at the beginning of the loop and then join afterward, is it realy thread which are forked or Process ?

Community
  • 1
  • 1
Fopa Léon Constantin
  • 11,863
  • 8
  • 48
  • 82
  • Maybe you could give an example of a code you are trying to understand. That is because there are differences e.g. between `omp for` and `omp parallel for`. I highly recommend to take a look at [the specification](http://openmp.org/wp/openmp-specifications/), in particular the glossary. Note that there is no notion of *process* within the specification. Also *fork* / *join* is rarely used in the terminology. – Zulan Sep 06 '16 at 10:39

1 Answers1

1

The OpenMP's execution model is a fork/join model, where execution starts with a single (master) thread and then other threads are spawned upon encountering a parallel region[1]. These threads are, indeed, threads, not processes, meaning all the threads spawned in a parallel region have access to the same shared-memory space. Put it in another way, if you were to implement your own OpenMP runtime, you would do it using Pthreads, not using fork() nor clone().

Worth mentioning: According to the standard, each thread has a temporary view of the memory (mostly for cache purposes), so the thread does not have to access the shared memory for every write/read of a variable [2]. Later, a flush operation synchronizes the thread's private view of the memory and the shared memory seen by all the threads.

It may be argued that because of this private view, a thread is actually a process. However, this private view (which is actually not mandatory) is synchronized with the memory seen by all the rest of threads and, therefore, a thread remains being a thread, and not a process.

[1] OpenMP Application Programming Interface 4.5, pp. 14

[2] OpenMP Application Programming Interface 4.5, pp. 17

jandres742
  • 191
  • 11