code example
RapidMind Multi-Core Development Platform

#include <rapidmind/platform.hpp>
using namespace rapidmind;


int main(int argc, char *argv[]) {
  int n = ...;
  rapidmind::init();
  float *x, *y;
  Array<1, Value1f> xr(n+1);
  Array<1, Value1f> yr(n+1);
  x = xr.write_data();
  y = yr.write_data();

  ... // fill x, y

  Program add3 = RM_BEGIN {
   In<Value1f> a;
   In<Value1f> b;
   In<Value1f> c;
   Out<Value1f> d;
   d = a + (b + c) * .5;
  } RM_END;
 
  Program add2 = RM_BEGIN {
   In<Value1f> a;
   In<Value1f> b;
   Out<Value1f> c;
   c = a + b;
  } RM_END;
 
  Program sqr = RM_BEGIN {
   In<Value1f> a;
   Out<Value1f> b;
   b = a * a;
  } RM_END;
 
  Array<1, Value1f> x0 = add3(slice(xr,1,n-1),
   offset(yr,2), take(yr,n-1));
  xr = x0;
  Array<1, Value1f> er = reduce(add2,
   sqr(slice(yr,1,n-1));
  float e = *er.read_data();

  ... // output x, e

  return 0;
}

[start] [references] [download] [install]