28.11.2014 Views

Lecture 2 – Threads - many-core.group

Lecture 2 – Threads - many-core.group

Lecture 2 – Threads - many-core.group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

GPU strategy 1 – kernel<br />

// find i and j indices of this thread<br />

ti = threadIdx.x;<br />

tj = threadIdx.y;<br />

i = blockIdx.x*(NI_TILE) + ti;<br />

j = blockIdx.y*(NJ_TILE) + tj;<br />

// find indices into linear memory <br />

i00 = I2D(ni, i, j);<br />

im10 = I2D(ni, i-1, j); ...<br />

// check that compute is required for this thread<br />

if (i > 0 && i < ni-1 && j > 0 && j < nj-1) {<br />

// evaluate derivatives <br />

d2tdx2 = temp_in[im10] - 2*temp_in[i00] + temp_in[ip10];<br />

d2tdy2 = temp_in[i0m1] - 2*temp_in[i00] + temp_in[i0p1];<br />

// update temperature<br />

temp_out[i00] = temp_in[i00] + tfac*(d2tdx2 + d2tdy2);<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!