I've been following a lattice-boltzmann tutorial and decided to implement it in Rust (still kinda new to it) as the usual language I use, Javascript, is not very performant. I've successfully ported everything to Rust, but I'm confused at the structure of a processing-heavy program in Rust.
Namely, I have 9 large vectors with dimensions [x_cells * y_cells], and I perform several iterative functions on these vectors. Because of Rust's ownership model, I originally passed mutable references of these vectors to my several processing functions as arguments which worked fine. However, having 9 additional arguments in a function call didn't seem right, so I refactored my code to use structs.
I put the nine vectors into a struct called Lattice and put my processing functions into my impl Lattice. The code is a lot more organized, but for some reason, it runs much slower than passing mutable references everywhere.
I'm looking more for guidance than anything, and I'm wondering if there's a standard way of doing these kinds of simulations in a performant manner in Rust. Thanks!
If you're curious, here's the function-only version of my code: https://github.com/Kauhentus/rust-lattice-boltzmann/blob/main/main-functions.rs
And here's the struct version of my code: https://github.com/Kauhentus/rust-lattice-boltzmann/blob/main/main-struct.rs
Aucun commentaire:
Enregistrer un commentaire