diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f8560fed6..a6b861416 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -30,6 +30,7 @@ jobs: - build_type: Debug build_shared_libs: OFF do_fortran: ON + api_prefix: gha - build_type: Release build_shared_libs: ON os: ubuntu-24.04 @@ -69,6 +70,7 @@ jobs: -D LIBINT2_ENABLE_FORTRAN=${{ matrix.do_fortran }} -D LIBINT2_ENABLE_PYTHON=ON -D LIBINT2_EXPORT_COMPRESSOR=${{ matrix.compressor }} + -D LIBINT2_API_PREFIX=${{ matrix.api_prefix }} outputs: should_skip: ${{ steps.skip_check.outputs.should_skip }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d767bdcc..f78341d28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -272,8 +272,8 @@ option_with_print(LIBINT2_GENERATE_FMA "Generate FMA (fused multiply-add) instructions (to benefit must have FMA-capable hardware and compiler)" OFF) option_with_print(LIBINT2_ENABLE_GENERIC_CODE "Use manually-written generic code" OFF) -option_with_print(LIBINT2_API_PREFIX - "Prepend this string to every name in the library API (except for the types)." OFF) +option_with_default(LIBINT2_API_PREFIX + "Prepend this string to every name in the library API (except for the types)." "") option_with_print(LIBINT2_VECTOR_LENGTH "Compute integrals in vectors of length N." OFF) option_with_default(LIBINT2_VECTOR_METHOD diff --git a/INSTALL.md b/INSTALL.md index b458a0960..dd4178010 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -357,7 +357,7 @@ Note that options, docs, and CMake components are focused on the C++ interface, * `LIBINT_ALIGN_SIZE` - G - If posix_memalign is available, this will specify alignment of Libint data, in units of sizeof(LIBINT2_REALTYPE). Default is to use built-in heuristics: system-determined for vectorization off (default) or veclen * sizeof(LIBINT2_REALTYPE) for vectorization on. (experts only). [Default=0] * `LIBINT2_GENERATE_FMA` - G - Generate FMA (fused multiply-add) instructions (to benefit must have FMA-capable hardware and compiler). [Default=OFF] * `LIBINT2_ENABLE_GENERIC_CODE` - G - Use manually-written generic code. [Default=OFF] -* `LIBINT2_API_PREFIX` - G - Prepend this string to every name in the library API (except for the types). [Default=OFF] +* `LIBINT2_API_PREFIX` - G - Prepend this string to every name in the library API (except for the types). [Default=""] * `LIBINT2_VECTOR_LENGTH` - G - Compute integrals in vectors of length N. [Default=OFF] * `LIBINT2_VECTOR_METHOD` - G - Specifies how to vectorize integrals. Irrelevant when `LIBINT2_VECTOR_LENGTH=OFF. Allowed values are 'block' and 'line'. [Default=block] * `LIBINT2_ACCUM_INTS` - G - Accumulate integrals to the buffer, rather than copy (OFF for copy, ON for accum). [Default=OFF] diff --git a/cmake/modules/options.cmake b/cmake/modules/options.cmake index 921dc7371..117160680 100644 --- a/cmake/modules/options.cmake +++ b/cmake/modules/options.cmake @@ -53,13 +53,13 @@ macro(option_with_default variable msge default) # TODO: need to namespace all Libint-specific cmake variables # disabled for now, pending discussion with @loriab if (TRUE OR ${variable} MATCHES "^LIBINT_") - print_option(${variable} ${default}) + print_option(${variable} "${default}") if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "") set(${variable} "${default}" CACHE STRING "${msge}" FORCE) endif() else () set(_libint_var LIBINT_${variable}) - print_option(${_libint_var} ${default}) + print_option(${_libint_var} "${default}") if(NOT DEFINED ${_libint_var} OR "${${_libint_var}}" STREQUAL "") if(DEFINED ${variable} AND (NOT "${${variable}}" STREQUAL "")) set(${_libint_var} "${variable}" CACHE STRING "${msge}" FORCE) diff --git a/export/fortran/libint_f.F90 b/export/fortran/libint_f.F90 index f68fa2588..0293da5e3 100644 --- a/export/fortran/libint_f.F90 +++ b/export/fortran/libint_f.F90 @@ -5,6 +5,15 @@ MODULE libint_f #include #include "fortran_incldefs.h" +/* Macro to form BIND(C, NAME=...) with API prefix for Fortran. + Uses LIBINT_API_PREFIX from config.h (a string literal, e.g. "gha") + and Fortran's // string concatenation operator. */ +#ifdef LIBINT_API_PREFIX +#define LIBINT2_FORTRAN_BIND(namestr) BIND(C, NAME=LIBINT_API_PREFIX // namestr) +#else +#define LIBINT2_FORTRAN_BIND(namestr) BIND(C) +#endif + IMPLICIT NONE #ifdef LIBINT2_MAX_AM @@ -59,83 +68,83 @@ MODULE libint_f #ifdef LIBINT_INCLUDE_ERI TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_eri, 0:libint2_max_am_eri, 0:libint2_max_am_eri, 0:libint2_max_am_eri), & - BIND(C) :: libint2_build_eri + LIBINT2_FORTRAN_BIND("libint2_build_eri") :: libint2_build_eri #if LIBINT_INCLUDE_ERI >= 1 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_eri1, 0:libint2_max_am_eri1, 0:libint2_max_am_eri1, 0:libint2_max_am_eri1), & - BIND(C) :: libint2_build_eri1 + LIBINT2_FORTRAN_BIND("libint2_build_eri1") :: libint2_build_eri1 #endif #if LIBINT_INCLUDE_ERI >= 2 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_eri2, 0:libint2_max_am_eri2, 0:libint2_max_am_eri2, 0:libint2_max_am_eri2), & - BIND(C) :: libint2_build_eri2 + LIBINT2_FORTRAN_BIND("libint2_build_eri2") :: libint2_build_eri2 #endif #endif #ifdef LIBINT_INCLUDE_ERI2 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_2eri, 0:libint2_max_am_2eri), & - BIND(C) :: libint2_build_2eri + LIBINT2_FORTRAN_BIND("libint2_build_2eri") :: libint2_build_2eri #if LIBINT_INCLUDE_ERI2 >= 1 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_2eri1, 0:libint2_max_am_2eri1), & - BIND(C) :: libint2_build_2eri1 + LIBINT2_FORTRAN_BIND("libint2_build_2eri1") :: libint2_build_2eri1 #endif #if LIBINT_INCLUDE_ERI2 >= 2 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_2eri2, 0:libint2_max_am_2eri2), & - BIND(C) :: libint2_build_2eri2 + LIBINT2_FORTRAN_BIND("libint2_build_2eri2") :: libint2_build_2eri2 #endif #endif #ifdef LIBINT_INCLUDE_ERI3 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_default, 0:libint2_max_am_default, 0:libint2_max_am_3eri), & - BIND(C) :: libint2_build_3eri + LIBINT2_FORTRAN_BIND("libint2_build_3eri") :: libint2_build_3eri #if LIBINT_INCLUDE_ERI3 >= 1 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_default1, 0:libint2_max_am_default1, 0:libint2_max_am_3eri1), & - BIND(C) :: libint2_build_3eri1 + LIBINT2_FORTRAN_BIND("libint2_build_3eri1") :: libint2_build_3eri1 #endif #if LIBINT_INCLUDE_ERI3 >= 2 TYPE(C_FUNPTR), DIMENSION(0:libint2_max_am_default2, 0:libint2_max_am_default2, 0:libint2_max_am_3eri2), & - BIND(C) :: libint2_build_3eri2 + LIBINT2_FORTRAN_BIND("libint2_build_3eri2") :: libint2_build_3eri2 #endif #endif INTERFACE - SUBROUTINE libint2_static_init() BIND(C) + SUBROUTINE libint2_static_init() LIBINT2_FORTRAN_BIND("libint2_static_init") END SUBROUTINE - SUBROUTINE libint2_static_cleanup() BIND(C) + SUBROUTINE libint2_static_cleanup() LIBINT2_FORTRAN_BIND("libint2_static_cleanup") END SUBROUTINE #ifdef LIBINT_INCLUDE_ERI - SUBROUTINE libint2_init_eri(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_eri(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_eri") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_eri(libint) BIND(C) + SUBROUTINE libint2_cleanup_eri(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_eri") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_eri(max_am) BIND(C) + FUNCTION libint2_need_memory_eri(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_eri") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_eri END FUNCTION #if LIBINT_INCLUDE_ERI >= 1 - SUBROUTINE libint2_init_eri1(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_eri1(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_eri1") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_eri1(libint) BIND(C) + SUBROUTINE libint2_cleanup_eri1(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_eri1") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_eri1(max_am) BIND(C) + FUNCTION libint2_need_memory_eri1(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_eri1") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_eri1 @@ -143,19 +152,19 @@ FUNCTION libint2_need_memory_eri1(max_am) BIND(C) #endif #if LIBINT_INCLUDE_ERI >= 2 - SUBROUTINE libint2_init_eri2(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_eri2(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_eri2") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_eri2(libint) BIND(C) + SUBROUTINE libint2_cleanup_eri2(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_eri2") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_eri2(max_am) BIND(C) + FUNCTION libint2_need_memory_eri2(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_eri2") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_eri2 @@ -164,38 +173,38 @@ FUNCTION libint2_need_memory_eri2(max_am) BIND(C) #endif #ifdef LIBINT_INCLUDE_ERI2 - SUBROUTINE libint2_init_2eri(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_2eri(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_2eri") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_2eri(libint) BIND(C) + SUBROUTINE libint2_cleanup_2eri(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_2eri") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_2eri(max_am) BIND(C) + FUNCTION libint2_need_memory_2eri(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_2eri") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_2eri END FUNCTION #if LIBINT_INCLUDE_ERI2 >= 1 - SUBROUTINE libint2_init_2eri1(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_2eri1(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_2eri1") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_2eri1(libint) BIND(C) + SUBROUTINE libint2_cleanup_2eri1(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_2eri1") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_2eri1(max_am) BIND(C) + FUNCTION libint2_need_memory_2eri1(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_2eri1") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_2eri1 @@ -203,19 +212,19 @@ FUNCTION libint2_need_memory_2eri1(max_am) BIND(C) #endif #if LIBINT_INCLUDE_ERI2 >= 2 - SUBROUTINE libint2_init_2eri2(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_2eri2(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_2eri2") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_2eri2(libint) BIND(C) + SUBROUTINE libint2_cleanup_2eri2(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_2eri2") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_2eri2(max_am) BIND(C) + FUNCTION libint2_need_memory_2eri2(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_2eri2") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_2eri2 @@ -224,38 +233,38 @@ FUNCTION libint2_need_memory_2eri2(max_am) BIND(C) #endif #ifdef LIBINT_INCLUDE_ERI3 - SUBROUTINE libint2_init_3eri(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_3eri(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_3eri") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_3eri(libint) BIND(C) + SUBROUTINE libint2_cleanup_3eri(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_3eri") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_3eri(max_am) BIND(C) + FUNCTION libint2_need_memory_3eri(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_3eri") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_3eri END FUNCTION #if LIBINT_INCLUDE_ERI3 >= 1 - SUBROUTINE libint2_init_3eri1(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_3eri1(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_3eri1") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_3eri1(libint) BIND(C) + SUBROUTINE libint2_cleanup_3eri1(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_3eri1") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_3eri1(max_am) BIND(C) + FUNCTION libint2_need_memory_3eri1(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_3eri1") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_3eri1 @@ -263,19 +272,19 @@ FUNCTION libint2_need_memory_3eri1(max_am) BIND(C) #endif #if LIBINT_INCLUDE_ERI3 >= 2 - SUBROUTINE libint2_init_3eri2(libint, max_am, buf) BIND(C) + SUBROUTINE libint2_init_3eri2(libint, max_am, buf) LIBINT2_FORTRAN_BIND("libint2_init_3eri2") IMPORT TYPE(libint_t), DIMENSION(*) :: libint INTEGER(KIND=C_INT), VALUE :: max_am TYPE(C_PTR), VALUE :: buf END SUBROUTINE - SUBROUTINE libint2_cleanup_3eri2(libint) BIND(C) + SUBROUTINE libint2_cleanup_3eri2(libint) LIBINT2_FORTRAN_BIND("libint2_cleanup_3eri2") IMPORT TYPE(libint_t), DIMENSION(*) :: libint END SUBROUTINE - FUNCTION libint2_need_memory_3eri2(max_am) BIND(C) + FUNCTION libint2_need_memory_3eri2(max_am) LIBINT2_FORTRAN_BIND("libint2_need_memory_3eri2") IMPORT INTEGER(KIND=C_INT), VALUE :: max_am INTEGER(KIND=C_SIZE_T) :: libint2_need_memory_3eri2 diff --git a/export/fortran/test-eri.cc b/export/fortran/test-eri.cc index be3c4cc1d..d25381474 100644 --- a/export/fortran/test-eri.cc +++ b/export/fortran/test-eri.cc @@ -394,12 +394,15 @@ void compute_eri_c(int &contrdepth, int &deriv_order, int &am1, double *c1, erieval[0].contrdepth = p0123; #endif - if (deriv_order == 0) libint2_build_eri[am1][am2][am3][am4](erieval); + if (deriv_order == 0) + LIBINT2_PREFIXED_NAME(libint2_build_eri)[am1][am2][am3][am4](erieval); #if LIBINT_INCLUDE_ERI >= 1 - if (deriv_order == 1) libint2_build_eri1[am1][am2][am3][am4](erieval); + if (deriv_order == 1) + LIBINT2_PREFIXED_NAME(libint2_build_eri1)[am1][am2][am3][am4](erieval); #endif #if LIBINT_INCLUDE_ERI >= 2 - if (deriv_order == 2) libint2_build_eri2[am1][am2][am3][am4](erieval); + if (deriv_order == 2) + LIBINT2_PREFIXED_NAME(libint2_build_eri2)[am1][am2][am3][am4](erieval); #endif } @@ -421,19 +424,19 @@ bool test_eri_c_f(int &contrdepth, int &am1, double *c1, double *alpha1, const unsigned int max_am = std::max(std::max(am1, am2), std::max(am3, am4)); if (deriv_order == 0) { - libint2_init_eri(erieval_c, max_am, 0); - libint2_init_eri(erieval_f, max_am, 0); + LIBINT2_PREFIXED_NAME(libint2_init_eri)(erieval_c, max_am, 0); + LIBINT2_PREFIXED_NAME(libint2_init_eri)(erieval_f, max_am, 0); } #if LIBINT_INCLUDE_ERI >= 1 if (deriv_order == 1) { - libint2_init_eri1(erieval_c, max_am, 0); - libint2_init_eri1(erieval_f, max_am, 0); + LIBINT2_PREFIXED_NAME(libint2_init_eri1)(erieval_c, max_am, 0); + LIBINT2_PREFIXED_NAME(libint2_init_eri1)(erieval_f, max_am, 0); } #endif #if LIBINT_INCLUDE_ERI >= 2 if (deriv_order == 2) { - libint2_init_eri2(erieval_c, max_am, 0); - libint2_init_eri2(erieval_f, max_am, 0); + LIBINT2_PREFIXED_NAME(libint2_init_eri2)(erieval_c, max_am, 0); + LIBINT2_PREFIXED_NAME(libint2_init_eri2)(erieval_f, max_am, 0); } #endif @@ -519,19 +522,19 @@ bool test_eri_c_f(int &contrdepth, int &am1, double *c1, double *alpha1, } if (deriv_order == 0) { - libint2_cleanup_eri(erieval_c); - libint2_cleanup_eri(erieval_f); + LIBINT2_PREFIXED_NAME(libint2_cleanup_eri)(erieval_c); + LIBINT2_PREFIXED_NAME(libint2_cleanup_eri)(erieval_f); } #if LIBINT_INCLUDE_ERI >= 1 if (deriv_order == 1) { - libint2_cleanup_eri1(erieval_c); - libint2_cleanup_eri1(erieval_f); + LIBINT2_PREFIXED_NAME(libint2_cleanup_eri1)(erieval_c); + LIBINT2_PREFIXED_NAME(libint2_cleanup_eri1)(erieval_f); } #endif #if LIBINT_INCLUDE_ERI >= 2 if (deriv_order == 2) { - libint2_cleanup_eri2(erieval_c); - libint2_cleanup_eri2(erieval_f); + LIBINT2_PREFIXED_NAME(libint2_cleanup_eri2)(erieval_c); + LIBINT2_PREFIXED_NAME(libint2_cleanup_eri2)(erieval_f); } #endif diff --git a/include/libint2/engine.h b/include/libint2/engine.h index 7e29eb710..36db41821 100644 --- a/include/libint2/engine.h +++ b/include/libint2/engine.h @@ -1077,7 +1077,7 @@ class Engine { void finalize() { if (primdata_.size() != 0) { - libint2_cleanup_default(&primdata_[0]); + LIBINT2_PREFIXED_NAME(libint2_cleanup_default)(&primdata_[0]); } } // finalize() diff --git a/include/libint2/engine.impl.h b/include/libint2/engine.impl.h index 05d5808ea..a97fd914a 100644 --- a/include/libint2/engine.impl.h +++ b/include/libint2/engine.impl.h @@ -628,7 +628,7 @@ __libint2_engine_inline void Engine::_initialize() { if (lmax_ >= lmax) { \ throw Engine::lmax_exceeded(BOOST_PP_STRINGIZE(BOOST_PP_NBODYENGINE_MCR3_TASK(product)), lmax, lmax_); \ } \ - if (stack_size_ > 0) libint2_cleanup_default(&primdata_[0]); \ + if (stack_size_ > 0) LIBINT2_PREFIXED_NAME(libint2_cleanup_default)(&primdata_[0]); \ stack_size_ = LIBINT2_PREFIXED_NAME(BOOST_PP_CAT( \ libint2_need_memory_, BOOST_PP_NBODYENGINE_MCR3_TASK(product)))( \ lmax_); \ diff --git a/include/libint2/initialize.h b/include/libint2/initialize.h index 25b4fe95e..d8b8491b4 100644 --- a/include/libint2/initialize.h +++ b/include/libint2/initialize.h @@ -41,10 +41,10 @@ namespace libint2 { namespace detail { struct __initializer { __initializer() { - libint2_static_init(); + LIBINT2_PREFIXED_NAME(libint2_static_init)(); libint2::DerivMapGenerator::initialize(); } - ~__initializer() { libint2_static_cleanup(); } + ~__initializer() { LIBINT2_PREFIXED_NAME(libint2_static_cleanup)(); } }; inline std::atomic& verbose_accessor() { diff --git a/src/bin/libint/build_libint.cc b/src/bin/libint/build_libint.cc index 7baef7f1c..8b5ece9ea 100644 --- a/src/bin/libint/build_libint.cc +++ b/src/bin/libint/build_libint.cc @@ -472,7 +472,7 @@ void build_onebody_1b_1k(std::ostream& os, std::string label, std::string eval_label; { std::ostringstream oss; - oss << cparams->api_prefix() << "_" << label; + oss << "_" << label; if (deriv_level > 0) oss << "deriv" << deriv_level; BFType a(la); BFType b(lb); @@ -501,9 +501,9 @@ void build_onebody_1b_1k(std::ostream& os, std::string label, // set pointer to the top-level evaluator function ostringstream oss; - oss << context->label_to_name(cparams->api_prefix()) << "libint2_build_" - << task << "[" << la << "][" << lb - << "] = " << context->label_to_name(label_to_funcname(eval_label)) + oss << context->label_to_function_name("libint2_build_" + task) << "[" + << la << "][" << lb + << "] = " << context->label_to_function_name(eval_label) << context->end_of_stat() << endl; iface->to_static_init(oss.str()); @@ -1114,7 +1114,7 @@ void build_TwoPRep_2b_2k(std::ostream& os, // + derivative level (if deriv_level > 0) std::string label; { - label = cparams->api_prefix(); + label = ""; if (deriv_level != 0) { std::ostringstream oss; oss << "deriv" << deriv_level; @@ -1145,10 +1145,9 @@ void build_TwoPRep_2b_2k(std::ostream& os, // set pointer to the top-level evaluator function ostringstream oss; - oss << context->label_to_name(cparams->api_prefix()) - << "libint2_build_" << task << "[" << la << "][" << lb << "][" - << lc << "][" << ld - << "] = " << context->label_to_name(label_to_funcname(label)) + oss << context->label_to_function_name("libint2_build_" + task) << "[" + << la << "][" << lb << "][" << lc << "][" << ld + << "] = " << context->label_to_function_name(label) << context->end_of_stat() << endl; iface->to_static_init(oss.str()); @@ -1325,7 +1324,7 @@ void build_TwoPRep_1b_2k(std::ostream& os, // + derivative level (if deriv_level > 0) std::string label; { - label = cparams->api_prefix(); + label = ""; if (deriv_level != 0) { std::ostringstream oss; oss << "deriv" << deriv_level; @@ -1357,9 +1356,9 @@ void build_TwoPRep_1b_2k(std::ostream& os, // set pointer to the top-level evaluator function ostringstream oss; - oss << context->label_to_name(cparams->api_prefix()) << "libint2_build_" - << task << "[" << lbra << "][" << lc << "][" << ld - << "] = " << context->label_to_name(label_to_funcname(label)) + oss << context->label_to_function_name("libint2_build_" + task) << "[" + << lbra << "][" << lc << "][" << ld + << "] = " << context->label_to_function_name(label) << context->end_of_stat() << endl; iface->to_static_init(oss.str()); @@ -1523,7 +1522,7 @@ void build_TwoPRep_1b_1k(std::ostream& os, // + derivative level (if deriv_level > 0) std::string label; { - label = cparams->api_prefix(); + label = ""; if (deriv_level != 0) { std::ostringstream oss; oss << "deriv" << deriv_level; @@ -1554,9 +1553,9 @@ void build_TwoPRep_1b_1k(std::ostream& os, // set pointer to the top-level evaluator function ostringstream oss; - oss << context->label_to_name(cparams->api_prefix()) << "libint2_build_" - << task << "[" << lbra << "][" << lket - << "] = " << context->label_to_name(label_to_funcname(label)) + oss << context->label_to_function_name("libint2_build_" + task) << "[" + << lbra << "][" << lket + << "] = " << context->label_to_function_name(label) << context->end_of_stat() << endl; iface->to_static_init(oss.str()); @@ -1738,7 +1737,7 @@ void build_R12kG12_2b_2k(std::ostream& os, } std::string prefix(cparams->source_directory()); - std::string label(cparams->api_prefix() + _label); + std::string label(_label); std::deque decl_filenames; std::deque def_filenames; @@ -1754,10 +1753,9 @@ void build_R12kG12_2b_2k(std::ostream& os, tparams->max_ntarget(5); ostringstream oss; - oss << context->label_to_name(cparams->api_prefix()) - << "libint2_build_r12kg12[" << la << "][" << lb << "][" << lc - << "][" << ld - << "] = " << context->label_to_name(label_to_funcname(label)) + oss << context->label_to_function_name("libint2_build_r12kg12") << "[" + << la << "][" << lb << "][" << lc << "][" << ld + << "] = " << context->label_to_function_name(label) << context->end_of_stat() << endl; iface->to_static_init(oss.str()); @@ -1883,7 +1881,7 @@ void build_R12kG12_2b_2k_separate( } std::string prefix(cparams->source_directory()); - std::string label(cparams->api_prefix() + _label); + std::string label(_label); std::deque decl_filenames; std::deque def_filenames; @@ -1899,10 +1897,10 @@ void build_R12kG12_2b_2k_separate( tparams->max_ntarget(1); ostringstream oss; - oss << context->label_to_name(cparams->api_prefix()) - << "libint2_build_" << task_names[task] << "[" << la << "][" - << lb << "][" << lc << "][" << ld - << "] = " << context->label_to_name(label_to_funcname(label)) + oss << context->label_to_function_name( + std::string("libint2_build_") + task_names[task]) + << "[" << la << "][" << lb << "][" << lc << "][" << ld + << "] = " << context->label_to_function_name(label) << context->end_of_stat() << endl; iface->to_static_init(oss.str()); @@ -2086,10 +2084,9 @@ void build_G12DKH_2b_2k(std::ostream& os, tparams->max_ntarget(3); ostringstream oss; - oss << context->label_to_name(cparams->api_prefix()) - << "libint2_build_g12dkh[" << la << "][" << lb << "][" << lc - << "][" << ld - << "] = " << context->label_to_name(label_to_funcname(label)) + oss << context->label_to_function_name("libint2_build_g12dkh") << "[" + << la << "][" << lb << "][" << lc << "][" << ld + << "] = " << context->label_to_function_name(label) << context->end_of_stat() << endl; iface->to_static_init(oss.str()); diff --git a/src/bin/libint/buildtest.cc b/src/bin/libint/buildtest.cc index 7917408c7..604a3869f 100644 --- a/src/bin/libint/buildtest.cc +++ b/src/bin/libint/buildtest.cc @@ -70,18 +70,17 @@ void generate_rr_code(std::ostream& os, auto rr = rrstack->find_hashed(rrid).second; assert(rr); #endif - std::string rrlabel = cparams->api_prefix() + rr->label(); - os << "generating code for " << context->label_to_name(rrlabel) + os << "generating code for " << context->label_to_name(rr->label()) << " target=" << rr->rr_target()->label() << endl; - std::string decl_filename(prefix + context->label_to_name(rrlabel)); + std::string decl_filename(prefix + context->label_to_name(rr->label())); decl_filename += ".h"; - std::string def_filename(prefix + context->label_to_name(rrlabel)); + std::string def_filename(prefix + context->label_to_name(rr->label())); def_filename += ".cc"; std::basic_ofstream declfile(decl_filename.c_str()); std::basic_ofstream deffile(def_filename.c_str()); - rr->generate_code(context, ImplicitDimensions::default_dims(), rrlabel, + rr->generate_code(context, ImplicitDimensions::default_dims(), rr->label(), declfile, deffile); declfile.close(); diff --git a/src/bin/libint/buildtest.h b/src/bin/libint/buildtest.h index e0ee43f0e..a4923c022 100644 --- a/src/bin/libint/buildtest.h +++ b/src/bin/libint/buildtest.h @@ -116,7 +116,6 @@ void __BuildTest(const std::vector >& targets, const std::shared_ptr& memman, const std::string& complabel) { const std::string prefix(""); - const std::string label = cparams->api_prefix() + complabel; std::shared_ptr strat(new Strategy); std::shared_ptr context(new CppCodeContext(cparams)); @@ -181,7 +180,7 @@ void __BuildTest(const std::vector >& targets, // this will generate code for this targets, and potentially generate code for // its prerequisites GenerateCode(dg_xxxx, context, cparams, strat, tactic, memman, decl_filenames, - def_filenames, prefix, label, false); + def_filenames, prefix, complabel, false); // update max stack size taskmgr.current().params()->max_stack_size(max_am, memman->max_memory_used()); @@ -235,7 +234,7 @@ void __BuildTest(const std::vector >& targets, std::ostream_iterator(std::cout, " ")); std::cout << std::endl << "Top compute function: " - << context->label_to_name(label_to_funcname(label)) << std::endl; + << context->label_to_function_name(complabel) << std::endl; } } diff --git a/src/bin/libint/context.cc b/src/bin/libint/context.cc index 694ed2521..0d91728ca 100644 --- a/src/bin/libint/context.cc +++ b/src/bin/libint/context.cc @@ -98,6 +98,11 @@ void CodeContext::zero_out_counters() const { void CodeContext::reset() { zero_out_counters(); } +std::string CodeContext::label_to_function_name( + const std::string& label) const { + return cparams()->api_prefix() + label_to_name(label_to_funcname(label)); +} + std::string CodeContext::replace_chars(const std::string& S, const std::string& From, const std::string& To) { diff --git a/src/bin/libint/context.h b/src/bin/libint/context.h index 532ae890d..d1c48bef9 100644 --- a/src/bin/libint/context.h +++ b/src/bin/libint/context.h @@ -60,6 +60,9 @@ class CodeContext { /// label_to_name(label) converts label to a name valid within the context of /// the language virtual std::string label_to_name(const std::string& label) const = 0; + /// label_to_function_name(label) converts label to a valid function name + /// with the API prefix prepended + std::string label_to_function_name(const std::string& label) const; /** declare returns a statement which declares variable named 'name' of type 'type' */ diff --git a/src/bin/libint/dg.cc b/src/bin/libint/dg.cc index 1ef21f1dc..eded6a54f 100644 --- a/src/bin/libint/dg.cc +++ b/src/bin/libint/dg.cc @@ -1000,8 +1000,7 @@ std::string declare_function(const std::shared_ptr& context, const std::string& tlabel, const std::string& function_descr, std::ostream& decl) { - std::string function_name = label_to_funcname(function_descr); - function_name = context->label_to_name(function_name); + std::string function_name = context->label_to_function_name(function_descr); decl << context->code_prefix(); std::string func_decl; @@ -1080,8 +1079,7 @@ void DirectedGraph::generate_code( std::string func_prereq_decl; if (missing_prereqs) { std::ostringstream oss; - func_prereq_name = - context->label_to_name(label_to_funcname(label)) + "_prereq"; + func_prereq_name = label_to_funcname(label) + "_prereq"; func_prereq_decl = declare_function(context, dims, args, tlabel, func_prereq_name, oss); } @@ -1103,10 +1101,8 @@ void DirectedGraph::generate_code( for (FuncNameContainer::const_iterator fn = func_names_.begin(); fn != func_names_.end(); fn++) { string function_name = (*fn).first; - def << "#include <" - << context->label_to_name(context->cparams()->api_prefix() + - function_name) - << ".h>" << endl; + def << "#include <" << context->label_to_name(function_name) << ".h>" + << endl; } def << endl; @@ -1184,8 +1180,8 @@ void DirectedGraph::generate_code( def << context->decldef("const int", "contrdepth", "inteval->contrdepth"); def << contr_loop->open(); - def << func_prereq_name << "(inteval+c, " << registry()->stack_name() << ")" - << context->end_of_stat() << endl; + def << context->label_to_function_name(func_prereq_name) << "(inteval+c, " + << registry()->stack_name() << ")" << context->end_of_stat() << endl; def << contr_loop->close() << endl; // if profiling is on, start the next timer, after stopping the current diff --git a/src/bin/libint/hrr.h b/src/bin/libint/hrr.h index a229c8a01..073125815 100644 --- a/src/bin/libint/hrr.h +++ b/src/bin/libint/hrr.h @@ -546,8 +546,7 @@ std::string HRR::spfunction_call( const std::shared_ptr& context, const std::shared_ptr& dims) const { std::ostringstream os; - os << context->label_to_name( - label_to_funcname(context->cparams()->api_prefix() + label())) + os << context->label_to_function_name(label()) // First argument is the library object << "(inteval, " // Second is the target diff --git a/src/bin/libint/iface.cc b/src/bin/libint/iface.cc index 17d456eef..2fbf1c618 100644 --- a/src/bin/libint/iface.cc +++ b/src/bin/libint/iface.cc @@ -116,8 +116,8 @@ Libint2Iface::Libint2Iface( const unsigned int nbf = cparams_->num_bf(tlabel); ostringstream oss; - oss << "void (*" << ctext->label_to_name(cparams->api_prefix()) - << "libint2_build_" << tlabel; + oss << "void (*" + << ctext->label_to_function_name("libint2_build_" + tlabel); for (unsigned int c = 0; c < nbf; ++c) { const unsigned int lmax = const_cast(cparams_.get()) @@ -135,15 +135,12 @@ Libint2Iface::Libint2Iface( // Declare library constructor/destructor oss_.str(null_str_); oss_ << ctext_->type_name() << " " - << ctext_->label_to_name(cparams->api_prefix() + "libint2_static_init") - << "()"; + << ctext_->label_to_function_name("libint2_static_init") << "()"; std::string si_fdec(oss_.str()); oss_.str(null_str_); oss_ << ctext_->type_name() << " " - << ctext_->label_to_name(cparams->api_prefix() + - "libint2_static_cleanup") - << "()"; + << ctext_->label_to_function_name("libint2_static_cleanup") << "()"; std::string sc_fdec(oss_.str()); ih_ << si_fdec << ctext_->end_of_stat() << endl; @@ -156,26 +153,23 @@ Libint2Iface::Libint2Iface( oss_.str(null_str_); oss_ << ctext_->type_name() << " " - << ctext_->label_to_name(cparams->api_prefix() + "libint2_init_" + - tlabel) - << "(" << ctext_->inteval_type_name(tlabel) + << ctext_->label_to_function_name("libint2_init_" + tlabel) << "(" + << ctext_->inteval_type_name(tlabel) << "* inteval, int max_am, void* buf)"; std::string li_fdec(oss_.str()); li_decls_.push_back(li_fdec); oss_.str(null_str_); oss_ << ctext_->type_name() << " " - << ctext_->label_to_name(cparams->api_prefix() + - "libint2_need_memory_" + tlabel) + << ctext_->label_to_function_name("libint2_need_memory_" + tlabel) << "(int max_am)"; std::string lm_fdec(oss_.str()); lm_decls_.push_back(lm_fdec); oss_.str(null_str_); oss_ << ctext_->type_name() << " " - << ctext_->label_to_name(cparams->api_prefix() + "libint2_cleanup_" + - tlabel) - << "(" << ctext_->inteval_type_name(tlabel) << "* inteval)"; + << ctext_->label_to_function_name("libint2_cleanup_" + tlabel) << "(" + << ctext_->inteval_type_name(tlabel) << "* inteval)"; std::string lc_fdec(oss_.str()); lc_decls_.push_back(lc_fdec); @@ -189,8 +183,7 @@ Libint2Iface::Libint2Iface( oss_.str(null_str_); oss_ << "#ifdef __cplusplus\n#ifdef LIBINT2_FLOP_COUNT\nextern \"C++\" " "template void " - << ctext_->label_to_name(cparams->api_prefix() + - "libint2_init_flopcounter") + << ctext_->label_to_function_name("libint2_init_flopcounter") << "(EvalType* inteval_vector, int inteval_vector_size)" << ctext_->open_block(); // TODO convert to ForLoop object @@ -352,8 +345,7 @@ Libint2Iface::~Libint2Iface() { << "else " << std::endl; { std::string tmp = - ctext_->label_to_name(cparams_->api_prefix() + - "libint2_need_memory_" + tlabel) + + ctext_->label_to_function_name("libint2_need_memory_" + tlabel) + "(max_am)"; // no posix_memalign? use new, with default alignment diff --git a/src/bin/libint/rr.cc b/src/bin/libint/rr.cc index f10b6d0e3..32bbb9df9 100644 --- a/src/bin/libint/rr.cc +++ b/src/bin/libint/rr.cc @@ -340,8 +340,7 @@ std::string RecurrenceRelation::spfunction_call( const std::shared_ptr& context, const std::shared_ptr& dims) const { ostringstream os; - os << context->label_to_name( - label_to_funcname(context->cparams()->api_prefix() + label())) + os << context->label_to_function_name(label()) // First argument is the library object << "(inteval, " // Second is the target