mirror of
https://github.com/Noratrieb/mandelbrot-rust.git
synced 2026-01-16 08:15:03 +01:00
sequence
This commit is contained in:
parent
00b9cf8669
commit
1fc0e2561c
10 changed files with 50 additions and 72 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1 +1,4 @@
|
||||||
/target
|
/target
|
||||||
|
seq
|
||||||
|
*.iml
|
||||||
|
.idea
|
||||||
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
|
|
@ -1,8 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/../../../../../../:\Users\nilsh\CLionProjects\mandelbrot_set\.idea/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
6
.idea/discord.xml
generated
6
.idea/discord.xml
generated
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="PROJECT_FILES" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
11
.idea/mandelbrot_set.iml
generated
11
.idea/mandelbrot_set.iml
generated
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="CPP_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
9
.idea/markdown.xml
generated
9
.idea/markdown.xml
generated
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="MarkdownSettings">
|
|
||||||
<enabledExtensions>
|
|
||||||
<entry key="MermaidLanguageExtension" value="false" />
|
|
||||||
<entry key="PlantUMLLanguageExtension" value="false" />
|
|
||||||
</enabledExtensions>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
8
.idea/modules.xml
generated
8
.idea/modules.xml
generated
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/mandelbrot_set.iml" filepath="$PROJECT_DIR$/.idea/mandelbrot_set.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
BIN
gpu.gif
Normal file
BIN
gpu.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 812 KiB |
BIN
gpu.png
BIN
gpu.png
Binary file not shown.
|
Before Width: | Height: | Size: 5.9 MiB After Width: | Height: | Size: 830 KiB |
71
src/lib.rs
71
src/lib.rs
|
|
@ -13,26 +13,55 @@ use image::{ImageBuffer, ImageResult, Rgb, RgbImage};
|
||||||
static PTX: &str = include_str!("../target/gpu.ptx");
|
static PTX: &str = include_str!("../target/gpu.ptx");
|
||||||
|
|
||||||
pub fn run(_: Config) -> Result<(), Box<dyn Error>> {
|
pub fn run(_: Config) -> Result<(), Box<dyn Error>> {
|
||||||
let center = CNumber::new(-0.77568377, 0.13646737);
|
let start_time = SystemTime::now();
|
||||||
|
|
||||||
let c_w = 4;
|
|
||||||
let c_h = 2;
|
|
||||||
|
|
||||||
let cfg = Cfg {
|
|
||||||
start: CNumber::new(-3.0, 1.),
|
|
||||||
end: CNumber::new(1., -1.),
|
|
||||||
height: 500 * 20,
|
|
||||||
width: 1000 * 10,
|
|
||||||
iterations: 30000,
|
|
||||||
threshold: 100,
|
|
||||||
};
|
|
||||||
|
|
||||||
let amount = cfg.height as usize * cfg.width as usize;
|
|
||||||
|
|
||||||
println!("{} points will be calculated", amount);
|
|
||||||
|
|
||||||
let _ctx = cust::quick_init()?;
|
let _ctx = cust::quick_init()?;
|
||||||
|
|
||||||
|
let center = CNumber::new(-0.77568377, 0.13646737);
|
||||||
|
|
||||||
|
let max_zoom = 1_000_000.;
|
||||||
|
let zoom_speed = 1.1;
|
||||||
|
|
||||||
|
let mut zoom = 1.;
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
while zoom < max_zoom {
|
||||||
|
let start = CNumber::new(center.real - 2. / zoom, center.imag + 1. / zoom);
|
||||||
|
let end = CNumber::new(center.real + 2. / zoom, center.imag - 1. / zoom);
|
||||||
|
|
||||||
|
let height = 1000;
|
||||||
|
|
||||||
|
let cfg = Cfg {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
height,
|
||||||
|
width: height * 2,
|
||||||
|
iterations: 50000,
|
||||||
|
threshold: 100,
|
||||||
|
};
|
||||||
|
|
||||||
|
let start_inner_time = SystemTime::now();
|
||||||
|
run_single_image(cfg, &format!("seq/gpu_{}.png", i))?;
|
||||||
|
println!(
|
||||||
|
"Iteration '{}' in time: {} with zoom {:.2}/{:.2}",
|
||||||
|
i,
|
||||||
|
format_time(start_inner_time.elapsed()?),
|
||||||
|
zoom,
|
||||||
|
max_zoom
|
||||||
|
);
|
||||||
|
|
||||||
|
i += 1;
|
||||||
|
zoom *= zoom_speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Total time: {}", format_time(start_time.elapsed()?));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_single_image(cfg: Cfg, filename: &str) -> Result<(), Box<dyn Error>> {
|
||||||
|
let amount = cfg.height as usize * cfg.width as usize;
|
||||||
|
|
||||||
let module = Module::from_str(PTX)?;
|
let module = Module::from_str(PTX)?;
|
||||||
let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?;
|
let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?;
|
||||||
|
|
||||||
|
|
@ -44,7 +73,6 @@ pub fn run(_: Config) -> Result<(), Box<dyn Error>> {
|
||||||
let threads = Vec2::new(32, 32);
|
let threads = Vec2::new(32, 32);
|
||||||
let blocks = (Vec2::new(cfg.width, cfg.height) / threads) + 1;
|
let blocks = (Vec2::new(cfg.width, cfg.height) / threads) + 1;
|
||||||
|
|
||||||
let start_time = SystemTime::now();
|
|
||||||
unsafe {
|
unsafe {
|
||||||
launch!(
|
launch!(
|
||||||
func<<<blocks, threads, 0, stream>>>(
|
func<<<blocks, threads, 0, stream>>>(
|
||||||
|
|
@ -65,12 +93,7 @@ pub fn run(_: Config) -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
out_buf.copy_to(&mut out)?;
|
out_buf.copy_to(&mut out)?;
|
||||||
|
|
||||||
println!("expected {}, got {} numbers!", amount, out.len());
|
create_image(&out, cfg, filename)?;
|
||||||
|
|
||||||
println!("calculated in: {}", format_time(start_time.elapsed()?));
|
|
||||||
|
|
||||||
create_image(&out, cfg, "gpu.png")?;
|
|
||||||
println!("Total Time: {}", format_time(start_time.elapsed()?));
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue