Fix GPTL to support 7-digit PIDs and fix some error handling - #5056
Conversation
The previous file length allowed PIDs larger than 6 digits. Modern OSs can have PIDs of 7 digits. Here we increase the 'file' string further to allow more future flexibility. In addition, this introduces a check to make this safer. Code written by Claude, carefully reviewed by myself.
Upon error, fopen returns NULL, not an integer < 0. Issue found and fixed by Claude, reviewed by myself.
|
@jgfouca @jasonb5 or others - do you know the story with this GPTL code? I know there is an external GPTL library, but it looks like we are out of sync with that, at least for this file, and from what I can tell, it looks like recent changes have been made directly to the GPTL here rather than patching upstream and pulling it in via a subtree / submodule. |
|
I do not, sorry. |
|
We use the version kept in E3SM/share/timing which is almost the same code. They diverged from the upstream a long time ago. Back when CIME had a driver and data models, maybe this was the timing library built with those CIME-only applications. Or we include it as a feature that comes with CIME that a model can use? |
|
What application is @klindsay28 using that is linking to this version? |
|
CESM apparently is still using this version. At least, changes I made in this version clearly had an impact on a CESM run. I was surprised because I didn't think we were using any Fortran code from CIME anymore, but apparently we are. But if E3SM isn't using this version, I'll reassign it to someone on the CESM side for review. |
Description
GPTLget_memusage had a hard-coded string size that only supported PIDs up to 6 digits. This caused problems on derecho, where PIDs can be up to 7 digits. This PR allows for significantly longer PIDs (longer than will be encountered in practice) and adds error checking of the relevant sprintf (changing it to snprintf with a check). In addition, this fixes the error check on another line, as noticed by Claude.
Changes were made by Claude and carefully reviewed by myself
Testing
I tested this via SMS_D_Ld2_P128x1.f19_g17.X.derecho_intel
In addition, with this diff:
I verified that we now get an abort rather than writing past the end of the
filestring:Checklist