c++ - Openmp: nested loops and allocation -


I want to parallel another loop for the loop. I can just use the #pragma omp parallel for "direct instruction" in the internal loop, but I'm afraid every time an applet is not something to create a new set of threads. Allocation in outer loop (before one in the inside) and any other formula is done with a thread (I assign a matrix so that the internal loop can be worked, so every thread should use it). I tried to do something like this:

  #pragma omp parallel {for (auto t = 1; t & lt; = time_step; ++ t) {#pragma omp single {matrix & lt ; Unsigned int & gt; Newfield (rows, columns); // some instructions} unsigned int j; #pragma for omp (unsigned int i = 2; i & lt; = rows-1; ++ i) {for (j = 1; j & lt; = cols; ++ j) {// Work on newField ( I, j)}} # prima omp single {// instructions}}}  

This code does not work. Is this (if I work it) more efficient than ever formula? What am i doing wrong

Thank you!

Many implementations of OpenMP

then you

 < For code> (auto t = 1; t can go with & lt; = time_step; +. T) {matrix & lt; Unsigned Inter & gt; Newfield (rows, columns); // Some instructions are unsigned int j; #pragma omp for parallel (unsigned int i = 2; i & lt; = rows-1; ++ i) {for (j = 1; j & lt; = cols; ++ j) {// Work on NewField (I, j)}} // instructions}  

and due to the absent single instructions, it can also be faster.


Comments