Page MenuHomec4science

algorithm_final.c
No OneTemporary

File Metadata

Created
Wed, Aug 21, 02:14

algorithm_final.c

/*
============================================================================
Filename : algorithm.c
Author : Your names go here
SCIPER : Your SCIPER numbers
============================================================================
*/
#include <math.h>
#include <stdio.h>
#define INPUT(I,J) input[(I)*length+(J)]
#define OUTPUT(I,J) output[(I)*length+(J)]
void simulate(double *input, double *output, int threads, int length, int iterations)
{
double *temp;
const int B = 8;
omp_set_num_threads(threads);
for(int n=0; n < iterations; n++)
{
int i = 0;
int j = 0;
#pragma omp parallel for private(i,j)
for(int kk=0; kk<(length-1)*(length-1)-1; kk+=B)
{
for(int k=kk; i<kk+B; k++)
{
i = k/(length-2) + 1;
j = k%(length-2) + 1;
if ( ((i == length/2-1) || (i== length/2)) && ((j == length/2-1) || (j == length/2)) )
continue;
if((i<length-1)&&(j<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;
}
}
}
temp = input;
input = output;
output = temp;
}
}

Event Timeline