locked
VS 2015 Update 1: OpenMP parallel for num_threads does not work anymore RRS feed

  • Question

  • Hi, the following code does not work anymore: #define _WIN32_WINNT _WIN32_WINNT_WIN7 #define NTDDI_VERSION NTDDI_WIN7 #include <omp.h> #include <iostream> #include <sstream> int n() { return 2; } // or 1 or 4 or any reasonable number greater than 0 int main() { #pragma omp parallel for num_threads(n()) for (auto i=0; i<100; ++i) { //std::stringstream s; //s << "i: " << i << " thread: "<< omp_get_thread_num() << '\n'; //std::cout << s.str(); } } The program crashes and the debugger throws an exception
    when the parallel section is entered:

    If I comment out the lines in the for loop, the program crashes, too.
    Additionally, I see 8 threads (CPU is i7 860) instead of 2:

    Above all the console says "User Error 1001: argument to num_threads clause must be positive"
    although 2 definitely is positive. And finally, the debugger also throws an exception:

    This sample code works as expected in VS 2015 without update 1 and VS 2013 Update 5. Our production code that uses these OMP for loops has been working correctly for years
    in VS 2013 and even VS 2012. I had to uninstall Update 1 to make our products work again.

    Can anybody confirm this behavior? If so please vote here:
    https://connect.microsoft.com/VisualStudio/feedback/details/2135136/vs-2015-update-1-openmp-parallel-for-num-threads-does-not-work-anymore

    Thanks.


    • Edited by powerchord Wednesday, December 16, 2015 2:09 PM
    Wednesday, December 16, 2015 2:05 PM

Answers

  • Hi,

    Thanks for your feedback.

    And I am really sorry that I forgot to enable OMP in the project options. Sorry about this.

    After setting the OMP options, I can compile the code you provided successfully with the #pragma omp parallel for num_threads.

    >Only Update 1 has this issue. It was never an issue before Update 1.

    Yes, with VS2015,VS2013,VS2010, we don't have such issue. Only for VS2015 update1 has such issue. I think you can submit this issue to connect, there will be product team engineer to help further.

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 21, 2015 8:45 AM
  • Hi May,

    thanks.
    Now that you can reproduce this issue please do me a favor and vote on Connect:

    https://connect.microsoft.com/VisualStudio/feedback/details/2135136/vs-2015-update-1-openmp-parallel-for-num-threads-does-not-work-anymore

    Maybe, just maybe that will speed it up. And every affected program "only" needs to wait six months for Update 2.

    Tuesday, December 22, 2015 9:15 AM

All replies

  • Hi,

    Thanks for posting here.

    According to your code provided, I am trying to reproduce your issue on my side. I find that I can not compile successfully with "#pragma omp parallel for num_threads(n())"

    I think you may need to write with reference to the format below.

    #pragma omp parallel [clauses]
    {
       code_block
    }

    >The program crashes and the debugger throws an exception
    when the parallel section is entered:

    After I change the code with format above, I can reproduce your issue for your sencond scenario. But I don't have your first crash in your first picture.

    If I change the num value from function to specified value, I will get just two threads. You may change it to num value to test if you get same result as mine. And I think the root cause of the issue is passing function calling to num_threads() .

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 17, 2015 9:06 AM
  • Hi May,

    the sample code I provided compiles "as is" under VS 2015, VS 2013 and VS 2012 on my computer.
    Maybe you forgot to enable OMP in the project options? Or chose the wrong compiler tool set?

    The reference is the for directive:
    https://msdn.microsoft.com/en-us/library/6z19s8e0.aspx

    Since I specify parallel, clauses can be any of those for the parallel directive, except nowait:
    https://msdn.microsoft.com/en-us/library/68ah4xc7.aspx

    So #pragma omp parallel for num_threads is syntactically correct.

    Your code is different from what is intended. You have num_threads threads and each of those threads executes the for loop. You finally have num_threads * 100 iterations. You can see that in the console output (for example, index 0 is executed eight times). This is not a parallel for loop.

    If I specify a numeric value and not a function inside num_threads, it works as expected.
    But the point is: the OpenMP standard explicitly allows an expression that yields a reasonable integer number (something greater than zero) as the parameter to num_threads.
    It need not be a numeric value specified at compile time or a global variable specified at run-time. It can be a function.

    And you're absolutely correct: the root cause is passing n() to num_threads although it is legal!
    Only Update 1 has this issue. It was never an issue before Update 1.
    I suspect the compiler developers accidentally messed something up here.
    Since you work for Microsoft would you please let them know?
    I consider this a serious bug that breaks existing code, and not in a good way.





    • Edited by powerchord Friday, December 18, 2015 1:01 PM
    Friday, December 18, 2015 9:57 AM
  • Hi,

    Thanks for your feedback.

    And I am really sorry that I forgot to enable OMP in the project options. Sorry about this.

    After setting the OMP options, I can compile the code you provided successfully with the #pragma omp parallel for num_threads.

    >Only Update 1 has this issue. It was never an issue before Update 1.

    Yes, with VS2015,VS2013,VS2010, we don't have such issue. Only for VS2015 update1 has such issue. I think you can submit this issue to connect, there will be product team engineer to help further.

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 21, 2015 8:45 AM
  • Hi May,

    thanks.
    Now that you can reproduce this issue please do me a favor and vote on Connect:

    https://connect.microsoft.com/VisualStudio/feedback/details/2135136/vs-2015-update-1-openmp-parallel-for-num-threads-does-not-work-anymore

    Maybe, just maybe that will speed it up. And every affected program "only" needs to wait six months for Update 2.

    Tuesday, December 22, 2015 9:15 AM
  • Hi,

    Thanks for your feedback.

    I will vote the issue and hope it can help you.

    Best Regards,

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 23, 2015 5:42 AM