Skip to content

Commit acf9b4d

Browse files
committed
Tweaks
1 parent e509185 commit acf9b4d

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

topic_basics_of_distributed_memory_programming/sequential_step1.html

+50-10
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,72 @@
55
<div class="item">Allocates an 1-D <code>char</code> array of (n*840)*(2*n*840)*3 elements. This array is used to
66
store an
77
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).
910
</div>
1011
<div class="item">Fills this array with pixel values corresponding to the Julia set.</div>
1112
</div>
1213

1314
<p class="ui">
1415
To make the above easier you are provided with one helper C function, <code>compute_julia_pixel()</code>, to which
1516
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.
1819
<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>
2021
</p>
2122

22-
<div class="ui accordion styled fluid">
23+
<div class="ui accordion fluid">
2324
<div class=" title">
2425
<i class="dropdown icon"></i>
25-
See the source of compute_julia_pixel()
26+
See the source of compute_julia_pixel()...
2627
</div>
2728
<div class=" content">
28-
<div class="ui container ">
29+
<div class="ui raised container segment ">
2930

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 %}
3334
</div>
3435
</div>
3536
</div>
3637

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

Comments
 (0)