Getting false behaviour using OpenMP's for directive with 2015 compiler RRS feed

  • Question

  • I'm getting a rather odd behaviour of the OpenMP "for" directive.

    First, something about the project: We are developing an extension for AutoCAD (AutoDesk's CAD software) and need to provide for versions from 2010 onwards. Meaning, we use the VS compilers from 2008, 2010, 2012 and right now are in the process of providing for the new AutoCAD 2017 version with the 2015 compiler. We use the IDE of 2008 and link the compilers into it.

    Everything went fine, except for one strange thing. Observe the following code
    (sidenote: log.LogString(..) is a function, that writes to a private log file, similar to printf(..) to console, except it always hangs the thread's number in front):

    CLogFile log;
    CString str;
    int ggg = 97;
    #pragma omp parallel default(none) shared(log, ggg) private(str)
        #pragma omp master
            str.Format(_T("Threads Number: %d."), omp_get_num_threads());
        #pragma omp for
        for(int i=0; i<ggg; i++)
            int a=0;
            for(int j=0; j<10000000; j++)
                a+=j; //do something, so that it lasts for at least some time
            str.Format(_T("Doing: %3d."), i);
        } //here the threads do not wait ...

    In the version compiled with the 2008 compiler it works as expected, however in the version compiled with the 2015 compiler, the last lines of the output look like this:

    1: Doing: 24.
    0: Doing: 11. 1: Finished! 7: Finished! 2: Finished! 3: Finished! 4: Finished! 6: Finished! 5: Finished! 0: Doing: 12.
    /end of file/

    The last "Doing:  12" should be before all the "Finished!"; also, the "0" thread does not finish at all!

    I assume, something is wrong with the implicit barrier at the end of the "for" directive, but have no clue as what to do.

    Additionally, I tried with "nowait" at "for" with an explicit "#pragma omp barrier" after the loop, it works fine. But this is a work-around!

    • Edited by StefanMarkic Tuesday, May 10, 2016 11:19 AM Typo in the title :S
    Tuesday, May 10, 2016 11:13 AM