Exemple #1
0
// given two vectors, compare their elements
void compareResults(thrust::device_vector<int> a, thrust::device_vector<int> b, int numOfParticles, string txt)
{
	thrust::device_vector<int> c(numOfParticles);
	thrust::fill(c.begin(), c.end(), 0);

	thrust::for_each(CountingIterator(0), CountingIterator(0)+numOfParticles,
			compare(thrust::raw_pointer_cast(&*a.begin()), thrust::raw_pointer_cast(&*b.begin()), thrust::raw_pointer_cast(&*c.begin())));
	int count = thrust::reduce(c.begin(), c.begin() + numOfParticles);

	std::string output = (count==0) ? txt+" - Result is the same" : txt+" - Result is NOT the same";
  std::cout << output << std::endl;
	if(count != 0) std::cout << "count " << count << std::endl << std::endl;
}
 PODMap<GlobalOrdinal> getPOD() const {
   PODMap<GlobalOrdinal> ret;
   ret.n=d_ids.size();
   ret.rows=const_cast<GlobalOrdinal*>(thrust::raw_pointer_cast(&d_rows[0]));
   ret.ids=const_cast<GlobalOrdinal*>(thrust::raw_pointer_cast(&d_ids[0]));
   return ret;
 }
  void set_map(const std::map<GlobalOrdinal,GlobalOrdinal> &map) {
    std::vector<GlobalOrdinal> rows;
    std::vector<GlobalOrdinal> ids;
    int size=map.size();
    rows.reserve(size);
    ids.reserve(size);

    for(typename std::map<GlobalOrdinal,GlobalOrdinal>::const_iterator it=map.begin(); it!=map.end(); ++it) {
      ids.push_back(it->first);
      rows.push_back(it->second);
    }
    d_ids.resize(size);
    d_rows.resize(size);

    cudaMemcpyAsync(thrust::raw_pointer_cast(&d_ids[0]),&ids[0],size*sizeof(GlobalOrdinal),cudaMemcpyHostToDevice,CudaManager::s1);
    cudaMemcpyAsync(thrust::raw_pointer_cast(&d_rows[0]),&rows[0],size*sizeof(GlobalOrdinal),cudaMemcpyHostToDevice,CudaManager::s1);
  }
Exemple #4
0
 // overloaded () operator invoked by odeint
 public: void operator()(
   const thrust::device_vector<real_t>&, 
   thrust::device_vector<real_t> &dxy_dt, 
   const real_t
 )
 {
   thrust::transform(
     iter, iter + stat.n_part, 
     dxy_dt.begin() + stat.n_part, 
     term_vel(stat, envi)
   );
 }
Exemple #5
0
 static void resize( thrust::device_vector< T > &x , const thrust::device_vector< T > &y )
 {
     x.resize( y.size() );
 }
Exemple #6
0
 static bool same_size( const thrust::device_vector< T > &x , const thrust::device_vector< T > &y )
 {
     return x.size() == y.size();
 }
Exemple #7
0
T FuncEval(const thrust::device_vector<FunctionObj<T> > &f_obj, const T *x_in) {
  return thrust::inner_product(f_obj.cbegin(), f_obj.cend(),
                               thrust::device_pointer_cast(x_in),
                               static_cast<T>(0), thrust::plus<T>(),
                               FuncEvalF<T>());
}
Exemple #8
0
void ProxEval(const thrust::device_vector<FunctionObj<T> > &f_obj, T rho,
              const T *x_in, T *x_out) {
  thrust::transform(thrust::device, f_obj.cbegin(), f_obj.cend(),
                    thrust::device_pointer_cast(x_in),
                    thrust::device_pointer_cast(x_out), ProxEvalF<T>(rho));
}
Exemple #9
0
void print_cuda_vec(const thrust::device_vector<Scalar>& vec, const std::string& name)
{
  for(size_t i=0; i<vec.size(); ++i) {
    std::cout << name << "["<<i<<"]: " << vec[i] << std::endl;
  }
}