Esempio n. 1
0
void mpkernel(int offset, int stride, int n, int sz, 
	      double *dev_x, double *dev_y, 
	      bool reset, bool print) 
{
  typedef typename vector_type::storage_type storage_type;

  // multi-point expansions
  vector_type x(sz, 0.0), y(sz, 0.0);

  // Loop over elements, propagating sz samples simultaneously
  for (int e=0; e<n; e++) {

    // Initialize x
    if (reset && storage_type::supports_reset) {
      storage_type& x_s = x.storage();
      storage_type& y_s = y.storage();
      x_s.shallowReset(dev_x+offset, sz, stride, false);
      y_s.shallowReset(dev_y+offset, sz, stride, false);
    }
    else {
      for (int i=0; i<sz; i++)
	x.fastAccessCoeff(i) = dev_x[offset+i*stride];
    }

    simple_function(x,y);

    // Print x and y
    if (print) {
      std::cout << "x(0) = [ ";
      for (int i=0; i<sz; i++)
	std::cout << x.coeff(i) << " ";
      std::cout << "]" << std::endl << std::endl;
      
      std::cout << "y(0) = [ ";
      for (int i=0; i<sz; i++)
	std::cout << y.coeff(i) << " ";
      std::cout << "]" << std::endl << std::endl;
    }

    // Return result
    if (!(reset && vector_type::storage_type::supports_reset)) {
      for (int i=0; i<sz; i++)
    	dev_y[offset+i*stride] = y.fastAccessCoeff(i);
    }

    offset += stride*sz;

  }
}
Esempio n. 2
0
void kernel(int offset, int stride, int n, int sz, double *dev_x, double *dev_y)
{
  // Loop over elements
  double x, y;
  for (int e=0; e<n; e++) {
    
    for (int i=0; i<sz; i++) {

      // Initialize x
      x = dev_x[offset+i*stride];

      // Compute function
      simple_function(x,y);

      // Return result
      dev_y[offset+i*stride] = y;

    }

    offset += stride*sz;

  }
}
Esempio n. 3
0
int main(int argc, char **argv)
{
  try {

    // Polynomial expansions
    const int sz = 10;
    vec_type u(sz, 0.0);
    for (int i=0; i<sz; i++) {
      u.fastAccessCoeff(i) = 0.1 * i;
    }

    // Compute PCE expansion of function
    vec_type v = simple_function(u);

    // Print u and v
    std::cout << "v = 1.0 / (log(u)^2 + 1):" << std::endl;
    std::cout << "\tu = " << u << std::endl;
    std::cout << "\tv = " << v << std::endl;
    
  }
  catch (std::exception& e) {
    std::cout << e.what() << std::endl;
  }
}
int main() {
  simple_function();
}