[flang-commits] [flang] [flang][OpenMP] Allocate array reduction variables on the heap (PR #87773)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Sun Apr 7 04:51:33 PDT 2024


kiranchandramohan wrote:

Allocating on the stack vs heap has some tradeoffs with OpenMP. If there are a large number of threads and if the memory required is high then there is a possibility that we run out of stack space. On the other hand, allocating on the heap probably takes more time. The runtime probably uses locks so I guess it is safe, but please check.

> Reductions might be inlined inside of a loop so stack allocations are not safe.

We could use stacksave and stackrestore as well. This was the original suggestion in the patch.
https://llvm.org/docs/LangRef.html#llvm-stacksave-intrinsic
https://llvm.org/docs/LangRef.html#llvm-stackrestore-intrinsic

https://github.com/llvm/llvm-project/pull/87773


More information about the flang-commits mailing list