Note that there are some explanatory texts on larger screens.

plurals
  1. POC and OpenMP: pointer to shared read-only data slows down execution
    primarykey
    data
    text
    <p>This is my situation, I have an array of pointers that point to arrays of some data... Let's say:</p> <pre><code> Data** array = malloc ( 100 * sizeof(Data*)); for(i = 0; i &lt; 100; i++) array[i] = malloc (20 * sizeof(Data); </code></pre> <p>Inside a parallel region, I make some operations that use that data. For instance:</p> <pre><code> #pragma omp parallel num_threads(4) firstprivate(array) { function(array[0], array[omp_get_thread_num()]; } </code></pre> <p>The first parameter is read-only but is the same along all threads... </p> <p>The problem is that if I use as the first parameter a diferent block of data, i.e.: array[omp_get_thread_num()+1], each function lasts 1seg. But when I use the same block of data, array[0], <em>each</em> function call lasts 4segs.</p> <p>My theory is that there is no way to know if the array[0] will be changed or not by the funciton so each thread asks for a copy and invalidate the copies that other threads have and that should explain the delay...</p> <p>I tried to make a local copy of array[0] like this:</p> <pre><code> #pragma omp parallel num_threads(4) firstprivate(array) { Data* tempData = malloc(20 * sizeof(Data)); memcpy(tempData,array[0], 20*sizeof(Data)); function(tempData, array[omp_get_thread_num()]; } </code></pre> <p>But I get the same result... It's like the thread doesn't 'release' the Data block so other threads could use it...</p> <p>I have to note that the first parameter is not always array[0] so I can't use firstprivate(array[0]) in the pragma line...</p> <p>Questions are:</p> <ul> <li>Am I doing something wrong?</li> <li>Is there a way to 'release' a shared block of memory so other threads could use it?</li> </ul> <p>It was very difficult try to make me understand so if you need further information, please let me know!</p> <p>Thanks in advance... Javier</p> <p>EDIT: I can't change the function declaration because it comes inside a library! (ACML)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload