Strange result of example Mandelbrot

I downloaded 2 versions of Mandelbrot:
Mandelbron_master and Mandelbrot_bands.

On all my computers they give me strange results.
For example, on my Desktop (windows 10) , Generate 10000x8000 size png file
Mandelbron_master (release version) : 4.75s (real time)
Mandelbrot_bands. (release version): 6s (real time)
Mandelbrot_bands, modify to 1 thread, release version: 23s (real time)

The results surprised me! Ignore the 2 strange results (4.74s and 6s), how can the final version be so slow! 23s!
The simple version Mandelbron_master gives me the best result! Andbody tells me what happened?

Mandelbrot_bands. (release version): 6s (real time)
Mandelbrot_bands, modify to 1 thread, release version: 23s (real time)

It sounds like the earlier one was multi threaded while the other test is single threaded ?

1 Like

Yes the earlier one is 8 threads. The final one is signal thread.
But the first one Mandelbrot_master is also single thread (Didn't use thread lib). And it is the fastest.

  1. We can't verify this unless you show us the full crate sources for both, including the build instrs.

  2. It sounds like *_master and _bands are two DIFFERENT algorithms, so it is not unreasonable they have different runtime characteristics.

1 Like

I uploaded 3 different programs.
master_main.rs(Simple, Single Thread)
bands_8_thread_main.rs(8 Threads)
bands_1_thread_main.rs(1 Thread)

These programs are supposed to show how powerful multi-thread is....
But I got faild.
3 Diff mandelbrot

Its easier when you send the whole cargo project. I tried running your code but it complained about image::png not existing and image::ColorType::Gray not beeing a thing. If I had your Cargo.toml I wouldn't have that issue.

1 Like

Sorry. The cargo.toml file is:

[package]
name = "mandelbrot"
version = "0.2.0"
authors = ["Jim Blandy jimb@red-bean.com"]
edition = "2018"

[dependencies]
num = "0.4"
image = "0.13.0"
crossbeam = "0.8"

That can't be true. At least in master_main.rs you use rayon.

You are right.
Mandelbron_master Cargo.toml
[package]
name = "mandelbrot"
version = "0.2.0"
authors = ["Jim Blandy jimb@red-bean.com"]
edition = "2018"

[dependencies]
num = "0.4"
image = "0.13.0"
rayon = "1"

Mandelbrot_bands (1 or 8 thread) Cargo.toml
[package]
name = "mandelbrot"
version = "0.2.0"
authors = ["Jim Blandy jimb@red-bean.com"]
edition = "2018"

[dependencies]
num = "0.4"
image = "0.13.0"
crossbeam = "0.8"

1 Like

A little treat for people that kept reading till here

3 Likes

Yes... I generate 10000x8000 size pictures.
Mandelbrot_master is a baseline. something like 5 secs
Mandelbrot_bands_8_thread is multi-thread version, should be much faster. But it's 6 secs
Mandelbrot_bands_1_thread is single-thread version. Why it is so slow, 23secs!

Those aren't particularly surprising results. Mandelbrot_master uses rayon, which is a well optimised and standard crate for these sorts of CPU-bound parallel computations. Mandelbrot_bands_8_thread implements its own parallelism, but ends up being only a little slower than the rayon version. Mandelbrot_bands_1_thread only uses one thread, so it is not surprising that it takes longer than the multi-threaded versions (although it doesn't take 8 times as long, presumably due to the overhead of launching threads).

Edit to add: According to its FAQ rayon by default uses as many threads as there are CPU cores, so it is probably using the same number of threads as the Mandelbrot_bands_8_thread version, further explaining their similar times.

2 Likes

Sorry everyone. I should use Mandelbrot_singal_thread on Git Hub as a baseline. It's exactly the version of the book.
Mandelbrot_master is a multi-thread version using rayon.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.