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

change V-cycle tolerance criterion #97

Merged
merged 10 commits into from
Jan 31, 2024

Conversation

marinlauber
Copy link
Member

@marinlauber marinlauber commented Jan 9, 2024

Solve the pressure oscillation from #96

The fix is to implement a variable depth V-cycle. The criterion to pop! or push! a new level to the multigrid depends on the previous number of v-cycles necessary to reach convergence.

The convergence is measured with a L_\infty norm.

This also implements a basic logging capability to track the convergence of the multigrid solver (to be improved)

TO DO:

  • Find the best value for the new tolerance criterion
  • Check dependence on Float64/Float32
  • Run the benchmark on CPU/GPU
  • Clean logging of MultiGrid
  • Better test for MultiGrid solver?

@weymouth
Copy link
Collaborator

weymouth commented Jan 9, 2024

Do we really need to do a V-cycle every time? If there is nothing going on, shouldn't it skip the loop like in the master?

src/MultiLevelPoisson.jl Outdated Show resolved Hide resolved
src/MultiLevelPoisson.jl Outdated Show resolved Hide resolved
@marinlauber

This comment was marked as outdated.

@b-fg b-fg linked an issue Jan 10, 2024 that may be closed by this pull request
@marinlauber

This comment was marked as outdated.

@marinlauber
Copy link
Member Author

I still need to benchmark and correct the tests before it's finalized.

@b-fg
Copy link
Member

b-fg commented Jan 23, 2024

How's this? You still need to include the latest changes @marinlauber ?

@marinlauber
Copy link
Member Author

Yes, this is not up to date, the latest change from master needs to be included, as well as the latest (my local change) change to the pressure solver. I will try and do this this afternoon.

src/MultiLevelPoisson.jl Outdated Show resolved Hide resolved
@marinlauber
Copy link
Member Author

I have just removed the debug flags. I will correct the test and run the TGV on GPU for benchmark.

@b-fg
Copy link
Member

b-fg commented Jan 31, 2024

Can you please post here the benchmark results? Just to document it in this issue too.

@b-fg
Copy link
Member

b-fg commented Jan 31, 2024

Also tests are not passing, please have a look at that too :)

@marinlauber
Copy link
Member Author

Results of running ./benchmark.sh

Benchmark environment: jelly sim_step! (max_steps=100)
▶ log2p = 5
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   5dea927 │ 1.10.0 │   Float32 │     2262206 │   0.15 │     8.82 │     1.00 │
│   CPUx6 │   5dea927 │ 1.10.0 │   Float32 │     8314557 │   1.16 │     2.23 │     3.95 │
│     GPU │   5dea927 │ 1.10.0 │   Float32 │     4204607 │   1.23 │     0.79 │    11.10 │
│   CPUx1 │   f73b0f8 │ 1.10.0 │   Float32 │     2701319 │   0.17 │     9.66 │     0.91 │
│   CPUx6 │   f73b0f8 │ 1.10.0 │   Float32 │     9932893 │   1.27 │     2.62 │     3.36 │
│     GPU │   f73b0f8 │ 1.10.0 │   Float32 │     5081400 │   1.34 │     0.94 │     9.36 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘
▶ log2p = 6
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   5dea927 │ 1.10.0 │   Float32 │     3193860 │   0.19 │    44.65 │     1.00 │
│   CPUx6 │   5dea927 │ 1.10.0 │   Float32 │    11733545 │   1.08 │    11.57 │     3.86 │
│     GPU │   5dea927 │ 1.10.0 │   Float32 │     5957765 │   0.71 │     2.02 │    22.06 │
│   CPUx1 │   f73b0f8 │ 1.10.0 │   Float32 │     4208427 │   0.22 │    48.49 │     0.92 │
│   CPUx6 │   f73b0f8 │ 1.10.0 │   Float32 │    15447345 │   1.18 │    13.85 │     3.23 │
│     GPU │   f73b0f8 │ 1.10.0 │   Float32 │     7946898 │   0.80 │     2.55 │    17.51 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘

Benchmark environment: tgv sim_step! (max_steps=100)
▶ log2p = 6
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   5dea927 │ 1.10.0 │   Float32 │     1271364 │   0.17 │     8.11 │     1.00 │
│   CPUx6 │   5dea927 │ 1.10.0 │   Float32 │     4677263 │   0.93 │     2.05 │     3.95 │
│     GPU │   5dea927 │ 1.10.0 │   Float32 │     2304513 │   1.67 │     0.50 │    16.25 │
│   CPUx1 │   f73b0f8 │ 1.10.0 │   Float32 │     1357166 │   0.19 │     8.27 │     0.98 │
│   CPUx6 │   f73b0f8 │ 1.10.0 │   Float32 │     4999132 │   1.12 │     2.11 │     3.85 │
│     GPU │   f73b0f8 │ 1.10.0 │   Float32 │     2469674 │   1.42 │     0.55 │    14.74 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘
▶ log2p = 7
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   5dea927 │ 1.10.0 │   Float32 │     1146285 │   0.09 │    49.56 │     1.00 │
│   CPUx6 │   5dea927 │ 1.10.0 │   Float32 │     4007692 │   0.63 │    12.00 │     4.13 │
│     GPU │   5dea927 │ 1.10.0 │   Float32 │     1915606 │   0.31 │     1.26 │    39.48 │
│   CPUx1 │   f73b0f8 │ 1.10.0 │   Float32 │     1326286 │   0.15 │    51.17 │     0.97 │
│   CPUx6 │   f73b0f8 │ 1.10.0 │   Float32 │     4688832 │   1.02 │    12.39 │     4.00 │
│     GPU │   f73b0f8 │ 1.10.0 │   Float32 │     2264255 │   0.61 │     1.36 │    36.51 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘

@marinlauber
Copy link
Member Author

I fixed the tests. It should be fine now.

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5dea927) 96.44% compared to head (577b12e) 96.45%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #97   +/-   ##
=======================================
  Coverage   96.44%   96.45%           
=======================================
  Files          12       12           
  Lines         450      451    +1     
=======================================
+ Hits          434      435    +1     
  Misses         16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@weymouth weymouth merged commit 8a0de76 into WaterLily-jl:master Jan 31, 2024
8 checks passed
@weymouth
Copy link
Collaborator

Speed-up, passing tests, and closes a issue. Merging!

@weymouth weymouth mentioned this pull request Mar 29, 2024
p = ml.levels[1]
BC!(p.x;perdir=p.perdir)
residual!(p); r₂ = L₂(p)
log && (res = [r₂])
residual!(p); r₀ = r₂ = L∞(p); r₂₀ = L₂(p)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marinlauber Why are there three computed residuals? It looks like only r₂ is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MultiLevelPoisson solver tolerance not independent of domain size
3 participants