Sha256: 89bf71ef5f89eeb2a135b8b75966bbbf00981867b6b405fec6095bf0d7765d4e
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
// // This file is part of the Bones source-to-source compiler examples. This C-code // example is meant to illustrate the use of Bones. For more information on Bones // use the contact information below. // // == More information on Bones // Contact............Cedric Nugteren <c.nugteren@tue.nl> // Web address........http://parse.ele.tue.nl/bones/ // // == File information // Filename...........neighbourhood/example2.c // Author.............Cedric Nugteren // Last modified on...16-April-2012 // #include <stdio.h> #define A 256 #define B 512 // This is 'example2', demonstrating a 2D array, a 2D neighbourhood and a for-loop-less notation of the neighbourhood accesses int main(void) { int i,j; // Declare input/output arrays float in[A][B]; float out[A][B]; // Set the input data for(i=0;i<A;i++) { for(j=0;j<B;j++) { in[i][j] = i+j; } } // Perform the computation #pragma species kernel 0:255,0:511|neighbourhood(-1:1,-1:1) -> 0:255,0:511|element for(i=0;i<A;i++) { for(j=0;j<B;j++) { if (i >= 1 && j >= 1 && i < (A-1) && j < (B-1)) { out[i][j] = (in[i+1][j+1] + in[i+1][ j ] + in[i+1][j-1] + in[ i ][j+1] + in[ i ][ j ] + in[ i ][j-1] + in[i-1][j+1] + in[i-1][ j ] + in[i-1][j-1])/9.0; } else { out[i][j] = in[i][j]; } } } #pragma species endkernel example2 // Clean-up and exit the function fflush(stdout); return 0; }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bones-compiler-1.3.1 | examples/neighbourhood/example02.c |
bones-compiler-1.1.0 | examples/neighbourhood/example2.c |