Sha256: 11dceb1b9d23b40edf78622e8cdcaf413ded8f9a2eba08f8c271c12da335b21a

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

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

#include <stdio.h>
#include <stdlib.h>
#define SIZE 1024*1024

// This is 'example4', demonstrating a basic 256-bin histogram computation
int main(void) {
	int i;
	unsigned char index;
	
	// Declare input/output arrays
	unsigned char *A = (unsigned char *)malloc(SIZE*sizeof(unsigned char));
	int B[256];
	
	// Set the input data
	for(i=0;i<SIZE;i++) {
		A[i] = i%256;
	}
	
	// Set the output to zero before starting
	for (i=0;i<256;i++) {
		B[i] = 0;
	}
	
	// Perform the computation
	#pragma species kernel 0:SIZE-1|element -> 0:255|shared
	for(i=0;i<SIZE;i++) {
		index = A[i];
		B[index]++;
	}
	#pragma species endkernel example4
	
	// Clean-up and exit the function
	free(A);
	fflush(stdout);
	return 0;
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bones-compiler-1.3.1 examples/shared/example04.c
bones-compiler-1.1.0 examples/shared/example4.c