Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F72849915
algorithm_extended.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, Jul 17, 08:51
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Jul 19, 08:51 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
19111964
Attached To
R10834 Project_multiproc
algorithm_extended.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);
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
Log In to Comment