03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

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.

182 CHAPTER 5. META-PROGRAMMING<br />

};<br />

}<br />

C(i + Index0, k + Max1)= tmp.value;<br />

next().update(tmp.sub, C, i, k);<br />

template <br />

struct mult block<br />

{<br />

template <br />

void operator()(Tmp& tmp, const Matrix& A, const Matrix& B, unsigned i, unsigned j, unsigned k)<br />

{<br />

std::cout ≪ ”tmp.” ≪ tmp.bs ≪ ”+= A[” ≪ i + Max0 ≪ ”][” ≪ j ≪ ”] ∗ B[” ≪ j ≪ ”][” ≪<br />

k + Max1 ≪ ”]\n”;<br />

tmp.value+= A(i + Max0, j) ∗ B(j, k + Max1);<br />

}<br />

};<br />

template <br />

void update(const Tmp& tmp, Matrix& C, unsigned i, unsigned k)<br />

{<br />

std::cout ≪ ”C[” ≪ i + Max0 ≪ ”][” ≪ k + Max1 ≪ ”]= tmp.” ≪ tmp.bs ≪ ”\n”;<br />

C(i + Max0, k + Max1)= tmp.value;<br />

}<br />

In order to verify that all operations are per<strong>for</strong>med, we log them completely but look here only<br />

at tmp.4 and tmp.3:<br />

tmp.4+= A[1][0] * B[0][0]<br />

tmp.3+= A[1][0] * B[0][1]<br />

tmp.4+= A[1][1] * B[1][0]<br />

tmp.3+= A[1][1] * B[1][1]<br />

tmp.4+= A[1][2] * B[2][0]<br />

tmp.3+= A[1][2] * B[2][1]<br />

tmp.4+= A[1][3] * B[3][0]<br />

tmp.3+= A[1][3] * B[3][1]<br />

C[1][0]= tmp.4<br />

C[1][1]= tmp.3<br />

tmp.4+= A[3][0] * B[0][0]<br />

tmp.3+= A[3][0] * B[0][1]<br />

tmp.4+= A[3][1] * B[1][0]<br />

tmp.3+= A[3][1] * B[1][1]<br />

tmp.4+= A[3][2] * B[2][0]<br />

tmp.3+= A[3][2] * B[2][1]<br />

tmp.4+= A[3][3] * B[3][0]<br />

tmp.3+= A[3][3] * B[3][1]<br />

C[3][0]= tmp.4<br />

C[3][1]= tmp.3

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

Saved successfully!

Ooh no, something went wrong!