Skip to content

Commit a843746

Browse files
committed
Merge branch 'develop' into libxc_openmp
2 parents ec0e7c0 + e98b1e4 commit a843746

136 files changed

Lines changed: 3181 additions & 3581 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
cd ..
6666
6767
- name: Upload Coverage to Codecov
68-
uses: codecov/codecov-action@v5
68+
uses: codecov/codecov-action@v6
6969
if: ${{ ! cancelled() }}
7070
with:
7171
fail_ci_if_error: true

.github/workflows/doxygen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
shell: bash
4646

4747
- name: Setup Pages
48-
uses: actions/configure-pages@v5
48+
uses: actions/configure-pages@v6
4949

5050
- name: Upload artifact
5151
uses: actions/upload-pages-artifact@v4
@@ -54,5 +54,5 @@ jobs:
5454

5555
- name: Deploy to GitHub Pages
5656
id: deployment
57-
uses: actions/deploy-pages@v4
57+
uses: actions/deploy-pages@v5
5858

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ abacus.json
2626
toolchain/install/
2727
toolchain/abacus_env.sh
2828
.trae
29+
compile_commands.json

CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ if(ENABLE_RAPIDJSON)
6969
include(FetchContent)
7070
FetchContent_Declare(
7171
rapidjson
72-
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
73-
GIT_TAG "origin/master"
74-
GIT_SHALLOW TRUE
75-
GIT_PROGRESS TRUE)
72+
URL https://codeload.github.com/Tencent/rapidjson/tar.gz/24b5e7a8b27f42fa16b96fc70aade9106cf7102f
73+
)
7674
set(RAPIDJSON_BUILD_TESTS
7775
OFF
7876
CACHE INTERNAL "")
@@ -322,7 +320,7 @@ if(DEBUG_INFO)
322320
endif()
323321

324322
if(ENABLE_MPI)
325-
find_package(MPI REQUIRED)
323+
find_package(MPI COMPONENTS CXX REQUIRED)
326324
include_directories(${MPI_CXX_INCLUDE_PATH})
327325
target_link_libraries(${ABACUS_BIN_NAME} MPI::MPI_CXX)
328326
add_compile_definitions(__MPI)
@@ -438,6 +436,11 @@ if(USE_CUDA)
438436
target_link_libraries(${ABACUS_BIN_NAME} cudart nvToolsExt)
439437
endif ()
440438
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
439+
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 13.0)
440+
if(EXISTS "${CUDAToolkit_ROOT}/include/cccl")
441+
include_directories("${CUDAToolkit_ROOT}/include/cccl")
442+
endif()
443+
endif()
441444
if(USE_CUDA)
442445
add_compile_definitions(__CUDA)
443446
add_compile_definitions(__UT_USE_CUDA)

cmake/FindCereal.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if(NOT CEREAL_INCLUDE_DIR)
1515
include(FetchContent)
1616
FetchContent_Declare(
1717
cereal
18-
URL https://codeload.github.com/MCresearch/cereal/tar.gz/master
18+
URL https://codeload.github.com/USCiLab/cereal/tar.gz/22a1b369f39be918ca79206a83c4facd759f9105
1919
)
2020
FetchContent_Populate(cereal)
2121
set(CEREAL_INCLUDE_DIR ${cereal_SOURCE_DIR}/include)

cmake/FindLibComm.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if(NOT LIBCOMM_DIR)
1616
include(FetchContent)
1717
FetchContent_Declare(
1818
LibComm
19-
URL https://github.com/abacusmodeling/LibComm/archive/refs/tags/v0.1.1.tar.gz
19+
URL https://codeload.github.com/abacusmodeling/LibComm/tar.gz/965bf90713ce5598bae4fd957d417065f77ceb42
2020
)
2121
FetchContent_Populate(LibComm)
2222
set(LIBCOMM_DIR ${libcomm_SOURCE_DIR})

cmake/FindLibRI.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if(NOT LIBRI_DIR)
1616
include(FetchContent)
1717
FetchContent_Declare(
1818
LibRI
19-
URL https://codeload.github.com/abacusmodeling/LibRI//tar.gz/v0.2.1.1
19+
URL https://codeload.github.com/abacusmodeling/LibRI/tar.gz/e6d78e0504693d2a464c72b87d3240ce183fd881
2020
)
2121
FetchContent_Populate(LibRI)
2222
set(LIBRI_DIR ${libri_SOURCE_DIR})

cmake/FindMKL.cmake

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,54 @@ if(NOT TARGET MKL::MKL)
99

1010
find_path(MKL_INCLUDE mkl_service.h HINTS ${MKLROOT}/include)
1111

12-
find_library(MKL_INTEL NAMES mkl_intel_lp64 HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
13-
find_library(MKL_INTEL_THREAD NAMES mkl_intel_thread HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
1412
find_library(MKL_CORE NAMES mkl_core HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
15-
find_library(MKL_IOMP5 NAMES iomp5
16-
HINTS ENV CMPLR_ROOT
17-
PATH_SUFFIXES lib lib/intel64 linux/compiler/lib/intel64_lin
18-
)
13+
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
14+
find_library(MKL_INTERFACE_LIB NAMES mkl_intel_lp64 HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
15+
find_library(MKL_THREAD NAMES mkl_intel_thread HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
16+
find_library(MKL_IOMP5 NAMES iomp5
17+
HINTS ENV CMPLR_ROOT
18+
PATH_SUFFIXES lib lib/intel64 linux/compiler/lib/intel64_lin
19+
)
20+
else()
21+
find_library(MKL_INTERFACE_LIB NAMES mkl_gf_lp64 HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
22+
find_library(MKL_THREAD NAMES mkl_gnu_thread HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
23+
# With GCC we use system-installed GNU OpenMP
24+
endif()
25+
1926
if(ENABLE_MPI)
27+
execute_process(COMMAND ${MPI_CXX_COMPILER} --showme:version
28+
OUTPUT_VARIABLE MPI_VER_OUT
29+
ERROR_VARIABLE MPI_VER_ERR)
30+
if(MPI_VER_OUT MATCHES "Open MPI" OR MPI_VER_ERR MATCHES "Open MPI")
31+
set(MKL_BLACS_LIB_NAME "mkl_blacs_openmpi_lp64")
32+
else()
33+
set(MKL_BLACS_LIB_NAME "mkl_blacs_intelmpi_lp64")
34+
endif()
2035
find_library(MKL_SCALAPACK NAMES mkl_scalapack_lp64 HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
21-
find_library(MKL_BLACS_INTELMPI NAMES mkl_blacs_intelmpi_lp64 HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
36+
find_library(MKL_BLACS NAMES ${MKL_BLACS_LIB_NAME} HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
2237
endif()
2338

2439
include(FindPackageHandleStandardArgs)
2540
# handle the QUIETLY and REQUIRED arguments and set MKL_FOUND to TRUE
2641
# if all listed variables are TRUE
2742

2843
if(ENABLE_MPI)
29-
find_package_handle_standard_args(MKL DEFAULT_MSG MKL_INTEL MKL_INTEL_THREAD MKL_CORE MKL_SCALAPACK MKL_BLACS_INTELMPI MKL_INCLUDE)
44+
find_package_handle_standard_args(MKL DEFAULT_MSG MKL_INTERFACE_LIB MKL_THREAD MKL_CORE MKL_SCALAPACK MKL_BLACS MKL_INCLUDE)
3045
else()
31-
find_package_handle_standard_args(MKL MKL_INTEL MKL_INTEL_THREAD MKL_CORE MKL_INCLUDE)
46+
find_package_handle_standard_args(MKL MKL_INTERFACE_LIB MKL_THREAD MKL_CORE MKL_INCLUDE)
3247
endif()
3348

3449
if(MKL_FOUND)
35-
if(NOT TARGET MKL::INTEL)
36-
add_library(MKL::INTEL UNKNOWN IMPORTED)
37-
set_target_properties(MKL::INTEL PROPERTIES
38-
IMPORTED_LOCATION "${MKL_INTEL}"
50+
if(NOT TARGET MKL::INTERFACE_LIB)
51+
add_library(MKL::INTERFACE_LIB UNKNOWN IMPORTED)
52+
set_target_properties(MKL::INTERFACE_LIB PROPERTIES
53+
IMPORTED_LOCATION "${MKL_INTERFACE_LIB}"
3954
INTERFACE_INCLUDE_DIRECTORIES "${MKL_INCLUDE}")
4055
endif()
41-
if(NOT TARGET MKL::INTEL_THREAD)
42-
add_library(MKL::INTEL_THREAD UNKNOWN IMPORTED)
43-
set_target_properties(MKL::INTEL_THREAD PROPERTIES
44-
IMPORTED_LOCATION "${MKL_INTEL_THREAD}"
56+
if(NOT TARGET MKL::THREAD)
57+
add_library(MKL::THREAD UNKNOWN IMPORTED)
58+
set_target_properties(MKL::THREAD PROPERTIES
59+
IMPORTED_LOCATION "${MKL_THREAD}"
4560
INTERFACE_INCLUDE_DIRECTORIES "${MKL_INCLUDE}")
4661
endif()
4762
if(NOT TARGET MKL::CORE)
@@ -56,10 +71,10 @@ if(MKL_FOUND)
5671
IMPORTED_LOCATION "${MKL_SCALAPACK}"
5772
INTERFACE_INCLUDE_DIRECTORIES "${MKL_INCLUDE}")
5873
endif()
59-
if(NOT TARGET MKL::BLACS_INTELMPI)
60-
add_library(MKL::BLACS_INTELMPI UNKNOWN IMPORTED)
61-
set_target_properties(MKL::BLACS_INTELMPI PROPERTIES
62-
IMPORTED_LOCATION "${MKL_BLACS_INTELMPI}"
74+
if(ENABLE_MPI AND NOT TARGET MKL::BLACS)
75+
add_library(MKL::BLACS UNKNOWN IMPORTED)
76+
set_target_properties(MKL::BLACS PROPERTIES
77+
IMPORTED_LOCATION "${MKL_BLACS}"
6378
INTERFACE_INCLUDE_DIRECTORIES "${MKL_INCLUDE}")
6479
endif()
6580
if(MKL_IOMP5 AND NOT TARGET MKL::IOMP5)
@@ -72,14 +87,14 @@ if(MKL_FOUND)
7287
set_property(TARGET MKL::MKL PROPERTY
7388
INTERFACE_LINK_LIBRARIES
7489
"-Wl,--start-group"
75-
MKL::INTEL MKL::INTEL_THREAD MKL::CORE MKL::MKL_SCALAPACK MKL::BLACS_INTELMPI
90+
MKL::INTERFACE_LIB MKL::THREAD MKL::CORE MKL::MKL_SCALAPACK MKL::BLACS
7691
"-Wl,--end-group"
7792
)
7893
else()
7994
set_property(TARGET MKL::MKL PROPERTY
8095
INTERFACE_LINK_LIBRARIES
8196
"-Wl,--start-group"
82-
MKL::INTEL MKL::INTEL_THREAD MKL::CORE
97+
MKL::INTERFACE_LIB MKL::THREAD MKL::CORE
8398
"-Wl,--end-group"
8499
)
85100
endif()
@@ -90,9 +105,9 @@ if(MKL_FOUND)
90105
endif()
91106

92107
if(ENABLE_MPI)
93-
mark_as_advanced(MKL_INCLUDE MKL_INTEL MKL_INTEL_THREAD MKL_CORE MKL_SCALAPACK MKL_BLACS_INTELMPI)
108+
mark_as_advanced(MKL_INCLUDE MKL_INTERFACE_LIB MKL_THREAD MKL_CORE MKL_SCALAPACK MKL_BLACS)
94109
else()
95-
mark_as_advanced(MKL_INCLUDE MKL_INTEL MKL_INTEL_THREAD MKL_CORE)
110+
mark_as_advanced(MKL_INCLUDE MKL_INTERFACE_LIB MKL_THREAD MKL_CORE)
96111
endif()
97112

98113
endif() # MKL::MKL

docs/advanced/input_files/input-main.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [min\_dist\_coef](#min_dist_coef)
2929
- [device](#device)
3030
- [precision](#precision)
31+
- [gint\_precision](#gint_precision)
3132
- [timer\_enable\_nvtx](#timer_enable_nvtx)
3233
- [cell\_factor](#cell_factor)
3334
- [dm\_to\_rho](#dm_to_rho)
@@ -759,6 +760,16 @@
759760
- double: double precision
760761
- **Default**: double
761762

763+
### gint_precision
764+
765+
- **Type**: String
766+
- **Availability**: *Used only for LCAO basis set on CPU.*
767+
- **Description**: Specifies the precision when performing grid integral in LCAO calculations.
768+
- single: single precision
769+
- double: double precision
770+
- mix: mixed precision, starting from single precision and switching to double precision when the SCF residual becomes small enough
771+
- **Default**: double
772+
762773
### timer_enable_nvtx
763774

764775
- **Type**: Boolean
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Basic Tool Classes Design Guide for ABACUS
2+
3+
## Overview
4+
5+
This document provides guidelines for designing and implementing basic tool classes in the ABACUS codebase, focusing on best practices for memory management, code style, and testing. These guidelines apply to all basic mathematical and utility classes, including but not limited to:
6+
7+
- vector3.h
8+
- matrix.h
9+
- timer.h
10+
- ndarray.h
11+
- realarray.h
12+
- complexarray.h
13+
- complexmatrix.h
14+
- matrix3.h
15+
- intarray.h
16+
- formatter.h
17+
- math_chebyshev.h
18+
19+
While this guide uses `IntArray` as an example for illustration purposes, the principles and practices described here are applicable to all basic tool classes in ABACUS.
20+
21+
## Memory Management
22+
23+
### 1. Exception Handling for Memory Allocation
24+
25+
Always use try-catch blocks when allocating memory to handle `std::bad_alloc` exceptions gracefully:
26+
27+
### 2. Two-Stage Memory Allocation
28+
29+
When reallocating memory (e.g., in `create` methods), use a two-stage approach to ensure that the original object remains valid if memory allocation fails.
30+
31+
### 3. Null Pointer Checks
32+
33+
Always check for null pointers before accessing memory, especially in methods that might be called on objects with failed memory allocation.
34+
35+
## Class Design
36+
37+
### 1. Copy Constructor
38+
39+
Implement a copy constructor to avoid shallow copy issues.
40+
41+
### 2. Move Semantics
42+
43+
Implement move constructor and move assignment operator to improve performance.
44+
45+
### 3. Boundary Checks
46+
47+
Add boundary checks to prevent out-of-bounds access.
48+
49+
## Code Style
50+
51+
### 1. Brace Style
52+
53+
Use separate lines for braces, and always use braces for "if" and "for" statements, even if they contain one line of code
54+
55+
### 2. Indentation
56+
57+
Use spaces instead of tabs for indentation (4 spaces per indent level).
58+
59+
### 3. Comments
60+
61+
Use English for comments and document important functionality. Follow Doxygen-style documentation for classes and methods.
62+
63+
## Code Quality
64+
65+
### 1. Named Constants
66+
67+
Avoid using magic numbers. Instead, define named constants for numerical values:
68+
69+
### 2. Header Includes
70+
71+
Ensure all necessary header files are included, especially for functions like `assert`:
72+
73+
```cpp
74+
#include <cassert>
75+
```
76+
77+
## Testing
78+
79+
### 1. Unit Tests
80+
81+
Write comprehensive unit tests for all classes, including:
82+
- Constructor tests
83+
- Method tests
84+
- Exception handling tests
85+
- Edge case tests
86+
87+
### 2. Test Class Initialization
88+
89+
Use constructor initialization lists for test classes to improve compatibility:
90+
91+
```cpp
92+
class IntArrayTest : public testing::Test
93+
{
94+
protected:
95+
ModuleBase::IntArray a2, a3, a4, a5, a6;
96+
int aa;
97+
int bb;
98+
int count0;
99+
int count1;
100+
const int zero;
101+
102+
IntArrayTest() : aa(11), bb(1), zero(0)
103+
{
104+
}
105+
};
106+
```
107+
108+
## Best Practices
109+
110+
1. **Single Responsibility Principle**: Each class should have a single, well-defined responsibility.
111+
2. **Encapsulation**: Hide implementation details and expose only necessary interfaces.
112+
3. **Error Handling**: Handle errors gracefully, especially memory allocation failures.
113+
4. **Performance**: Use move semantics and other performance optimizations where appropriate.
114+
5. **Testing**: Write comprehensive tests for all functionality.
115+
6. **Code Style**: Follow consistent code style guidelines, including:
116+
- Always use braces for if and for statements
117+
- Use separate lines for braces
118+
- Use spaces instead of tabs for indentation
119+
- Use English for comments
120+
7. **Code Quality**: Maintain high code quality by:
121+
- Using named constants instead of magic numbers
122+
- Ensuring all necessary header files are included
123+
- Adding boundary checks to prevent out-of-bounds access
124+
8. **Documentation**: Document classes and methods to improve maintainability.
125+
9. **Compatibility**: Ensure code is compatible with C++11 standard.
126+
10. **Portability**: Write code that works across different platforms.
127+
11. **Reusability**: Design classes to be reusable in different contexts.
128+
129+
## Application to Other Basic Tool Classes
130+
131+
While this guide uses `IntArray` as an example, these principles apply to all basic tool classes in ABACUS. For example:
132+
133+
- **vector3.h**: Apply the same memory management and error handling principles, with additional focus on vector operations and operator overloading.
134+
- **matrix.h**: Extend the memory management practices to 2D arrays, with additional considerations for matrix operations.
135+
- **timer.h**: Focus on static member management and time measurement accuracy.
136+
- **ndarray.h**: Apply the same principles to multi-dimensional arrays, with additional considerations for shape manipulation.
137+
- **formatter.h**: Focus on string manipulation and formatting, with attention to performance and usability.
138+
- **math_chebyshev.h**: Apply the principles to template classes, with additional focus on mathematical algorithm implementation.
139+
140+
By following these guidelines, you can ensure that all basic tool classes in ABACUS are well-designed, robust, and maintainable.

0 commit comments

Comments
 (0)