Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why does the compiler insert a malloc statement in this function?

807575May 14 2010 — edited May 20 2010
In [this thread about OpenMP scaling|http://forums.sun.com/thread.jspa?threadID=5426481&tstart=0] I learned that it is very bad to have heap allocation, effectively calls to the malloc() function, in OpenMP parallel sections. Well, that much one can figure -- the deeper insight fwas about how quickly the compiler can start adding malloc() for temporary variables in computations.

So I went and dumbed down computations all around for usage of temporary variables explicitly created on the stack (as normal local variables). This enabled my OpenMP code to scale positively. But there's still much room for improvement. Now I stumbled over a pattern of malloc() calls in certain key functions that I really cannot explain. This is my question: Can someone tell me for what the Sun compiler needs heap storage in the function one_face_flux?

This is the original code (looks a bit weird because it is after preprocessing): [source code of one_face_flux|http://pastebin.com/LkqCGFgc]
And this is the [disassembly from er_print|http://pastebin.com/L4kMcR25] , intermixed with code. From the correlation of assembly with source lines indicated here, I presume that one of the local variables is put on the heap. But ... usually they are on the stack, aren't they?

I tried to include a relevant excerpt of the disassembly here, but meaningful context seems to be too big for the forum post size limit.

The corresponding free() is at the end of the function... so I have to assume that this really is for one of the local variables... or for some implicit temporary? Other cases of temporaries with malloc I've seen had the malloc more local to the actual line where the temporary is used.
I just though about tracing what amount of memory is actually allocated... that might give a hint to me (as I know the values of the constants used for dimensions) ... but perhaps this general pattern is known with Sun Studio? It seems to happen for some functions, but not all.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 17 2010
Added on May 14 2010
14 comments
546 views