Buddhabrot
Single Core and Multi Core (CPU and GPU) versions of Buddhabrot
Install / Use
/learn @Michaelangel007/BuddhabrotREADME
Buddhabrot
Optimized Buddhabrot HDR image generators:
- [x] Single threaded (CPU),
- [x] multi-threaded OpenMP (CPU),
- [ ] multi-threaded C++14 (CPU) {forthcoming}
- [ ] multi-core using CUDA (GPU) {forthcoming},
- [ ] and multi-core using OpenCL {forthcoming},
Full image
This 4,500 x 6000 (27 Mega pixels!) at 524,288 depth image took 1 day, 18 hours on a MacBook Pro (i7 @ 2.8 GHz) utilizing all 8 cores.
Here is a thumbnail image at 30% size (1350x1800):
<img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/1350x1800/thumbnail_7F9CFF_buddhabrot_1350x1800_512Kd.png">Note: If low resolution images have a "blocky" look that is due to under-sampling the image -- the max depth is not deep enough.
Depth thumbnails
The maximum depth effects how many finer details are visible. Here are some depth comparisons:
<br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@256.png" > Depth 256 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@512.png" > Depth 512 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@1K.png" > Depth 1,024 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@2K.png" > Depth 2,048 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@4K.png" > Depth 4,096 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@8K.png" > Depth 8,192 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@16K.png" > Depth 16,384 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@32K.png" > Depth 32,768 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@64K.png" > Depth 65,536 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@128K.png"> Depth 131,072 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@256K.png"> Depth 262,144 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@512K.png"> Depth 524,288 <br><img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/400x300/400x300@1M.png" > Depth 1,048,576
NOTE: These are HDR (High Dynamic Range) 16-bit single channel images (monochrome) converted into a SR (Standard Range) 8-bit / channel "false color" image.
HDR
Can I view/edit the raw HDR images in Photoshop or GIMP?
Yes for Photoshop, partially for GIMP.
Photoshop HDR
For example using the file omp4_buddhabrot_6000x4500_d524288_s10_j8.u16.data:
- Copy the file and rename the extension from
.datato.raw - File Open, and specify:
- Header: 0 (default)
- Channels: 1
- Width: 6000
- Height: 4500
- Depth: 16 Bits
- Byte Order: IBM PC (Little Endian)
- Image, Image Rotation, 90° CW
- Image, Mode, RGB Color
- Image, Adjustments, HDR Toning...
- Method: Local Adaptation
- Radius: 1
- Strength: 0.1
- Tone and Detail
- Gamma: 1 (or 2 for a little brighter)
- Exposure: -1 (or 0 for a little brighter)
- Detail: 0%
- Advanced
- Shadow: 0% (or -100% for a little deeper black)
- Highlight: 0%
- Tone Curve and Histogram
- Input: 11%
- Output: 0%
- Corner: Yes
The HDR image has a single channel. To produce a false color image you'll need to manually do layer blends.
i.e.
-
Layer, New, Layer
-
Name: Subtract Grey
-
Mode: Subtract
-
Background Color:
-
RGB: 7,7,7
-
Edit, Fill
-
Use: Background Color
-
Blending: Normal
-
Opacity: 100%
-
Layer, New, Layer
-
Name: Colorize
-
Mode: Overlay
-
Foreground Color
-
RGB: #0080FF (Or for a slightly brighter blue #7F9CFF)
-
Edit, Fill
-
Use: Foreground Color
-
Blending: Normal
-
Opacity: 100%
You'll want to save and then export to an 8-bit !
1350x1800 Thumbnail <br> <img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/1350x1800/thumbnail_0080FF_buddhabrot_1350x1800_512Kd.png">
Alternatively, you could also use 32 bits/channel preview
- Image, Mode, 32 bits/channel
- View, 32-Bit Preview Options...
- Exposure: 7
- Gamma: 2
GIMP HDR
- File Open, File Type: RAW, and specify:
- Offset: 0 (default)
- Width
- Height
- Image Type: RGB565
- Palette: n/a
Unfortunately GIMP 2.8 is gimped -- it doesn't have proper 16-bit/channel support so you won't be able to view the monochrome HDR image, only a false 15-bit image.
<img src="https://raw.githubusercontent.com/Michaelangel007/buddhabrot/master/pics/gimp_import_data_1.png">Status
- [x] Single threaded (CPU)
- [x] Multi-threaded OpenMP
- [x]
-j#Use a maximum number of threads - [x]
--no-bmpDon't save BMP image - [x]
--no-rawDon't save raw image - [x]
--no-rotDon't rotate BMP - [x]
-bmp foo.bmpSave BMP with specified filename - [x]
-raw bar.rawsave RAW with specified filename
TODO
- [ ]
-hSave partial histogram images - [ ] Exposure settings via:
raw2bmp -bias # -min # - max # - [ ] MSVC solution and project -- not yet started
- [ ] Multi-threaded C++14 -- not yet started
- [ ] Multi-core CUDA -- not yet started
- [ ] Multi-core OpenCL -- not yet started
| Type | Linux | OSX | Windows | Filename |
|-----------------|----------|----------|---------|------------------|
| Single threaded | Done | Done | TODO | bin/buddhabrot |
| OpenMP | Done | Done | TODO | bin/omp2 |
| C++14 | TODO | TODO | TODO | bin/c14 |
| CUDA | TODO | TODO | TODO | bin/cuda |
| OpenCL | TODO | TODO | TODO | bin/ocl |
Compiling
You will need a compiler that supports OpenMP. (And eventually C++14, CUDA, and OpenCL.)
Windows
On Windows a MSVC (Microsoft Visual C++) solution and project are provided in build/. Currently a MSVC 2010 Express solution is available under build/Buddhabrot_MSVC2010Express.sln
If you try to use MSVC 2010 Express edition to build the OpenMP code note that the Express edition can generate OpenMP code BUT the required header and library files are not present out-of-the-box! They will be provided soon as a convenience.
Note: If you wish to use various OpenMP's directives #pragma omp with Microsoft's compiler, they in typical fashion, only support OpenMP 2.0 (and no later versions.)
OSX
To build type: make The makefile will detect the OS and use the right flags. Note that the CUDA versions are NOT built by default, you must use make cuda
For OpenMP support under OSX, Apple switched from the default compiler from gcc (which does) to llvm (which does not.) Here are the details and instructions on how to install gcc and get OpenMP support:
* OpenMP On OSX (10.8, 10.9)
There are 2 initial problems compiling with OpenMP under OSX.
a) The default C/C++ compiler is llvm not gcc; llvm does not (yet) support OpenMP.
The solution is to install and use gcc.
Install gcc 4.7 (or greater) from MacPorts
https://www.macports.org/install.php
sudo port install gcc47
sudo port select gcc mp-gcc477
usr/local/bin/g++ --version
b) Compiling with gcc you may get this error message:
Undefined symbols for architecture x86_64:
"_gomp_thread_attr", referenced from:
_initialize_env in libgomp.a(env.o)
ld: symbol(s) not found for architecture x86_64
There are 2 solutions:
1) Install gcc 4.7 (or greater) from MacPorts as documented above
or
2) Add the global thread symbol for gomp (Gnu OpenMP)
#include <pthread.h> // required on OSX 10.8
pthread_attr_t gomp_thread_attr;
To find out where OpenMP's header is:
sudo find / -name omp.h
Default on XCode 4.6 + Command Line Tools
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin10/4.2.1/include/omp.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include/omp.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin11/4.2.1/include/omp.h
/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include/omp.h
If you have installed gcc:
/user/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include/omp.h
/user/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/include/omp.h
Linux
See the OSX instructions for make
Running
To run the single threaded version bin/buddhabrot
To run the multi-threaded version bin/omp4
One can specify a custom resolution. If you change specify the width and height it is highly recommended you keep the aspect ratio of 4:3. e.g. bin/omp3 4000 3000
The raw data will be 4,000 x 3,000. The generated BMP will be rotated 90 degrees so the Buddhabrot appears in the "standard form" at 3,000 x 4,000.
Benchmarks
Using the default 1,024 x 768 at 1,000 depth we can see how much faster parallelizing the code can be:
| Hardware | org. | cpu1 | omp1 | omp2 | omp3 | cuda | ocl | |--------------------|------|------|------|------|------|------|-----| | Intel i7 @ 2.6 GHz | 0:57 | 0:55 | 0:22 |
