Page MenuHomec4science

algorithm_2_tile.c
No OneTemporary

File Metadata

Created
Fri, Nov 1, 03:06

algorithm_2_tile.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);
for(int n=0; n < iterations; n++)
{
#pragma omp parallel for collapse(2)
for(int i=1; i<length-1; i+=2)
{
for(int j=1; j<length-1; j+=2)
{
if((i+1<length-1)&&(j+1<length-1))
{
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;
OUTPUT(i+1,j) = (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) + INPUT(i+2,j-1) + INPUT(i+2,j) + INPUT(i+2,j+1))/9;
OUTPUT(i,j+1) = (INPUT(i-1,j) + INPUT(i-1,j+1) + INPUT(i-1,j+2) + INPUT(i,j) + INPUT(i,j+1) + INPUT(i,j+2) + INPUT(i+1,j) + INPUT(i+1,j+1) + INPUT(i+1,j+2))/9;
OUTPUT(i+1,j+1) = (INPUT(i,j) + INPUT(i,j+1) + INPUT(i,j+2) + INPUT(i+1,j) + INPUT(i+1,j+1) + INPUT(i+1,j+2) + INPUT(i+2,j) + INPUT(i+2,j+1) + INPUT(i+2,j+2))/9;
}
else
{
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