Sha256: b1380202cdcccb3e818147d77a1dbf0c943f87f08a99dc3bdd3f6556389c7d87

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 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/example1.c
// Author.............Cedric Nugteren
// Last modified on...16-April-2012
//

#include <stdio.h>
#define SIZE 60000
#define NB 2

// This is 'example1', demonstrating a basic 1D neighbourhood-based computation whose size is set by a define
int main(void) {
	int i,n;
	float result = 0;
	
	// Declare input/output arrays
	float A[SIZE];
	float B[SIZE];
	
	// Set the input data
	for(i=0;i<SIZE;i++) {
		A[i] = i/2.0;
	}
	
	// Perform the computation
	#pragma scop
	{
		#pragma species kernel A[0:SIZE-1]|neighbourhood(-NB:NB) ^ A[0:SIZE-1]|element -> B[0:SIZE-1]|element
		for (i = 0; i < SIZE; i++) {
			if (i >= NB && i < SIZE - NB) {
				result = 0;
				for (n = -NB; n <= NB; n++) {
					result = result + A[i + n];
				}
				B[i] = result / (NB * 2 + 1);
			} else {
				B[i] = A[i];
			}
		}
		#pragma species endkernel example01_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/example01_species.c