Strumenti Utente

Strumenti Sito


magistraleinformaticanetworking:spd:2018:mandel

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Entrambe le parti precedenti la revisioneRevisione precedente
Prossima revisione
Revisione precedente
magistraleinformaticanetworking:spd:2018:mandel [18/04/2018 alle 11:41 (7 anni fa)] Massimo Coppolamagistraleinformaticanetworking:spd:2018:mandel [18/04/2018 alle 15:03 (7 anni fa)] (versione attuale) Massimo Coppola
Linea 1: Linea 1:
 ==== Example code for mandelbrot ==== ==== Example code for mandelbrot ====
 +
 +C/C++ skeleton code for Mandelbrot computation. 
  
 <code> <code>
Linea 7: Linea 9:
 #include "tbb/parallel_for.h" #include "tbb/parallel_for.h"
 #include "tbb/blocked_range.h" #include "tbb/blocked_range.h"
 +// or use blocked_range2d if appropriate
  
 using namespace tbb; using namespace tbb;
 using namespace std; using namespace std;
  
-// costanti di default+// default constants
  
-//square area, lower left angle and size+// square area, lower left angle and size
 #define DEFAULT_X -2.0 #define DEFAULT_X -2.0
 #define DEFAULT_Y -2.0 #define DEFAULT_Y -2.0
Linea 20: Linea 23:
 #define DEFAULT_ITERATIONS 1000 #define DEFAULT_ITERATIONS 1000
  
-// we assume a point diverges if quared modulus exceeds this value+// we assume a point diverges if its squared modulus exceeds this value
 #define MAX_SMODULUS = 4 #define MAX_SMODULUS = 4
  
 +// a variable holding the number of iterations limit
 static int maxIter = DEFAULT_ITERATIONS; static int maxIter = DEFAULT_ITERATIONS;
  
  
-//funzione per calcolo mandelbrot in un punto+//function computing the mandelbrot in asingle point
 //returns the number of iteration until divergence //returns the number of iteration until divergence
 int mand_compute( double cx, double cy) int mand_compute( double cx, double cy)
 { {
-    int i;+ int i=0;
     double x = cx; double y = cy;     double x = cx; double y = cy;
     double nx, ny;     double nx, ny;
Linea 36: Linea 40:
     {     {
        // (x,y)^2 + c        // (x,y)^2 + c
-       nx = x*x - y*y; +       nx = x*x - y*y + cx
-       ny = 2*x*y+       ny = 2*x*y + cy;
        if ( nx*nx + ny*ny > MAX_SMODULUS ) break;        if ( nx*nx + ny*ny > MAX_SMODULUS ) break;
 +       x=nx; y=ny;
     }     }
     return i;     return i;
 } }
  
-// class to hold the computation+// define class to hold the computation
  
  
Linea 49: Linea 54:
 int main () { int main () {
  
-// inizializza iterazioni+// initialization
  
-// inizializza zona+// inizialize data if needed
  
-//crea parallel range+// parallel for 
 +// with blocked_range
  
-//parallel for 
  
 } }
Linea 62: Linea 67:
 ==== Example code for saving an array as PPM graphics ==== ==== Example code for saving an array as PPM graphics ====
  
-Compile this file together with you code and be sure to insert the function prototye in the main source file+Compile and link this file together with you code.  
 +Remember to insert the function prototye in the main source file
  
 <code> <code>
magistraleinformaticanetworking/spd/2018/mandel.1524051714.txt.gz · Ultima modifica: 18/04/2018 alle 11:41 (7 anni fa) da Massimo Coppola

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki