Does OpenMP move stack or data variables to the heap if they are shared?

后端 未结 1 1850
死守一世寂寞
死守一世寂寞 2021-01-21 18:02

I\'m watching this Introduction to OpenMP series of videos, and the presenter keeps repeating that \"heap is shared, stack is private\". It is also mentioned that data and text

相关标签:
1条回答
  • 2021-01-21 18:21

    The wording (stack/heap) is imprecise

    The OpenMP standard makes no reference1 to stack or heap in it's memory model. So I would answer your question with implementation defined. I see no reason to move the data of stack variables to the heap if they are shared. If you see by looking at pointers of shared variables, that they are on the stack, I would in fact believe that.

    Even the C standard contains no reference to either stack or heap.

    In my opinion you should not use the concepts that aren't part of the standards (and hence depend on implementation) to reason about correctness. Instead use storage duration and scopes.

    I speculate that Tim Mattson uses stack/heap because they may be more broadly known.

    1 OpenMP allows control of the stacksize for threads, but with no further reference what the stack is.

    The particular example you pointed out is wrong

    even if you consider the simplification:

    • automatic storage duration == "stack"
    • allocated/dynamic2 storage duration == "heap"

    Your analysis is correct, the citation applies. As per 2.15.1.1, there is no predetermined data-sharing rule for objects with automatic storage duration that is not declared in a scope inside the construct. Hence it is a variable with implicitly determined data-sharing attributes.

    2 Confusingly, the C standard uses "allocated storage duration" while C++ and OpenMP use "dynamic storage duration".

    0 讨论(0)
提交回复
热议问题