Skip to content

Commit 4284720

Browse files
authored
Merge branch 'develop' into dsp/sdft
2 parents 6287e57 + abf77eb commit 4284720

59 files changed

Lines changed: 1557 additions & 3283 deletions

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

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ if(DEBUG_INFO)
322322
endif()
323323

324324
if(ENABLE_MPI)
325-
find_package(MPI REQUIRED)
325+
find_package(MPI COMPONENTS CXX REQUIRED)
326326
include_directories(${MPI_CXX_INCLUDE_PATH})
327327
target_link_libraries(${ABACUS_BIN_NAME} MPI::MPI_CXX)
328328
add_compile_definitions(__MPI)
@@ -438,6 +438,11 @@ if(USE_CUDA)
438438
target_link_libraries(${ABACUS_BIN_NAME} cudart nvToolsExt)
439439
endif ()
440440
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
441+
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 13.0)
442+
if(EXISTS "${CUDAToolkit_ROOT}/include/cccl")
443+
include_directories("${CUDAToolkit_ROOT}/include/cccl")
444+
endif()
445+
endif()
441446
if(USE_CUDA)
442447
add_compile_definitions(__CUDA)
443448
add_compile_definitions(__UT_USE_CUDA)

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
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.

docs/developers_guide/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. _developers_guide:
2+
3+
Developers Guide
4+
================
5+
6+
This section provides guidelines and resources for developers working on the ABACUS codebase.
7+
8+
.. toctree::
9+
:maxdepth: 2
10+
:caption: Developer Resources
11+
12+
basic_types_class.md

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ the developments and applications of novel machine-learning-assisted DFT methods
5656
:caption: Developing Team
5757

5858
DevelopingTeam
59+
developers_guide/index
5960

6061
.. toctree::
6162
:maxdepth: 2

0 commit comments

Comments
 (0)