MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_bm_cplx_openmp.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file mandelbrot_bm_cplx_openmp.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Benchmark drawing a mandelbrot set using the C++ complex type with OpenMP.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 DAMAGE.
28 @endparblock
29 @filedetails
30
31 Basic benchmark. Uses complex numbers. Uses OpenMP.
32*/
33/*******************************************************************************************************************************************************.H.E.**/
34/** @cond exj */
35
36//--------------------------------------------------------------------------------------------------------------------------------------------------------------
37#include "ramCanvas.hpp"
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40int main(void) {
41 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
42 mjr::ramCanvas3c8b::csIntType count;
43 const int NUMITR = 1024;
44 std::complex<double> c, z, zero(0.0, 0.0);
45 mjr::ramCanvas3c8b theRamCanvas(7680, 7680, -2.2, 0.8, -1.5, 1.5);
46
47#pragma omp parallel for private(c, z, count) schedule(static,1)
48 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
49 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
50 for(c=std::complex<mjr::ramCanvas3c8b::coordFltType>(theRamCanvas.int2realX(x),theRamCanvas.int2realY(y)),z=zero,count=0; (std::norm(z)<4)&&(count<=NUMITR); count++,z=z*z+c)
51 ;
52 if(count < NUMITR)
53 theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType::csCColdeFireRamp::c(static_cast<mjr::ramCanvas3c8b::csIntType>(mjr::math::ivl::wrapCC(count*20, 767))));
54 }
55 }
56 theRamCanvas.writeTIFFfile("mandelbrot_bm_cplx_openmp.tiff");
57 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
58 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
59}
60/** @endcond */
int main(int argc, char *argv[])