Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Improve sparse utils #107

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open

WIP: Improve sparse utils #107

wants to merge 34 commits into from

Conversation

ahojukka5
Copy link
Member

See issue #96. This is "Work in Progress", not to be merged yet.

That is, we have at the end Ax=b, taking sparse matrices in
standard format and giving back x = [u, la] vector.
- rewrite how update!solver) works using only SparseVector
- this clearly reduces memory allocation and makes code more clear, a lot of magic disappeared
- there is still some problem when constructing LinearSystem

 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 solve!(solver)                                               1    217ms  89.6%   217ms   96.1MiB  50.0%  96.1MiB
   empty field assemblies before solution                     1    132ms  54.4%   132ms      128B  0.00%     128B
   combine assemblies                                         1   82.1ms  33.9%  82.1ms   96.0MiB  49.9%  96.0MiB
   solve linear system                                        1   2.90ms  1.19%  2.90ms   37.5KiB  0.02%  37.5KiB
     solve boundary system using LU factorization             1   1.67ms  0.69%  1.67ms   6.27KiB  0.00%  6.27KiB
     solve interior domain using LDLt factorization           1    896μs  0.37%   896μs   8.81KiB  0.00%  8.81KiB
     solve Lagrange multipliers using LU factorization        1   43.1μs  0.02%  43.1μs   10.4KiB  0.01%  10.4KiB
   construct LinearSystem                                     1    123μs  0.05%   123μs   9.86KiB  0.01%  9.86KiB
   make stffiness matrix symmetric                            1   38.5μs  0.02%  38.5μs   6.78KiB  0.00%  6.78KiB
   update solution vectors                                    1   1.21μs  0.00%  1.21μs      352B  0.00%     352B
 assemble!(solver)                                            1   24.6ms  10.1%  24.6ms   96.2MiB  50.0%  96.2MiB
 update!(solver)                                              1    521μs  0.21%   521μs   37.4KiB  0.02%  37.4KiB
 initialize!(solver)                                          1   23.7μs  0.01%  23.7μs   3.13KiB  0.00%  3.13KiB
 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────

versus

 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                         Time                   Allocations
                                                                 ──────────────────────   ───────────────────────
                        Tot / % measured:                             16.7s / 100%            21.0GiB / 100%

 Section                                                 ncalls     time   %tot     avg     alloc   %tot      avg
 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 solve!(solver)                                               1    16.7s  99.8%   16.7s   21.0GiB  99.6%  21.0GiB
   construct LinearSystem                                     1    11.2s  67.2%   11.2s   14.9GiB  70.8%  14.9GiB
   make stffiness matrix symmetric                            1    3.81s  22.8%   3.81s   4.47GiB  21.2%  4.47GiB
   solve linear system                                        1    1.34s  8.04%   1.34s   1.49GiB  7.08%  1.49GiB
     solve boundary system using LU factorization             1   1.25ms  0.01%  1.25ms   6.27KiB  0.00%  6.27KiB
     solve interior domain using LDLt factorization           1    688μs  0.00%   688μs   8.39KiB  0.00%  8.39KiB
     solve Lagrange multipliers using LU factorization        1   75.2μs  0.00%  75.2μs   9.99KiB  0.00%  9.99KiB
   empty field assemblies before solution                     1    209ms  1.25%   209ms      128B  0.00%     128B
   combine assemblies                                         1   78.7ms  0.47%  78.7ms   96.0MiB  0.45%  96.0MiB
   update solution vectors                                    1   1.40μs  0.00%  1.40μs      352B  0.00%     352B
 assemble!(solver)                                            1   27.4ms  0.16%  27.4ms   96.2MiB  0.45%  96.2MiB
 update!(solver)                                              1    721μs  0.00%   721μs   39.9KiB  0.00%  39.9KiB
 initialize!(solver)                                          1   25.6μs  0.00%  25.6μs   3.13KiB  0.00%  3.13KiB
 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────
- If / when changing function calling, let's put old ones to deprecated.jl so that code won't break too much.
- Fixed elastiticy tests, we do not use `u` and `la` in assemblies anymore.
To prevent test break again:

- removed code aster mesh file reading (test only one thing at time)
- define function get_solution_vector to return solution from solver
- Removed unnecessary stuff (test only one thing at time)
- block.assembly.u -> solver.u, or better, reshape(get_solution_vector(solver), solver.ndim, solver.nnodes)
- fixed way how solution is read from solver.
```
23-Apr 17:15:05:INFO:root:Assembled 2 problems in 0.05 seconds. ndofs = 4634485491540951040.
23-Apr 17:15:05:INFO:root:Assembly times:
23-Apr 17:15:05:INFO:root:1 BLOCK 0.02
23-Apr 17:15:05:INFO:root:2 symmetry bc 0.02
23-Apr 17:15:05:INFO:root:Solving problems ...
test 2d nonlinear elasticity with surface load: Error During Test
  Got an exception of type OutOfMemoryError outside of a @test
```

- But it's not showing in my local installation with same julia version.
- Removed obsolete code from `assemble!(solver::Solver; with_mass_matrix=false)`.
- Now also timings of assembly is done using TimerOutputs.
- block.assembly.u -> get_solution_vector(solver)
To prevent tests to break again, now we have a function `get_nodal_values` what can be used to query single nodal value from element, we use this from now on and do not read from solution vector directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant