openmp reduction
От: barmale-y  
Дата: 10.09.10 09:33
Оценка:
Как понимать вот это утверждение о том, что переменные в операторе reduction должны быть декларированы как shared [url=здесь]https://computing.llnl.gov/tutorials/openMP/#REDUCTION[/url]]:

Restrictions:
* Variables in the list must be named scalar variables. They can not be array or structure type variables. They must also be declared SHARED in the enclosing context.


Что это за контекст такой?

Если на директиву shared(s) компилятор ругается, а без этого объявления все хорошо работает, как и с директивой default(shared).

#include <stdio.h>
main() {
    int s = 0, i;
    #pragma omp parallel for shared(s) private(i)  reduction(+:s)
    for(i=0; i<100; ++i)  {
        s += i;
    }
    printf("s=%i",s);
}

error: ‘s’ appears more than once in data clauses
Re: openmp reduction
От: remark Россия http://www.1024cores.net/
Дата: 10.09.10 09:44
Оценка:
Здравствуйте, barmale-y, Вы писали:

BY>Как понимать вот это утверждение о том, что переменные в операторе reduction должны быть декларированы как shared [url=здесь]https://computing.llnl.gov/tutorials/openMP/#REDUCTION[/url]]:


В MSDN это описано более вразумительно. Возможно на computing.llnl.gov копия из более старого стандарта OpenMP.

The restrictions to the reduction clause are as follows:

The type of the variables in the reduction clause must be valid for the reduction operator except that pointer types and reference types are never permitted.

A variable that is specified in the reduction clause must not be const-qualified.

Variables that are private within a parallel region or that appear in the reduction clause of a parallel directive cannot be specified in a reduction clause on a work-sharing directive that binds to the parallel construct.

#pragma omp parallel private(y)
{ /* ERROR - private variable y cannot be specified
             in a reduction clause */
   #pragma omp for reduction(+: y)
   for (i=0; i<n; i++)
      y += b[i];
}

/* ERROR - variable x cannot be specified in both
           a shared and a reduction clause */
#pragma omp parallel for shared(x) reduction(+: x)



1024cores &mdash; all about multithreading, multicore, concurrency, parallelism, lock-free algorithms
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.