Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macro for consistent sunrealtype formatting #517

Open
wants to merge 44 commits into
base: develop
Choose a base branch
from

Conversation

Steven-Roberts
Copy link
Collaborator

Replaces #498 after v7.1.0 update

src/sundials/sundials_utils.h Outdated Show resolved Hide resolved
src/ida/ida_io.c Outdated Show resolved Hide resolved
src/nvector/parhyp/nvector_parhyp.c Outdated Show resolved Hide resolved
src/nvector/parallel/nvector_parallel.c Outdated Show resolved Hide resolved
src/nvector/openmpdev/nvector_openmpdev.c Outdated Show resolved Hide resolved
test/answers Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to open a PR in the answers repo to merge these updates into main

include/sundials/sundials_linearsolver.h Show resolved Hide resolved
include/sundials/sundials_nonlinearsolver.h Show resolved Hide resolved
include/sundials/sundials_types.h Outdated Show resolved Hide resolved
#if defined(SUNDIALS_SINGLE_PRECISION)

typedef float sunrealtype;
#define SUN_RCONST(x) x##F
#define SUN_BIG_REAL FLT_MAX
#define SUN_SMALL_REAL FLT_MIN
#define SUN_UNIT_ROUNDOFF FLT_EPSILON
#define SUN_FORMAT_E "% ." SUN_STRING(FLT_DIG) "e"
#define SUN_FORMAT_G "% ." SUN_STRING(FLT_DIG) "g"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the updated outputs with "% ." I think it would be better to have this macro not include % (i.e., use #define SUN_FORMAT_G "." SUN_STRING(FLT_DIG) "g". This way the space after % can be added locally in the format string when it's needed for alignment (i.e., outputting matrix/vector entries) and in other cases (like PrintAllStats) the space can be excluded.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the new output file format is not ideal with double spaces for positive numbers. What about this?

#define SUN_FORMAT_E      "% ." SUN_STRING(FLT_DIG) "e"
#define SUN_FORMAT_G      "%." SUN_STRING(FLT_DIG) "g"

Note I just removed a space from the g format. We can use SUN_FORMAT_E for cases where alignment is needed (I think this is already the case), and SUN_FORMAT_G elsewhere. We could even rename them to SUN_FORMAT_ALIGNED and SUN_FORMAT. I like the simplicity and consistency of just two macros which contain the entire format specifier. Let's discuss at tomorrow's meeting.

@balos1 balos1 added this to the SUNDIALS Next milestone Sep 10, 2024
@Steven-Roberts
Copy link
Collaborator Author

Aside from updating outfiles, I think this is ready. Before I spend the time updating all of those (just logging test out files updated for now) which will make the PR diff enormous, I wanted to see if there's any suggestions on the format, name of macros, etc.

Copy link
Collaborator

@drreynolds drreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial feedback on the PR. Overall I think this is really helpful, but I have a few questions.

src/arkode/arkode.c Show resolved Hide resolved
@@ -1290,132 +1290,63 @@ int arkStep_PrintAllStats(ARKodeMem ark_mem, FILE* outfile, SUNOutputFormat fmt)
retval = arkStep_AccessStepMem(ark_mem, __func__, &step_mem);
if (retval != ARK_SUCCESS) { return (retval); }

switch (fmt)
/* function evaluations */
sunfprintf_long(outfile, fmt, SUNFALSE, "Explicit RHS fn evals", step_mem->nfe);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how the new sunfprintf functions really tighten things up with the table-vs-csv output, but it would be nice if these were documented somewhere (e.g., in the developer guide), since it took me a while to discover their definitions inside src/sundials/sundials_utils.h.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, have the outputs from these been compared with the previous outputs (especially for the CSV)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how the new sunfprintf functions really tighten things up with the table-vs-csv output

Credit to @gardner48 from an earlier incarnation of this PR

it would be nice if these were documented somewhere

Agreed

Also, have the outputs from these been compared with the previous outputs (especially for the CSV)?

I haven't. Looks like there's some test that use CSV output, so I'll check those diffs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice if these were documented somewhere

Agreed

The documentation could go in this section of the developer guide.

Also, have the outputs from these been compared with the previous outputs (especially for the CSV)?

I haven't. Looks like there's some test that use CSV output, so I'll check those diffs.

I checked this manually in the initial implementation but we should add a unit test to catch any regressions

src/arkode/arkode_butcher.c Show resolved Hide resolved
Comment on lines +35 to +37
%ignore SUN_FORMAT_E;
%ignore SUN_FORMAT_G;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these %ignore have undesirable consequences, e.g., if Swig ends up processing a header file that includes a print statement that uses one of these?

Copy link
Collaborator Author

@Steven-Roberts Steven-Roberts Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format macros are only used in src/**/*.c files, so I don't think it should be a problem. No compilation issues for me. Any concerns @balos1?

include/sundials/sundials_types.h Outdated Show resolved Hide resolved
@@ -1290,132 +1290,63 @@ int arkStep_PrintAllStats(ARKodeMem ark_mem, FILE* outfile, SUNOutputFormat fmt)
retval = arkStep_AccessStepMem(ark_mem, __func__, &step_mem);
if (retval != ARK_SUCCESS) { return (retval); }

switch (fmt)
/* function evaluations */
sunfprintf_long(outfile, fmt, SUNFALSE, "Explicit RHS fn evals", step_mem->nfe);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice if these were documented somewhere

Agreed

The documentation could go in this section of the developer guide.

Also, have the outputs from these been compared with the previous outputs (especially for the CSV)?

I haven't. Looks like there's some test that use CSV output, so I'll check those diffs.

I checked this manually in the initial implementation but we should add a unit test to catch any regressions

src/arkode/arkode_butcher.c Show resolved Hide resolved
src/arkode/arkode_erkstep_io.c Show resolved Hide resolved
src/arkode/arkode_lsrkstep.c Outdated Show resolved Hide resolved
src/sundials/sundials_utils.h Show resolved Hide resolved
@gardner48
Copy link
Member

gardner48 commented Dec 18, 2024

Aside from updating outfiles, I think this is ready. Before I spend the time updating all of those (just logging test out files updated for now) which will make the PR diff enormous, I wanted to see if there's any suggestions on the format, name of macros, etc.

The updateOutFiles.py script can help with updating the files. It will copy the .out files for any failed tests in a CI artifact to a given directory:

  1. Download the output_files.zip artifact from the CI job
  2. Unzip the file to get a directory named something like build_single_32_both_ON_DEV_7c819c41fc23
  3. Copy the files to the desired location: ./scripts/updateOutFiles.py ~/Downloads/build_single_32_both_ON_DEV_7c819c41fc23 test/answers/linux-ubuntu20.04-x86_64/gcc-9.4.0/single

Copy link
Member

@gardner48 gardner48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor doc formatting items otherwise this looks good to me

doc/superbuild/source/developers/source_code/Style.rst Outdated Show resolved Hide resolved
doc/superbuild/source/developers/source_code/Style.rst Outdated Show resolved Hide resolved
doc/superbuild/source/developers/source_code/Style.rst Outdated Show resolved Hide resolved
doc/superbuild/source/developers/source_code/Style.rst Outdated Show resolved Hide resolved
doc/superbuild/source/developers/source_code/Style.rst Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants