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

C restructure #417

Merged
merged 19 commits into from
Aug 17, 2024
Merged

C restructure #417

merged 19 commits into from
Aug 17, 2024

Conversation

daviesje
Copy link
Contributor

@daviesje daviesje commented Aug 8, 2024

A draft pull request for a restructure of the C backend. #359

Changes:

  • We no longer include all headers and code in one file GenerateICs.c
  • Instead, each file includes only the headers it uses, and all #include "X.c" have been removed
  • build.cffi has been changed to make it clear which functions and definitions are available to the python wrapper.
    • CFFI requires all functions, global variables, and type definitions directly used in python to be present in cdef() calls as well as in the set_source() header files.
    • The cdef() code cannot contain compiler directives, as a result new header files were created labelled _something_wrapper.h to contain exposed definitions. these are also included in the relevant header files for the backend so we only have to edit one file to expose a function properly.
  • C files UsefulFunctions.c and ps.c have been split up into functions grouped together by their themes e.g cosmology.c thermochem.c hmf.c etc...
  • Some unused functions have been removed

Todos:

  • Make directories for different categories of files, perhaps one for the output structures and one for lower-level functions?
  • Remove the many unused variables declared throughout the code
  • Stricter typing:
    • Indices for the entire box should already be unsigned long long, but single axis indices are sometimes int or unsigned long long.
    • Many lower-level functions still use float, most of these should be double unless they are a grid which takes up significant memory/disk space Migration toward double precision floating point numbers #361
  • Think about splitting up heating_helper_progs.c as well
  • Look into another build system i.e meson
  • Set up C linting [Feature Req.] Automatic C linting #23

Copy link
Member

@steven-murray steven-murray left a comment

Choose a reason for hiding this comment

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

Couple of comments but overall this is SUPER nice. Thank you!!!

build_cffi.py Show resolved Hide resolved
build_cffi.py Show resolved Hide resolved
lib.Broadcast_struct_global_PS(up(), cp())
lib.Broadcast_struct_global_UF(up(), cp())
lib.Broadcast_struct_global_IT(up(), cp(), ap(), fo())
lib.Broadcast_struct_global_all(up(), cp(), ap(), fo())
Copy link
Member

Choose a reason for hiding this comment

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

This is not your task necessarily (certainly not in this PR) but I'd love to have a nicer lower level wrapper that just exposes these functions directly in Python style, so you could call like

broadcast_structs(up, cp, ap, fo)
```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean just adding something like the following to the wrapper? these functions are already exposed

def broadcast_inputstructs(up,cp,ap=None,fo=None):
    if not isinstance(up,UserParams) or not isinstance(cp,CosmoParams):
        raise ValueError
    if isinstance(ap,AstroParams) and isinstance(fo,FlagOptions):
        lib.Broadcast_struct_global_all(up(), cp(), ap(), fo())

    lib.Broadcast_struct_global_noastro(up(), cp())

Copy link
Member

Choose a reason for hiding this comment

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

Exactly.

@daviesje daviesje marked this pull request as ready for review August 13, 2024 14:54
@daviesje daviesje merged commit 818f1ab into v4-prep Aug 17, 2024
3 of 12 checks passed
@daviesje daviesje deleted the c-restructure branch August 17, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

C build reorganisation
2 participants