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

Indirect definition of _ADIOS2 and _HDF5 macros for lib piof #557

Open
dqwu opened this issue Jan 12, 2024 · 0 comments
Open

Indirect definition of _ADIOS2 and _HDF5 macros for lib piof #557

dqwu opened this issue Jan 12, 2024 · 0 comments
Assignees
Labels
ADIOS All ADIOS related issues/enhancements cmake enhancement

Comments

@dqwu
Copy link
Contributor

dqwu commented Jan 12, 2024

In tests/general/util/pio_tutil.F90, several macros, namely _NETCDF4,
_NETCDF, _PNETCDF, _ADIOS2, and _HDF5, are utilized.

In the case of NetCDF/PnetCDF libraries, the macros _NETCDF4,
_NETCDF, and _PNETCDF are directly defined for lib piof in
src/flib/CMakeLists.txt:

#===== NetCDF-Fortran =====
if (WITH_NETCDF)
  find_package (NetCDF ${NETCDF_FORTRAN_MIN_VER_REQD} COMPONENTS Fortran)
  if (NetCDF_Fortran_FOUND)
    message(STATUS "NetCDF Fortran library dependencies: ${NetCDF_Fortran_LIBRARIES}")
    ...
    target_compile_definitions (piof
      PUBLIC _NETCDF)
    ...
    if (EXISTS ${NetCDF_Fortran_INCLUDE_DIR}/netcdf_par.h)
      target_compile_definitions (piof
        PUBLIC _NETCDF4)
...

#===== PnetCDF =====
if (WITH_PNETCDF)
  find_package (PnetCDF ${PNETCDF_MIN_VER_REQD} COMPONENTS Fortran)
  if (PnetCDF_FOUND)
    message(STATUS "PnetCDF Fortran library dependencies: ${PnetCDF_Fortran_LIBRARIES}")
    ...
    target_compile_definitions (piof
      PUBLIC _PNETCDF)

However, for ADIOS2/HDF5 libraries, where no Fortran components
are available, the direct definition of _ADIOS2 and _HDF5 for lib
piof in src/flib/CMakeLists.txt is not feasible.

To overcome this limitation, a workaround is to define these macros
for lib pioc in src/clib/CMakeLists.txt. Consequently, they are indirectly
defined for lib piof.

For _HDF5, it will be something like:

#===== HDF5-C =====
if (WITH_HDF5)
  find_package (HDF5 COMPONENTS HL C)
  if (HDF5_C_FOUND)
    ...
    target_compile_definitions (pioc
      PUBLIC _HDF5)

The current definition of _ADIOS2 for lib adios2pio-nm-lib in
tools/adios2pio-nm/CMakeLists.txt may need to be relocated to
src/clib/CMakeLists.txt to ensure consistency for lib pioc:

if (ADIOS2_FOUND)
  target_compile_definitions (adios2pio-nm-lib
    PUBLIC _ADIOS2)

It is worth noting that this workaround introduces a minor issue
related to duplicate macro definitions. On one hand, _ADIOS2 and
_HDF5 are defined using CMake's target_compile_definitions() for
lib pioc. On the other hand, they are also explicitly defined in
pio.h of lib pioc:

#if PIO_USE_ADIOS
  #define _ADIOS2 1
#endif
#if PIO_USE_HDF5
  #define _HDF5 1
#endif
@dqwu dqwu added enhancement ADIOS All ADIOS related issues/enhancements cmake labels Jan 12, 2024
jayeshkrishna added a commit that referenced this issue Jan 12, 2024
The Fortran code relies on these flags to determine support for
ADIOS and HDF5 libraries. For NetCDF and PnetCDF libraries the
Fortran library, piof, includes config tests for the Fortran
libraries of these 3rd party libs. However ADIOS and HDF5
do not have these config tests (and Fortran libs) in the Fortran
library.

So exporting these flags from the pioc lib for all dependent libs.
(Note: _ADIOS2 flag was being exported inadvertently via the ADIOS
conversion library, now it has been correctly moved out to the
pioc lib config)

See Issue #557
jayeshkrishna added a commit that referenced this issue Feb 5, 2024
The Fortran code relies on these flags to determine support for
ADIOS and HDF5 libraries. For NetCDF and PnetCDF libraries the
Fortran library, piof, includes config tests for the Fortran
libraries of these 3rd party libs. However ADIOS and HDF5
do not have these config tests (and Fortran libs) in the Fortran
library.

So exporting these flags from the pioc lib for all dependent libs.
(Note: _ADIOS2 flag was being exported inadvertently via the ADIOS
conversion library, now it has been correctly moved out to the
pioc lib config)

See Issue #557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADIOS All ADIOS related issues/enhancements cmake enhancement
Projects
None yet
Development

No branches or pull requests

2 participants