Page MenuHomec4science

algorithm_bit_slower.c
No OneTemporary

File Metadata

Created
Wed, Sep 11, 09:10

algorithm_bit_slower.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);
double * midbuffer = malloc(length * sizeof(double));
int i;
int j;
const int matsize = length*length;
// Parallelize this!!
for(int n=0; n < iterations; n++)
{
printf("Loop: %d\n", n);
#pragma omp parallel for private(i,j)
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;
}
// compute line first
OUTPUT(i,j) = (INPUT(i,j-1) + INPUT(i,j) + INPUT(i,j+1));
}
// constant time operation, minimize cache misses
memset(midbuffer, 0, length * sizeof(double));
double old;
for(int i=1; i<length-1; i++) { // loop i first
for(int j=1; j<length-1; j++) // loop j later
{
if ( ((i == length/2-1) || (i== length/2))
&& ((j == length/2-1) || (j == length/2)) ) {
continue;
}
old = OUTPUT(i,j);
OUTPUT(i,j) = (midbuffer[j] + OUTPUT(i,j) + OUTPUT(i+1,j)) / 9;
midbuffer[j] = old;
}
}
temp = input;
input = output;
output = temp;
}
free(midbuffer);
}

Event Timeline