Strumenti Utente

Strumenti Sito


magistraleinformaticanetworking:spm:skepu-reduce

SKEPU reduce sample code

reduce.cpp
#include <iostream>
 
#define SKEPU_OPENMP
 
#include "skepu/vector.h"
#include "skepu/matrix.h"
#include "skepu/reduce.h"
 
using namespace std;
 
// definition of functions to be used in the map and reduce
 
UNARY_FUNC(inc,  int, a, return(a+1); )
UNARY_FUNC(dec,  int, a, return(a-1); )
UNARY_FUNC(sq,   int, a, return(a*a); )
BINARY_FUNC(add, int, a, b, return(a+b); )
BINARY_FUNC(sub, int, a, b, return(a-b); )
BINARY_FUNC(mul, int, a, b, return(a*b); )
BINARY_FUNC(div, int, a, b, return(a/b); )
 
#define N 4
 
int main()
{	
  // declare vectors 
  skepu::Vector<float> v0(N);
  skepu::Matrix<float> m(N,N);
 
  // initialize the vector(s) to some meaningful value
  for(int i=0; i<N;i++) {
    v0[i]=i+1;
  }
  cout << "Initial  array is " << v0 << endl;   
  for(int i=0; i<N; i++) 
    for(int j=0; j<N; j++) 
      m(i,j) = (i*N)+j;
  cout << "Initial matrix is " << m << endl; 
 
  skepu::Reduce<add> reduceadd(new add);
  int i = reduceadd(v0);
  cout << "After reduceadd : " << i << endl; 
 
  skepu::Reduce<add> reduceaddmat(new add); 
  i = reduceaddmat(m);
  cout << "After reduceaddmat : " << i << endl;
  return 0;
}
magistraleinformaticanetworking/spm/skepu-reduce.txt · Ultima modifica: 28/10/2013 alle 17:31 (11 anni fa) da Marco Danelutto