开发者

Problem with omp_set_num_threads called from a WinAPI thread

I've run into a funny problem using OpenMP v2 under MSVC 9 SP1. when calling omp_set_num_threads from the main thread of execution then using omp_get_num_threads to check the amount set, all works well and checks out.

However, in an GUI app, I call the same thing, but its own thread(created with CreateThread), to prevent the UI from becoming unresponsive, how ever it seems that omp_set_num_threads doesn't work when called from a thread, as omp_get_num_threads always reports 1, and from tests I can see only one thread in operation.

In Summary: does omp_set_num_threads have problems/restrictions when being called from a thread thats not the processes main thread?

Code:

void CalculateDivisionSeriesOMP(unsigned long dwMul开发者_JS百科, int nType, size_t nOMPThreads)
{
    omp_set_num_threads(nOMPThreads);
    if(nType == 0)
    {
        #pragma omp parallel default(shared)
        {
            #pragma omp master
            {
                Printf("Starting Search For Divisor With Constant: 0x%08X...",dwMul);
                Printf("%d Threads In Use",omp_get_num_threads());
            }

            #pragma omp for
            for(__int64 i = 2; i < 4294967295; i++)
            {
                mu U = magicu2(i);
                if(U.M == dwMul)
                    Printf("Found Unsigned Divisor: %d Series Expansion Stage(Shift): %d Add: %d",unsigned long(i),U.s,U.a);

                ms S = magic(i);
                if(S.M == dwMul)
                    Printf("Found Signed Divisor: %d Series Expansion Stage(Shift): %d",i,S.s);
            }
        }

    }
//more of the same...
}

DWORD WINAPI DivThread(void* p)
{
    //...
    CalculateDivisionSeriesOMP(dwMul,nType,nOMPThreads);
    //...
}

//...
hDivThread = CreateThread(NULL,0,DivThread,NULL,0,NULL);
//..


What compiler options are used(openmp)? Please, check this code in function:

#ifndef _OPENMP
printf("No OpenMP.");
#else
printf("OpenMP OK.");
#endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜