
5.8. FURTHER CACHE/VIRTUAL MEMORY ISSUES 145
ful of such issues when we write shared-memory code. And remember, the
problem is especially acute in multicore settings, due to cache coherency
issues (Section 2.5.1.1).
To make this idea concrete, we’ll look at two OpenMP programs to do
in-place matrix transpose. Here’s the first:
// CacheRow . c
#include <omp. h>
#include <s t d l i b . h>
#include <s t d i o . h>
// t r a n s l a t e from 2−D to 1−D i n d i c e s
int onedim ( int n , int i , int j ) { return n ∗ i + j ; }
void t r a n sp ( int ∗m, int n)
{
#pragma omp p a r a l l e l
{ int i , j , tmp ;
// walk through a l l the above−dia g on a l elements ,