void operator() (const state_type rhot, double t) const { // Find dimension of density matric from vector. int side = int(sqrt(float(rhot.size()))); // Grab elements corresponding to diagonals in density matrix. const vector_slice<const state_type> diags(rhot, slice(0,side+1,side)); // Print diagonal elements. m_out << t; for(size_t n = 0; n < diags.size(); n++) m_out << "\t" << diags[n].real(); m_out << "\t" << sum(diags).real(); m_out << endl; }
void copy(vector_slice<vector<SCALARTYPE> > const & gpu_vector_slice, VectorType & cpu_vector) { assert(gpu_vector_slice.end() - gpu_vector_slice.begin() >= 0 && bool("Range must have nonnegative length!")); if (gpu_vector_slice.end() - gpu_vector_slice.begin() > 0) { std::vector<SCALARTYPE> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size()); viennacl::backend::memory_read(gpu_vector_slice.handle(), sizeof(SCALARTYPE)*gpu_vector_slice.start(), sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0])); for (vcl_size_t i=0; i<cpu_vector.size(); ++i) cpu_vector[i] = temp_buffer[i * gpu_vector_slice.stride()]; } }
void copy(const VectorType & cpu_vector, vector_slice<vector<SCALARTYPE> > & gpu_vector_slice ) { if (cpu_vector.size() > 0) { std::vector<SCALARTYPE> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size()); viennacl::backend::memory_read(gpu_vector_slice.handle(), sizeof(SCALARTYPE)*gpu_vector_slice.start(), sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0])); for (vcl_size_t i=0; i<cpu_vector.size(); ++i) temp_buffer[i * gpu_vector_slice.stride()] = cpu_vector[i]; viennacl::backend::memory_write(gpu_vector_slice.handle(), sizeof(SCALARTYPE)*gpu_vector_slice.start(), sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0])); } }
vector_slice(vector_slice<VectorType> const & v, slice const & entry_slice) : base_type(const_cast<handle_type &>(v.handle()), entry_slice.size(), v.start() + v.stride() * entry_slice.start(), entry_slice.stride() * v.stride()) {}