Sha256: 4190f372d4cdff25638819d86e8dd1b7b424bd9c9f395a00753c061499b10686

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 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 scop
	{
		#pragma species kernel in[0:A-1,0:B-1]|neighbourhood(-1:1,-1:1) -> out[0:A-1,0:B-1]|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 example02_k1
	}
	#pragma endscop
	
	// Clean-up and exit the function
	fflush(stdout);
	return 0;
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bones-compiler-1.3.1 test/examples/neighbourhood/example02_species.c