Keywords for commit messages
This section provides a list of keywords to include in commits comments. These keywords help organize and identify different types of contributions for better readability and maintainability.
Keywords List
<strong>1. <tt>doc:</tt>
- **Purpose: For documentation-related comments or detailed explanations.
- Example:
<strong>2. <tt>feat:</tt>
- **Purpose: To mark features or specific functionalities.
- Example:
<strong>3. <tt>fix:</tt>
- **Purpose: To identify bug fixes or adjustments.
- Example:
<strong>4. <tt>refactor:</tt>
- **Purpose: For restructuring code without changing its functionality.
- Example:
<strong>5. <tt>test:</tt>
- **Purpose: For comments related to tests or test cases.
- Example:
<strong>6. <tt>perf:</tt>
- **Purpose: To highlight performance improvements or optimizations.
- Example:
<strong>7. <tt>todo:</tt>
- **Purpose: To indicate pending tasks or features.
- Example:
<strong>8. <tt>hack:</tt>
- **Purpose: To identify temporary or workaround solutions.
- Example:
<strong>9. <tt>warn:</tt>
- **Purpose: For warnings about potential issues or limitations.
- Example:
<strong>10. <tt>debug:</tt>
- **Purpose: For debugging or test-specific comments.
- Example:
<strong>11. <tt>chore:</tt>
- **Purpose: For minor maintenance or cleaning tasks.
- Example:
<strong>12. <tt>deprecated:</tt>
- **Purpose: To mark features or methods that are no longer in use.
- Example:
Best Practices
- Consistency:
- Always use these keywords in lowercase to maintain clarity.
- Combination:
- Combine keywords if necessary to clarify intent. For example:
Parallelization Guidelines
Parallelization Guidelines in MPM-Geomechanics
This project uses OpenMP to accelerate selected functions through multi-threaded parallelization.
To maintain clarity and avoid unnecessary code duplication, we adopt the following convention:
Use macro-controlled dual versions <strong>only when needed</strong>
Separate sequential and parallel versions (using #if defined(...)) should be used only when the function requires thread-local storage such as:
- Mass or force accumulation into nodal values
- Boolean flags (e.g. node activation)
- Temporary vectors shared across threads
Examples:
nodalMass
nodalMomentum
nodalInternalForce
Use a single-version pattern with conditional pragma otherwise
If the function does not require thread-local storage, and the parallel and sequential logic is the same, then use this structure:
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int i = 0; i < N; ++i) {
}
Use of <tt>static_cast<int></tt> in <tt>for</tt> loops
In several parts of the simulator, loops iterate over particle or node containers whose size is returned as size_t. Since OpenMP requires a signed integer loop counter, we must convert size_t to int.
To ensure clarity and safety, always use static_cast<int> instead of the C-style (int) cast.
Rationale:
static_cast<int> is the C++ standard and makes the conversion intention explicit.
- It prevents unsafe or ambiguous conversions allowed by the C-style cast.
- It improves code readability and consistency across the project.
Example (correct usage):
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int i = 0; i < static_cast<int>(particles->size()); ++i) {
if (!particles->at(i)->getActive()) continue;
}
Normalization of OpenMP pragmas
All parallel loops must be guarded with #ifdef _OPENMP to ensure clean compilation with or without OpenMP support. Always use the same style:
#ifdef _OPENMP
#pragma omp parallel for schedule(static)
#endif
for (int i = 0; i < static_cast<int>(particles->size()); ++i) {
}
Atomic operations: always take the reference first
When using #pragma omp atomic, always assign the target variable to a reference before the atomic operation:
double& m = nodeI->getMassRef();
#ifdef _OPENMP
#pragma omp atomic update
#endif
m += nodalMass;