110 lines
4.4 KiB
Markdown
110 lines
4.4 KiB
Markdown
# Step 18: Deterministic Sparse Assembly
|
|
|
|
## 담당 역할과 필수 스킬
|
|
|
|
- 담당 역할: `implementation-agent`
|
|
- 필수 스킬: `fesa-cpp-msvc-tdd`
|
|
- 모든 C++ build/test와 최종 VERIFY는 MSVC x64 Debug 기준으로 수행한다.
|
|
|
|
## 읽어야 할 파일
|
|
|
|
- `/AGENTS.md`
|
|
- `/docs/ARCHITECTURE.md`
|
|
- `/docs/ADR.md`
|
|
- `/docs/linear-static-3d-euler-beam/requirements.md`
|
|
- `/docs/linear-static-3d-euler-beam/implementation-plan.md`
|
|
- `/include/fesa/math/vector.hpp`
|
|
- `/include/fesa/math/matrix.hpp`
|
|
- `/include/fesa/fem/dof_manager.hpp`
|
|
- `/include/fesa/elements/euler_beam_3d.hpp`
|
|
- `/include/fesa/assembly/parallel_for.hpp`
|
|
- `/src/fesa/assembly/parallel_for.cpp`
|
|
|
|
## 소유 파일
|
|
|
|
- Create: `/include/fesa/math/sparse_matrix.hpp`
|
|
- Create: `/src/fesa/math/sparse_matrix.cpp`
|
|
- Create: `/include/fesa/assembly/sparse_assembler.hpp`
|
|
- Create: `/src/fesa/assembly/sparse_assembler.cpp`
|
|
- Create: `/tests/unit/math/sparse_matrix_test.cpp`
|
|
- Create: `/tests/unit/assembly/sparse_assembler_test.cpp`
|
|
- Modify: `/src/fesa/CMakeLists.txt`
|
|
- Modify: `/tests/CMakeLists.txt`
|
|
|
|
## 작업
|
|
|
|
element-local stiffness contributions를 deterministic하게 COO로 수집하고 0-based CSR로
|
|
finalize하는 별도 sparse module을 구현하라.
|
|
|
|
```cpp
|
|
struct CooContribution {
|
|
std::size_t row;
|
|
std::size_t column;
|
|
double value;
|
|
std::size_t elementOrder;
|
|
std::size_t localOrder;
|
|
};
|
|
class SparseMatrix {
|
|
public:
|
|
static Result<SparseMatrix> fromCoo(std::size_t rows, std::size_t columns,
|
|
std::vector<CooContribution> contributions,
|
|
const SparsePattern& expectedPattern);
|
|
std::size_t rows() const noexcept;
|
|
std::size_t columns() const noexcept;
|
|
const std::vector<std::size_t>& rowOffsets() const noexcept;
|
|
const std::vector<std::size_t>& columnIndices() const noexcept;
|
|
const std::vector<double>& values() const noexcept;
|
|
Vector multiply(const Vector& rhs) const;
|
|
Status validate() const;
|
|
};
|
|
```
|
|
|
|
`SparseMatrix`는 `Matrix`를 상속하지 않는다. COO는 `(row,column,elementOrder,localOrder)`로
|
|
stable sort한 후 duplicate를 고정 순서로 합산한다. Zero value 보존/제거 policy는
|
|
implementation plan과 I/O-independent math contract에 맞춰 하나로 고정하고 test한다.
|
|
Row offsets/column indices는 0-based, columns sorted unique, sizes/ranges consistent해야 한다.
|
|
Element stiffness 계산은 ParallelFor로 index-addressed buffer에 넣고 global reduction은
|
|
element internal index 순서로 수행한다.
|
|
|
|
Tests는 known matrix CSR/matrix-vector product, duplicate sum, invalid index/pattern, empty row, symmetry,
|
|
serial-vs-TBB byte-identical row/column/value vectors, repeated runs를 포함하고
|
|
`SparseAssembly` regex로 등록한다.
|
|
|
|
## Acceptance Criteria
|
|
|
|
```powershell
|
|
cmake --build .harness/build --config Debug --target fesa_tests
|
|
ctest --test-dir .harness/build -C Debug -R SparseAssembly --output-on-failure
|
|
```
|
|
|
|
RED 후 GREEN/VERIFY:
|
|
|
|
```powershell
|
|
cmake -S . -B .harness/build -A x64 `
|
|
-DFESA_GTEST_SOURCE_DIR=C:/git/googletest `
|
|
"-DMKL_DIR=C:/Program Files (x86)/Intel/oneAPI/mkl/2026.1/lib/cmake/mkl" `
|
|
"-DTBB_DIR=C:/Program Files (x86)/Intel/oneAPI/tbb/2023.1/lib/cmake/tbb" `
|
|
"-DHDF5_DIR=C:/Program Files/HDF_Group/HDF5/2.1.1/cmake"
|
|
cmake --build .harness/build --config Debug
|
|
ctest --test-dir .harness/build -C Debug -R SparseAssembly --output-on-failure
|
|
ctest --test-dir .harness/build -C Debug --show-only=json-v1
|
|
ctest --test-dir .harness/build -C Debug --output-on-failure
|
|
```
|
|
|
|
## 검증 절차
|
|
|
|
1. CSR invariant/determinism tests를 먼저 작성하고 RED를 확인한다.
|
|
2. ordered COO reduction과 CSR ownership의 최소 구현으로 GREEN을 만든다.
|
|
3. repeated serial/TBB equivalence와 전체 VERIFY를 수행한다.
|
|
4. `/docs/linear-static-3d-euler-beam/implementation-report.md`의
|
|
Step 18 section에 실제 RED/GREEN/VERIFY command, exit code,
|
|
핵심 output과 변경 파일을 기록한다.
|
|
5. Step 18을 `completed`로 갱신하고 CSR/determinism evidence를 summary에 기록한다.
|
|
|
|
## 금지사항
|
|
|
|
- `SparseMatrix`를 dense `Matrix`에서 상속하지 마라. 이유: storage/backend 의미가 다르다.
|
|
- TBB worker가 shared CSR value에 직접 쓰게 하지 마라. 이유: race와 nondeterminism이 생긴다.
|
|
- PARDISO-specific descriptor/index type을 public sparse API에 넣지 마라. 이유: Step 20 adapter 책임이다.
|
|
- 직접 commit하지 마라. 이유: Harness executor가 담당한다.
|