I'm learning unified parallel C for a high performance computing course.
Can someone please explain why it's "not recommended" to have a shared pointer to local memory?
The only reason I can think of is having a dangling pointer.
Please see the reference images:
[
Sources: http://hpac.rwth-aachen.de/teaching/sem-lsc-13/UPC.pdf http://www.cs.fsu.edu/~engelen/courses/HPC/Languages.pdf
You're correct - the reason is essentially the likelihood of a dangling pointer.
More specifically, a pointer-to-local value is generally only meaningful to the thread which created it, so placing that value in a shared datastructure often makes no sense, since other threads can only treat it as an opaque value that cannot be safely dereferenced. Moreover, a pointer-to-local value cannot be queried for affinity information, so the wider data structure or algorithm would need to somehow maintain that affinity information in order to know where the pointer was valid for use.