Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82429802
algorithm_bit_slower.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Sep 11, 09:10
Size
2 KB
Mime Type
text/x-c
Expires
Fri, Sep 13, 09:10 (2 d)
Engine
blob
Format
Raw Data
Handle
20699462
Attached To
R10834 Project_multiproc
algorithm_bit_slower.c
View Options
/*
============================================================================
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
Log In to Comment