Page MenuHomec4science

algorithm.c
No OneTemporary

File Metadata

Created
Mon, Jun 3, 20:06

algorithm.c

/*
============================================================================
Filename : algorithm.c
Author : Your names go here
SCIPER : Your SCIPER numbers
============================================================================
*/
#include <math.h>
#define INPUT(I,J) input[(I)*length+(J)]
#define OUTPUT(I,J) output[(I)*length+(J)]
#define CACHE_SIZE 8
#define COORD(I,J,K) (I) = K / length; (J) = (K) - (I) * length;
void simulate(double *input, double *output, int threads, int length, int iterations)
{
double *temp;
omp_set_num_threads(threads);
int i;
int j;
const int matsize = length*length;
double horiz_block[3];
for(int n=0; n < iterations; n++)
{
printf("Loop: %d\n", n);
#pragma omp parallel for private(i,j, horiz_block)
for(int k=1; k<matsize; k++) // loop j first
{
COORD(i,j,k)
if ((i == 0) || (i == length-1) || (j == 0) || (j == length-1) ||
(((i == length/2-1) || (i== length/2))
&& ((j == length/2-1) || (j == length/2))) ) {
continue;
}
// write on one chache miss, read on three
horiz_block[0] = INPUT(i-1,j-1) + INPUT(i-1,j) + INPUT(i-1,j+1);
horiz_block[1] = INPUT(i,j-1) + INPUT(i,j) + INPUT(i,j+1);
horiz_block[2] = INPUT(i+1,j-1) + INPUT(i+1,j) + INPUT(i+1,j+1);
// write on one chache miss
OUTPUT(i,j) = (horiz_block[0] + horiz_block[1] + horiz_block[2]) / 9;
// Original line
/*
OUTPUT(i,j) = (INPUT(i-1,j-1) + INPUT(i-1,j) + INPUT(i-1,j+1) +
INPUT(i,j-1) + INPUT(i,j) + INPUT(i,j+1) +
INPUT(i+1,j-1) + INPUT(i+1,j) + INPUT(i+1,j+1) )/9; */
}
temp = input;
input = output;
output = temp;
}
}

Event Timeline