|
5 | 5 | <div class="item">Allocates an 1-D <code>char</code> array of (n*840)*(2*n*840)*3 elements. This array is used to
|
6 | 6 | store an
|
7 | 7 | image with height (in pixels) of n*840, width (in pixels) of 2*n*840, where each pixel is encoded using 3 bytes (RBG
|
8 |
| - values). |
| 8 | + values). By passing different values of n we can scale the resolution of the image, with n=1 being the |
| 9 | + smallest resolution (840 x 1680). |
9 | 10 | </div>
|
10 | 11 | <div class="item">Fills this array with pixel values corresponding to the Julia set.</div>
|
11 | 12 | </div>
|
12 | 13 |
|
13 | 14 | <p class="ui">
|
14 | 15 | To make the above easier you are provided with one helper C function, <code>compute_julia_pixel()</code>, to which
|
15 | 16 | you pass the (x,y) coordinates of a pixed, the (width, height) dimensions of the image, a "tint" float (pass 1.0
|
16 |
| - for now), and a pointer to 3 contiguous bytes. These bytes are set to appropriate RGB values (Red Green Blue) for |
17 |
| - displaying the Julia set. |
| 17 | + for now), and a pointer to 3 contiguous bytes (<code>unsigned char</code>). These bytes are set to appropriate |
| 18 | + RGB values (Red Green Blue) for displaying the Julia set. |
18 | 19 | <a target="_blank" href="{{site.baseurl}}topic_basics_of_distributed_memory_programming/compute_julia_pixel.c">[Download
|
19 |
| - source of compute_julia_pixel()]</a> |
| 20 | + source of compute_julia_pixel()]</a> |
20 | 21 | </p>
|
21 | 22 |
|
22 |
| -<div class="ui accordion styled fluid"> |
| 23 | +<div class="ui accordion fluid"> |
23 | 24 | <div class=" title">
|
24 | 25 | <i class="dropdown icon"></i>
|
25 |
| - See the source of compute_julia_pixel() |
| 26 | + See the source of compute_julia_pixel()... |
26 | 27 | </div>
|
27 | 28 | <div class=" content">
|
28 |
| - <div class="ui container "> |
| 29 | + <div class="ui raised container segment "> |
29 | 30 |
|
30 |
| - {% highlight Java %} |
31 |
| - {% include_relative topic_basics_of_distributed_memory_programming/compute_julia_pixel.c %} |
32 |
| - {% endhighlight %} |
| 31 | + {% highlight Java %} |
| 32 | + {% include_relative topic_basics_of_distributed_memory_programming/compute_julia_pixel.c %} |
| 33 | + {% endhighlight %} |
33 | 34 | </div>
|
34 | 35 | </div>
|
35 | 36 | </div>
|
36 | 37 |
|
| 38 | +<br> |
| 39 | + |
| 40 | +<p class="ui"> |
| 41 | + The program must store the pixels of the 2-D image into a <b>1-D array using a <i>row-major scheme</i></b>. |
| 42 | +</p> |
| 43 | + |
| 44 | + |
| 45 | +<div class="ui accordion fluid"> |
| 46 | + <div class=" title"> |
| 47 | + <i class="dropdown icon"></i> |
| 48 | + See more details about this "row-major" business... |
| 49 | + </div> |
| 50 | + |
| 51 | + <div class="content"> |
| 52 | + <div class="ui container raised segment"> |
| 53 | + <h4 class="ui header">Storing 2-D data is a row-major 1-D array</h4> |
| 54 | + <p class="ui"> |
| 55 | + You may find the use of a 1-D array to store the pixels surprising, since after all the image is 2-D. However, it is |
| 56 | + common to use 1-D arrays, especially when they are dynamically allocated. One option would be to allocate an array |
| 57 | + of pointers to |
| 58 | + 1-D arrays, making it possible to access elements with the convenient syntax <code>Array[i][j]</code>. |
| 59 | + But this is typically a bad idea as it reduces locality (i.e., the efficient use of the cache), which in turns harms |
| 60 | + performance. |
| 61 | + </p> |
| 62 | + <p>Therefore, we instead store 2-D data into a 1-D array of contiguous elements. The "row-major" scheme consists in storing rows in sequence. In other |
| 63 | + terms, if the width of the image is <code>N</code>, then pixel (i,j) is stored as <code>Array[i * N + j]</code>. This is actually |
| 64 | + the scheme used by the C language to store 2-D arrays. |
| 65 | + </p> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | +</div> |
| 69 | +<br> |
| 70 | + |
| 71 | + |
| 72 | +Now that the program computes the Julia set pixels as a 1-D array of 3-byte elements, it would be nice to see them (if only to check |
| 73 | +that they're set correctly). So move on to Step #2 (next tab)... |
| 74 | + |
| 75 | + |
| 76 | + |
0 commit comments