mmostajab
mmostajab

Reputation: 2037

making a variable static private to each thread using openmp

I need to make t static to each thread, how can I do that? I tried this but t is not static private to each thread.

#pragma omp Parallel
{
    traceRays();
}
...
...
void traceRays()
{
    static float t = 1;
}

Upvotes: 0

Views: 664

Answers (2)

cipper
cipper

Reputation: 287

You can do it by just making t threadprivate:

void traceRays()
{
    static float t = 1;
    #pragma omp threadprivate(t)
}

Upvotes: 0

if the static variable is not declared in the parallel region, then everytime you attempt to define in the parallel region use: #omp parallel private(t)

Upvotes: 1

Related Questions