locked
High cpu load while using OpenMP RRS feed

  • Question

  • Following code results in 100% cpu load though it really does nothing (only sleeps).
    Compiled with VS2008 SP1 with option "/openmp".
    Processor Core 2 Duo with XP SP3.

    I can see in the debugger that high cpu load occurs in VCOMP90!_vcomp::PartialBarrier1_Poll::Block function. It seems to have a tight loop calling Sleep(0) that results in hight cpu load and high "System Calls/sec" rate.

    ntdll!KiFastSystemCallRet
    ntdll!NtDelayExecution+0xc
    kernel32!SleepEx+0x61
    kernel32!Sleep+0xf
    VCOMP90!_vcomp::PartialBarrier1_Poll::Block+0x20 [f:\dd\vctools\openmprt\inc\synch.h @ 47]
    VCOMP90!InvokeThreadTeam+0x74 [f:\dd\vctools\openmprt\src\ttpool.cpp @ 608]
    VCOMP90!_vcomp_fork+0x136 [f:\dd\vctools\openmprt\src\fork.cpp @ 186]
    test_omp!TestFunc+0x15
    test_omp!main+0x5
    test_omp!__tmainCRTStartup+0x10f [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 586]
    kernel32!BaseProcessStart+0x23


    _____________________________________

    #include <windows.h>
    #include <omp.h>

    void TestFunc();

    int main()
    {
        TestFunc();
        return 0;
    };


    void InForCall(int);


    void TestFunc()
    {
    #pragma omp parallel for num_threads(3)
        for(int i = 0; i < 3; ++i)
        {
            switch(i)
            {
            case 0:
                InForCall(i);
                break;
            case 1:
                InForCall(i);
                break;
            case 2:
                InForCall(i);
                break;
            };       
        };
    };

    void InForCall(int i)
    {
        Sleep(1000 + i*5000);
    };

    Friday, August 7, 2009 12:52 PM

Answers

  • Hello,

    I guess this is the desired event when doing the parallel tasks in Visual Studio using OpenMP.  The threads' status are SPIN when they are idle, wait for the next invoking and do a "tight loop calling Sleep(0)".  Seems there is no a way to modify their status in Visual Studio, you could try to feedback this issue on our professional site: https://connect.microsoft.com/VisualStudio/ to get more information.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wesley Yao Monday, August 17, 2009 5:30 AM
    Thursday, August 13, 2009 8:48 AM