This commit is contained in:
Simon Gardling 2021-03-26 20:45:22 +00:00
parent a479181882
commit 7f285dbdec
3 changed files with 25 additions and 15 deletions

View File

@ -12,6 +12,7 @@ itertools = "0.10"
rand = "0.8.3" rand = "0.8.3"
rand_distr = "0.4" rand_distr = "0.4"
rayon = "1.5" rayon = "1.5"
fastapprox = "0.3.0"
arrayfire = {git = "https://github.com/arrayfire/arrayfire-rust.git"} arrayfire = {git = "https://github.com/arrayfire/arrayfire-rust.git"}
#arrayfire = "3.8.0" #arrayfire = "3.8.0"

View File

@ -5,10 +5,13 @@ use rand::Rng;
use arrayfire as af; use arrayfire as af;
fn main() { fn main() {
backend_man(); let gpu_compute: bool = false;
// af::set_backend(af::Backend::CPU); if gpu_compute {
af::set_device(0); backend_man();
af::info(); // af::set_backend(af::Backend::CPU);
af::set_device(0);
af::info();
}
// let n_iterations = 16384; // let n_iterations = 16384;
let n_iterations = 2024; let n_iterations = 2024;
@ -39,11 +42,17 @@ fn main() {
let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity); let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity);
model.print_configurations(); model.print_configurations();
// let dims = af::Dim4::new(&[n_particles as u64, 1, 1, 1]); if gpu_compute {
for i in 0..n_iterations { let dims = af::Dim4::new(&[n_particles as u64, 1, 1, 1]);
model.step(); for i in 0..n_iterations {
// model.step_cl(dims); model.step_cl(dims);
pb.set_position(i); pb.set_position(i);
}
} else {
for i in 0..n_iterations {
model.step();
pb.set_position(i);
}
} }
pb.finish(); pb.finish();

View File

@ -188,16 +188,16 @@ impl Model {
} = grid.config; } = grid.config;
let (width, height) = (grid.width, grid.height); let (width, height) = (grid.width, grid.height);
let xc = agent.x + agent.angle.cos() * sensor_distance; let xc = agent.x + fastapprox::faster::cos(agent.angle) * sensor_distance;
let yc = agent.y + agent.angle.sin() * sensor_distance; let yc = agent.y + fastapprox::faster::sin(agent.angle) * sensor_distance;
let agent_add_sens = agent.angle + sensor_angle; let agent_add_sens = agent.angle + sensor_angle;
let agent_sub_sens = agent.angle - sensor_angle; let agent_sub_sens = agent.angle - sensor_angle;
let xl = agent.x + agent_sub_sens.cos() * sensor_distance; let xl = agent.x + fastapprox::faster::cos(agent_sub_sens) * sensor_distance;
let yl = agent.y + agent_sub_sens.sin() * sensor_distance; let yl = agent.y + fastapprox::faster::sin(agent_sub_sens) * sensor_distance;
let xr = agent.x + agent_add_sens.cos() * sensor_distance; let xr = agent.x + fastapprox::faster::cos(agent_add_sens) * sensor_distance;
let yr = agent.y + agent_add_sens.sin() * sensor_distance; let yr = agent.y + fastapprox::faster::sin(agent_add_sens) * sensor_distance;
// Sense. We sense from the buffer because this is where we previously combined data // Sense. We sense from the buffer because this is where we previously combined data
// from all the grid. // from all the grid.