Lecture 2 â Threads - many-core.group
Lecture 2 â Threads - many-core.group
Lecture 2 â Threads - many-core.group
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
GPU strategy 2 – kernel (part 2)<br />
// only compute if (a) thread is within the whole domain<br />
if (i > 0 && i < ni-1 && j > 0 && j < nj-1) {<br />
// and (b) thread is not on boundary of a block<br />
if ((threadIdx.x > 0) && (threadIdx.x < NI_TILE-1) &&<br />
(threadIdx.y > 0) && (threadIdx.y < NJ_TILE-1)) {<br />
//evaluate derivatives<br />
d2tdx2 = (temp[ti+1][tj] - 2*temp[ti][tj] + temp[ti-1][tj]);<br />
d2tdy2 = (temp[ti][tj+1] - 2*temp[ti][tj] + temp[ti][tj-1]);<br />
// update temperature<br />
temp_out[i2d] = temp_in[i2d] + tfac*(d2tdx2 + d2tdy2);<br />
}<br />
}