omp parallel vs. omp parallel for omp parallel vs. omp parallel for multithreading multithreading

omp parallel vs. omp parallel for


These are equivalent.

#pragma omp parallel spawns a group of threads, while #pragma omp for divides loop iterations between the spawned threads. You can do both things at once with the fused #pragma omp parallel for directive.


I don't think there is any difference, one is a shortcut for the other. Although your exact implementation might deal with them differently.

The combined parallel worksharing constructs are a shortcut for specifying a parallel construct containing one worksharing construct and no other statements. Permitted clauses are the union of the clauses allowed for the parallel and worksharing contructs.

Taken from http://www.openmp.org/mp-documents/OpenMP3.0-SummarySpec.pdf

The specs for OpenMP are here:

https://openmp.org/specifications/


Here is example of using separated parallel and for here. In short it can be used for dynamic allocation of OpenMP thread-private arrays before executing for cycle in several threads.It is impossible to do the same initializing in parallel for case.

UPD:In the question example there is no difference between single pragma and two pragmas. But in practice you can make more thread aware behavior with separated parallel and for directives.Some code for example:

#pragma omp parallel{     double *data = (double*)malloc(...); // this data is thread private    #pragma omp for    for(1...100) // first parallelized cycle    {    }    #pragma omp single     {} // make some single thread processing    #pragma omp for // second parallelized cycle    for(1...100)    {    }    #pragma omp single     {} // make some single thread processing again    free(data); // free thread private data}