Skip to content

[newchem-cpp] initial transcription of cool_multi_time_g#275

Merged
mabruzzo merged 34 commits into
grackle-project:newchem-cppfrom
mabruzzo:gen2024-transcribe_cool_multi_time_g
Jun 12, 2025
Merged

[newchem-cpp] initial transcription of cool_multi_time_g#275
mabruzzo merged 34 commits into
grackle-project:newchem-cppfrom
mabruzzo:gen2024-transcribe_cool_multi_time_g

Conversation

@mabruzzo

@mabruzzo mabruzzo commented Mar 20, 2025

Copy link
Copy Markdown
Collaborator

This PR was originally proposed as brittonsmith#19


This PR includes changes from #274 (it should be merged first)


This PR converts cool_multi_time_g from Fortran to C++. Along the way, I have refactored a bunch of local variables into new structs (these may not be perfectly organized right now, but they are probably good enough to move on from right now). It also introduces a lot of machinery for needed for supporting C++ files in Grackle (some of these can be reconsidered in the future).

It may be easiest to review this PR commit-by-commit (I performed a sequence of logical transformations to group together local variables).

OpenMP should work properly in the transcribed version of this routine (it is broken in the version of cool_multi_time_g.F currently in the newchem-cpp branch. With that said, I have not tested it because the OpenMP support is broken in other parts of the newchem-cpp branch -- it will be hard to do that until after we merge in all of the other transcribed routines (in each case, I took steps to try to fix it).

While transferring the PR, I added a commit that adopts a more general solution for properly linking the C++ runtime library when using the classic build-system.


Be aware, some future PRs (they have not been ported to this repository yet), brittonsmith#24 and brittonsmith#25, will make some additional modifications to cool_multi_time_g.

ChristopherBignamini and others added 20 commits December 27, 2024 10:17
A handful of c functions had a `[-Wreturn-type]` compiler warning where
a function was supposed to return a value but had at least 1 control
flow branch where we didn't return anything.

Also fixed a spot in `c_local_example` where we were passing a
`chemistry_data**` ptr to `local_free_chemistry_data` rather than a
`chemistry_data*` ptr.
To aide with transcription to C/C++ I made the following tweaks to
`calc_grain_size_increment_1d.F`:
- Within `calc_grain_size_increment_1d`, I broke lines similar to
    `SN_i(nSN) =  1; SN_metal(:,nSN) = metal_loc(:,j,k)`
  into 2 separate lines.
  - Prior to this commit, there were essentially 2 statements on each
    of these lines (the statements are delimited by `;`)
  - The transcription routines can't currently handle cases like this
    (it assumes that there is only 1 statement on each line)
  - I made changes like this in 12 locations.
- I inserted `#include "grackle_fortran_types.def"` into
  `solve_cubic_equation` to declare the ``pi_val`` macro inside of the
  subroutine's parameter declarations.
  - This is a convention followed by nearly every subroutine
    declaration in Fortran and it simplifies the process of
    transcription.
  - A standard Fortran compiler does not technically require this change
    since the header is already included within the body of different
    subroutine earlier in the file and the macro definition carries over
    from there.
A handful of c functions had a `[-Wreturn-type]` compiler warning where
a function was supposed to return a value but had at least 1 control
flow branch where we didn't return anything.

Also fixed a spot in `c_local_example` where we were passing a
`chemistry_data**` ptr to `local_free_chemistry_data` rather than a
`chemistry_data*` ptr.
`make dep` previously didn't work correctly with some of the C++ files
(I think because I changed the suffix of the names of some headers)
This is the last commit in a sequence where we were refactoring the
local variable declarations. The routine should now work properly with
OpenMP, but we can't test that since OpenMP-support was broken in
earlier commits to the gen2024 branch (before we began the
transcription).

More simplifications can certainly be made, but it is worth holding off
on that until after we have transcribed more of Grackle.
Previously, I had manually specified the name of the C++ runtime library
and had libtool directly invoke the system's linker. However, the
default C++ runtime library (assumed during compilation) varies across
machine and architecture and it would involve specifying the the library
in **every** configuration Makefile.

This strategy is better since the C++ compiler knows exactly what it
needs. It is also considered a general "best practice" (apparently,
it can be important on some architectures for more that just knowing
the proper C++ runtime library)
@mabruzzo mabruzzo changed the title Gen2024 transcribe cool multi time g [newchem-cpp] initial transcription of transcribe cool_multi_time_g Mar 20, 2025
@mabruzzo mabruzzo changed the title [newchem-cpp] initial transcription of transcribe cool_multi_time_g [newchem-cpp] initial transcription of cool_multi_time_g Mar 20, 2025
@mabruzzo mabruzzo moved this from In Progress to Awaiting Review in New Chemistry and C++ Transcription Mar 20, 2025
@mabruzzo mabruzzo added the refactor internal reorganization or code simplification with no behavior changes label Mar 24, 2025
@mabruzzo mabruzzo force-pushed the gen2024-transcribe_cool_multi_time_g branch from 02c22b3 to e54c32f Compare April 16, 2025 15:23
@mabruzzo mabruzzo changed the base branch from newchem-cpp to main June 11, 2025 14:10
@mabruzzo mabruzzo changed the base branch from main to newchem-cpp June 11, 2025 14:10
@brittonsmith brittonsmith changed the base branch from newchem-cpp to main June 11, 2025 16:35
@brittonsmith brittonsmith changed the base branch from main to newchem-cpp June 11, 2025 16:35

@brittonsmith brittonsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Quite simple and happy to see this go in. I like the simplification of the new data structures. I had the comments about how we're doing the looping and array indexing, but they are minor. One other general comment. I think we can eventually (if not now) move away from the abbreviated fortran-style file naming convention that gives us cool_multi_time to something a bit more expressive.

Edit: I forgot to say that I haven't reviewed the status reporting PR (#269), so maybe this acceptance is provisional on my approving that.

Comment thread src/clib/cool_multi_time_g-cpp.C
Comment thread src/clib/cool_multi_time_g-cpp.C
@mabruzzo

Copy link
Copy Markdown
Collaborator Author

I simply cherry-picked the most recent commit that I added to #269

@mabruzzo mabruzzo merged commit 23e182d into grackle-project:newchem-cpp Jun 12, 2025
5 checks passed
@mabruzzo mabruzzo deleted the gen2024-transcribe_cool_multi_time_g branch June 12, 2025 16:03
@github-project-automation github-project-automation Bot moved this from Awaiting Review to Done in New Chemistry and C++ Transcription Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor internal reorganization or code simplification with no behavior changes

Projects

Development

Successfully merging this pull request may close these issues.

3 participants