Conversation
1832b49 to
59ab170
Compare
fcaf2e3 to
d2fbfbc
Compare
- provide C enums - add atom and molecule types - add basis set and shell definitions - add molecule grid and runtime environment - add load balancer to C API - add molecular weights for C API - add functional class wrapping ExchCXX - add xc integrator and matrix type - add references for functionals - add support for reading and writing from HDF5 in C
There was a problem hiding this comment.
Pull request overview
This pull request adds Fortran/C bindings to GauXC to enable integration with legacy Fortran codes. The implementation introduces a C API layer and Fortran interfaces that bind to the C functions using iso_c_binding.
Changes:
- Added C API with headers and implementation for core functionality (molecule, basisset, matrix, integrator, etc.)
- Added Fortran modules that interface with the C API using
iso_c_binding - Updated build system to support optional C and Fortran API compilation via CMake options
- Added test coverage for C API interoperability in existing test files
Reviewed changes
Copilot reviewed 66 out of 66 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| CMakeLists.txt | Added GAUXC_ENABLE_C and GAUXC_ENABLE_FORTRAN options with build logic |
| src/CMakeLists.txt | Conditional compilation of C/Fortran sources based on enabled features |
| include/gauxc/*.h | C API headers for all major components (molecule, basisset, matrix, integrator, etc.) |
| src/c_*.cxx | C API implementation wrapping C++ classes |
| src/.f90, src/.F90 | Fortran modules providing iso_c_binding interfaces to C API |
| include/gauxc/util/c_*.hpp | Helper utilities for C-C++ interop (pointer casting, conversions) |
| include/gauxc/gauxc_config.{h,f}.in | Configuration templates for C/Fortran feature detection |
| tests/moltypes_test.cxx | Added C API interoperability tests |
| src/external/c_hdf5_{read,write}.cxx | C API for HDF5 I/O operations |
| src/external/hdf5_{read,write}.f90 | Fortran wrappers for HDF5 operations |
Comments suppressed due to low confidence (1)
include/gauxc/gauxc_config.h.in:14
- The configuration macro
GAUXC_HAS_Cis defined in gauxc_config.f.in (line 1) but missing from gauxc_config.h.in. This creates an inconsistency where C/C++ code won't have access to theGAUXC_HAS_Cmacro to conditionally compile C API code, even though it's available in Fortran. Add#cmakedefine GAUXC_HAS_Cto gauxc_config.h.in.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #else | ||
| & (status) & | ||
| #endif | ||
| & result(rt) bind(c) |
There was a problem hiding this comment.
Make sure that the c variant is called which transforms the fortran MPI communicator
| & result(rt) bind(c) | |
| & result(rt) bind(c, name="gauxc_runtime_environment_new_fortran") |
| delete detail::get_basisset_ptr(*basis); | ||
| basis->ptr = nullptr; | ||
| } | ||
|
|
There was a problem hiding this comment.
Add some additional routines to querry info in basisset object. I found it useful to check during debugging.
| int32_t gauxc_basisset_nshells(GauXCStatus* status, const GauXCBasisSet basis) { | |
| status->code = 0; | |
| if (basis.ptr == nullptr) { | |
| status->code = 1; | |
| status->message = "No basis set associated to this object"; | |
| return 0; | |
| } | |
| return detail::get_basisset_ptr(basis)->nshells(); | |
| } | |
| int32_t gauxc_basisset_ngtos(GauXCStatus* status, const GauXCBasisSet basis) { | |
| status->code = 0; | |
| if (basis.ptr == nullptr) { | |
| status->code = 1; | |
| status->message = "No basis set associated to this object"; | |
| return 0; | |
| } | |
| return detail::get_basisset_ptr(basis)->nbf(); | |
| } |
| !> @return Pointer to the newly created basis set object | ||
| type(gauxc_basisset_type) :: basis | ||
| end function gauxc_basisset_new_from_shells | ||
| end interface |
There was a problem hiding this comment.
Interface the additional basis set routines also from fortran
| end interface | |
| integer(c_int32_t) function gauxc_basisset_nshells(status, basis) bind(c) | |
| import :: c_int32_t, gauxc_status_type, gauxc_basisset_type | |
| implicit none | |
| !> @param status Status of the operation | |
| type(gauxc_status_type), intent(out) :: status | |
| type(gauxc_basisset_type), value :: basis | |
| end function | |
| integer(c_int32_t) function gauxc_basisset_ngtos(status, basis) bind(c) | |
| import :: c_int32_t, gauxc_status_type, gauxc_basisset_type | |
| implicit none | |
| !> @param status Status of the operation | |
| type(gauxc_status_type), intent(out) :: status | |
| type(gauxc_basisset_type), value :: basis | |
| end function | |
| end interface |
| } | ||
| return env; | ||
| } | ||
|
|
There was a problem hiding this comment.
Add a variant which additionally transforms a fortran MPI communicator to the c-version
| GauXCRuntimeEnvironment gauxc_runtime_environment_new_fortran( | |
| GauXCStatus* status | |
| GAUXC_MPI_CODE(, MPI_Fint f_comm) | |
| ) { | |
| MPI_Comm c_comm; | |
| c_comm = MPI_Comm_f2c(f_comm); | |
| return gauxc_runtime_environment_new(status GAUXC_MPI_CODE(, c_comm)); | |
| } | |
Closes #66