inline typename CrsArray< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror create_mirror_view( const CrsArray<DataType,Arg1Type,Arg2Type,SizeType > & view , typename Impl::enable_if< ! ViewTraits<DataType,Arg1Type,Arg2Type,void>::is_hostspace >::type * = 0 ) { // Force copy: typedef Impl::ViewAssignment< Impl::LayoutDefault > alloc ; typedef CrsArray< DataType , Arg1Type , Arg2Type , SizeType > crsarray_type ; typename crsarray_type::HostMirror tmp ; typename crsarray_type::row_map_type::HostMirror tmp_row_map ; // Allocation to match: alloc( tmp_row_map , view.row_map ); alloc( tmp.entries , view.entries ); // Assignment of 'const' from 'non-const' tmp.row_map = tmp_row_map ; // Deep copy: deep_copy( tmp_row_map , view.row_map ); deep_copy( tmp.entries , view.entries ); return tmp ; }
inline typename CrsArray< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror create_mirror( const CrsArray<DataType,Arg1Type,Arg2Type,SizeType > & view ) { #if KOKKOSARRAY_MIRROR_VIEW_OPTIMIZE // Allow choice via type: return create_mirror_view( view ); #else // Force copy: typedef Impl::ViewAssignment< Impl::LayoutDefault > alloc ; typedef CrsArray< DataType , Arg1Type , Arg2Type , SizeType > crsarray_type ; typename crsarray_type::HostMirror tmp ; typename crsarray_type::row_map_type::HostMirror tmp_row_map ; // Allocation to match: alloc( tmp_row_map , view.row_map ); alloc( tmp.entries , view.entries ); // Assignment of 'const' from 'non-const' tmp.row_map = tmp_row_map ; // Deep copy: deep_copy( tmp_row_map , view.row_map ); deep_copy( tmp.entries , view.entries ); return tmp ; #endif }
bigInt *sub_modulus(const bigInt *first, const bigInt *second) { if(!first || !first->sign) { bigInt *result = deep_copy(second); result->sign *= -1; return result; } if(!second || !second->sign) return deep_copy(first); int compare_first_second = compare_modulus(first, second); if(!compare_first_second) return new_bigInt(); // return 0 if(compare_first_second < 0) { const bigInt *temp = first; first = second; second = temp; } bigInt *result = light_copy(first); result->digits = (type *)calloc(result->length_full, sizeof(type)); memcpy(result->digits, first->digits, first->length * sizeof(type)); sub_modulus_fast(result, second); result->sign *= get_sign(compare_first_second); return result; }
inline typename CrsArrayType::crsarray_type create_crsarray( const std::string & label , const std::vector< std::vector< InputSizeType > > & input ) { typedef CrsArrayType output_type ; typedef std::vector< std::vector< InputSizeType > > input_type ; typedef typename output_type::entries_type entries_type ; typedef typename output_type::size_type size_type ; typedef typename Impl::assert_shape_is_rank_one< typename entries_type::shape_type >::type ok_rank ; typedef View< typename output_type::size_type [] , typename output_type::array_layout , typename output_type::device_type > work_type ; output_type output ; // Create the row map: const size_t length = input.size(); { work_type row_work( "tmp" , length + 1 ); typename work_type::HostMirror row_work_host = create_mirror_view( row_work ); size_t sum = 0 ; row_work_host[0] = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { row_work_host[i+1] = sum += input[i].size(); } deep_copy( row_work , row_work_host ); output.entries = entries_type( label , sum ); output.row_map = row_work ; } // Fill in the entries: { typename entries_type::HostMirror host_entries = create_mirror_view( output.entries ); size_t sum = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { for ( size_t j = 0 ; j < input[i].size() ; ++j , ++sum ) { host_entries( sum ) = input[i][j] ; } } deep_copy( output.entries , host_entries ); } return output ; }
inline typename StaticCrsGraphType::staticcrsgraph_type create_staticcrsgraph( const std::string & label , const std::vector< std::vector< InputSizeType > > & input ) { typedef StaticCrsGraphType output_type ; typedef typename output_type::entries_type entries_type ; static_assert( entries_type::rank == 1 , "Graph entries view must be rank one" ); typedef View< typename output_type::size_type [] , typename output_type::array_layout , typename output_type::execution_space > work_type ; output_type output ; // Create the row map: const size_t length = input.size(); { work_type row_work( "tmp" , length + 1 ); typename work_type::HostMirror row_work_host = create_mirror_view( row_work ); size_t sum = 0 ; row_work_host[0] = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { row_work_host[i+1] = sum += input[i].size(); } deep_copy( row_work , row_work_host ); output.entries = entries_type( label , sum ); output.row_map = row_work ; } // Fill in the entries: { typename entries_type::HostMirror host_entries = create_mirror_view( output.entries ); size_t sum = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { for ( size_t j = 0 ; j < input[i].size() ; ++j , ++sum ) { host_entries( sum ) = input[i][j] ; } } deep_copy( output.entries , host_entries ); } return output ; }
void cgsolve( const CrsMatrix<AScalarType,Device> & A , const View<VScalarType*,LayoutRight,Device> & b , const View<VScalarType*,LayoutRight,Device> & x , size_t & iteration , double & normr , double & iter_time , const size_t maximum_iteration = 200 , const double tolerance = std::numeric_limits<VScalarType>::epsilon() ) { typedef View<VScalarType*,LayoutRight,Device> vector_type ; const size_t count = b.dimension_0(); vector_type p ( "cg::p" , count ); vector_type r ( "cg::r" , count ); vector_type Ap( "cg::Ap", count ); /* r = b - A * x ; */ /* p = x */ deep_copy( p , x ); /* Ap = A * p */ multiply( A , p , Ap ); /* r = b - Ap */ waxpby( count , 1.0 , b , -1.0 , Ap , r ); /* p = r */ deep_copy( p , r ); double old_rdot = dot( count , r ); normr = std::sqrt( old_rdot ); iteration = 0 ; Kokkos::Impl::Timer wall_clock ; while ( tolerance < normr && iteration < maximum_iteration ) { /* pAp_dot = dot( p , Ap = A * p ) */ /* Ap = A * p */ multiply( A , p , Ap ); const double pAp_dot = dot( count , p , Ap ); const double alpha = old_rdot / pAp_dot ; /* x += alpha * p ; */ axpy( count, alpha, p , x ); /* r -= alpha * Ap ; */ axpy( count, -alpha, Ap, r ); const double r_dot = dot( count , r ); const double beta = r_dot / old_rdot ; /* p = r + beta * p ; */ xpby( count , r , beta , p ); normr = std::sqrt( old_rdot = r_dot ); ++iteration ; } iter_time = wall_clock.seconds(); }
node* node::deep_copy(const node* list) { $1 node* new_node = new node(); new_node->set_value(list->get_value()); new_node->set_type(list->get_type()); if(list->get_left() != NULL) *new_node -= deep_copy(list->get_left()); if(list->get_right() != NULL) *new_node += deep_copy(list->get_right()); return new_node; };
bool StreamReader::rwAsync() { if (nullptr == pool) { pool = std::make_shared<ZMBCommon::ThreadsPool>(2); file_pkt_q->imbue(pool); } ZMBCommon::CallableDoubleFunc readTask; readTask.functor = [=]() { AVPacket pkt; ::memset(&pkt, 0x00, sizeof(AVPacket)); av_init_packet(&pkt); int res = ff.read_frame(&pkt); if (res < 0) { return; } //dispatch the packet for writing: auto avpkt = std::make_shared<av::Packet> (); avpkt->deep_copy(&pkt); av::Rational tb(*ff.get_timebase()); avpkt->setTimeBase(tb); assert(avpkt->getSize() > 0); ZMBCommon::CallableDoubleFunc writeTask; writeTask.functor = [=]() { file_pkt_q->writeAsync(avpkt); }; pool->submit(writeTask); }; pool->submit(readTask); }
operator boost::asio::mutable_buffer() { if (is_shared()) deep_copy(); auto pv = zmq_msg_data(const_cast<zmq_msg_t*>(&msg_)); return boost::asio::buffer(pv, size()); }
void scatterStack (const ConstMatrixViewType& R_stack, MatrixViewType& R_local, const Teuchos::RCP<MessengerBase<typename MatrixViewType::scalar_type> >& messenger) { typedef typename MatrixViewType::ordinal_type ordinal_type; typedef typename MatrixViewType::scalar_type scalar_type; typedef ConstMatView< ordinal_type, scalar_type > const_view_type; const int nprocs = messenger->size(); const int my_rank = messenger->rank(); if (my_rank == 0) { const ordinal_type ncols = R_stack.ncols(); // Copy data from top ncols x ncols block of R_stack into R_local. const_view_type R_stack_view_first (ncols, ncols, R_stack.get(), R_stack.lda()); deep_copy (R_local, R_stack_view_first); // Loop through all other processors, sending each the next // ncols x ncols block of R_stack. RMessenger< ordinal_type, scalar_type > sender (messenger); for (int destProc = 1; destProc < nprocs; ++destProc) { const scalar_type* const R_ptr = R_stack.get() + destProc*ncols; const_view_type R_stack_view_cur (ncols, ncols, R_ptr, R_stack.lda()); sender.send (R_stack_view_cur, destProc); } } else { const int srcProc = 0; R_local.fill (scalar_type(0)); RMessenger< ordinal_type, scalar_type > receiver (messenger); receiver.recv (R_local, srcProc); } }
CondorError& CondorError::operator=(CondorError& copy) { if (© != this) { clear(); deep_copy(copy); } return *this; }
// redirection to subtraction and addition of modules bigInt *add_with_sign(const bigInt *first, const bigInt *second, int sign_of_operation) { int sign_first = get_sign(first->sign); int sign_second = get_sign(second->sign); if(!sign_second) return deep_copy(first); if(!sign_first) { bigInt *result = deep_copy(second); result->sign *= sign_of_operation; return result; } if(sign_first + sign_second) return sign_of_operation < 0 ? sub_modulus(first, second) : add_modulus(first, second); return sign_of_operation < 0 ? add_modulus(first, second) : sub_modulus(second, first); }
bigInt *add_modulus(const bigInt *first, const bigInt *second) { if(!first || !first->sign) return deep_copy(second); if(!second || !second->sign) return deep_copy(first); int length = get_max(first->length_full, second->length); if(second->length >= first->length_full || first->length == first->length_full) length += length_spare; bigInt *result = light_copy(first); result->length_full = length; result->digits = (type *)calloc(result->length_full, sizeof(type)); memcpy(result->digits, first->digits, sizeof(type) * first->length); return add_modulus_fast(result, second); }
t_JMC& t_JMC::operator= (const t_JMC& _rhs) { deep_copy(_rhs); return *this; }
lst_node deep_copy(lst_node node) { lst_node copy = calloc(1, sizeof(struct lst_node_struct)); memcpy(copy, node, sizeof(struct lst_node_struct)); // Recurse on each child // We only use this when building dijunction trees => max of two siblings if (copy->left_child) { copy->left_child = deep_copy(copy->left_child); if (copy->left_child->right_sib) copy->left_child->right_sib = deep_copy(copy->left_child->right_sib); } return copy; }
void tree< T , A >:: deep_copy( NodePtr_t ptr , NodePtr_t src , bool child /*= true*/ ) { if ( src != 0 ) { NodePtr_t node_ptr = alloc_node( ptr ); allocator_.construct( & node_ptr->value , src->value ); if ( child ) ptr->child = node_ptr; else ptr->right = node_ptr; ++size_; deep_copy( node_ptr , src->child ); deep_copy( node_ptr , src->right , false ); } } // tree< T , A >::deep_copy
cons_t* deep_copy(const cons_t *p) { if ( !p ) return NULL; cons_t *r = new cons_t(); memcpy(r, p, sizeof(cons_t)); if ( listp(r) ) { r->car = deep_copy(r->car); r->cdr = deep_copy(r->cdr); } else if ( syntaxp(r) ) r->syntax->transformer = deep_copy(r->syntax->transformer); else if ( stringp(r) ) r->string = copy_str(r->string); return r; }
int rpcudp::sendto(const void* buf, size_t bufsize, int flag, const udpaddr& addr) { _spinlock.lock(); auto& client = _get_client(addr); _spinlock.unlock(); const_shared_memory memory( deep_copy(const_memory_block(buf, bufsize))); return client.sendto(memory, addr); }
void tree< T , A >::insert( iterator it , const Self & t ) { NodePtr_t _T = alloc_node(); deep_copy( _T , get_node_ptr( t.begin() ) ); NodePtr_t _S = get_node_ptr( it ); if ( _S->child != 0 && _S->child != root_ ) deep_erase( _S->child ); _S->child = _T->child; if ( _T->child ) _T->child->left = _S; free_node( _T ); }
inline typename StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror create_mirror( const StaticCrsGraph<DataType,Arg1Type,Arg2Type,SizeType > & view ) { // Force copy: //typedef Impl::ViewAssignment< Impl::ViewDefault > alloc ; // unused typedef StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType > staticcrsgraph_type ; typename staticcrsgraph_type::HostMirror tmp ; typename staticcrsgraph_type::row_map_type::HostMirror tmp_row_map = create_mirror( view.row_map); typename staticcrsgraph_type::row_block_type::HostMirror tmp_row_block_offsets = create_mirror( view.row_block_offsets); // Allocation to match: tmp.row_map = tmp_row_map ; // Assignment of 'const' from 'non-const' tmp.entries = create_mirror( view.entries ); tmp.row_block_offsets = tmp_row_block_offsets ; // Assignment of 'const' from 'non-const' // Deep copy: deep_copy( tmp_row_map , view.row_map ); deep_copy( tmp.entries , view.entries ); deep_copy( tmp_row_block_offsets , view.row_block_offsets ); return tmp ; }
// read dirty int htable_find(struct htable *ht, uchar * key, int klen, int type, uchar * buffer, int vlen, struct mvalue *md, hashval_t *hashd) { int idx, debug = DEBUG_TIMES, ret; struct hdata *hd = NULL; struct hentry *he = NULL; struct mvalue *mx = NULL; uchar *val; if (*hashd == 0) *hashd = (ht->h) (key, klen); idx = *hashd & ht->mask; hd = ht->table + idx; pthread_spin_lock(&hd->lock); if (hd->list == NULL) { pthread_spin_unlock(&hd->lock); return -1; } he = hd->list; while (he != NULL) { if ((ht->c) (key, he->key) == 0) { val = get_val_from_he(he, type); if (NULL == val) ret = -1; else if (buffer != NULL) ret = deep_copy(val, buffer, vlen); else { if (md != NULL) { mx = (struct mvalue *)val; *md = *mx; //meta data } ret = 1; //successed } pthread_spin_unlock(&hd->lock); return ret; } he = he->next; if (debug-- == 0) { printf("error in htable find\n"); exit(0); } } pthread_spin_unlock(&hd->lock); return -1; }
bool StreamReader::readSyncWriteAsync() { AVPacket pkt; av_init_packet(&pkt); int res = ff.read_frame(&pkt); if (res >= 0) { /*copy contents*/ auto avpkt = std::make_shared<av::Packet> (); avpkt->deep_copy(&pkt); av::Rational tb(*ff.get_timebase()); avpkt->setTimeBase(tb); assert(avpkt->getSize() > 0); file_pkt_q->writeAsync(avpkt); } return res >= 0; }
inline typename StaticCrsGraphType::staticcrsgraph_type create_staticcrsgraph( const std::string & label , const std::vector< InputSizeType > & input ) { typedef StaticCrsGraphType output_type ; //typedef std::vector< InputSizeType > input_type ; // unused typedef typename output_type::entries_type entries_type ; typedef View< typename output_type::size_type [] , typename output_type::array_layout , typename output_type::execution_space > work_type ; output_type output ; // Create the row map: const size_t length = input.size(); { work_type row_work( "tmp" , length + 1 ); typename work_type::HostMirror row_work_host = create_mirror_view( row_work ); size_t sum = 0 ; row_work_host[0] = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { row_work_host[i+1] = sum += input[i]; } deep_copy( row_work , row_work_host ); output.entries = entries_type( label , sum ); output.row_map = row_work ; } return output ; }
void gatherStack (MatrixViewType& R_stack, ConstMatrixViewType& R_local, const Teuchos::RCP<MessengerBase<typename MatrixViewType::scalar_type> >& messenger) { typedef typename MatrixViewType::ordinal_type ordinal_type; typedef typename MatrixViewType::scalar_type scalar_type; typedef MatView<ordinal_type, scalar_type> mat_view_type; const int nprocs = messenger->size(); const int my_rank = messenger->rank(); if (my_rank == 0) { const ordinal_type ncols = R_stack.ncols(); // Copy data from R_local into top ncols x ncols block of R_stack. mat_view_type R_stack_view_first (ncols, ncols, R_stack.get(), R_stack.lda()); deep_copy (R_stack_view_first, R_local); // Loop through all other processors, fetching their matrix data. RMessenger< ordinal_type, scalar_type > receiver (messenger); for (int srcProc = 1; srcProc < nprocs; ++srcProc) { const scalar_type* const R_ptr = R_stack.get() + srcProc*ncols; mat_view_type R_stack_view_cur (ncols, ncols, R_ptr, R_stack.lda()); // Fill (the lower triangle) with zeros, since // RMessenger::recv() only writes to the upper triangle. R_stack_view_cur.fill (scalar_type (0)); receiver.recv (R_stack_view_cur, srcProc); } } else { // We only read R_stack on Proc 0, not on this proc. // Send data from R_local to Proc 0. const int destProc = 0; RMessenger<ordinal_type, scalar_type> sender (messenger); sender.send (R_local, destProc); } messenger->barrier (); }
void cgsolve( const ParallelDataMap data_map , const CrsMatrix<AScalarType,Device> A , const View<VScalarType*,Device> b , const View<VScalarType*,Device> x , size_t & iteration , double & normr , double & iter_time , const size_t maximum_iteration = 200 , const double tolerance = std::numeric_limits<VScalarType>::epsilon() ) { typedef View<VScalarType*,Device> vector_type ; typedef View<VScalarType, Device> value_type ; const size_t count_owned = data_map.count_owned ; const size_t count_total = data_map.count_owned + data_map.count_receive ; Operator<AScalarType,VScalarType,Device> matrix_operator( data_map , A ); // Need input vector to matvec to be owned + received vector_type pAll ( "cg::p" , count_total ); vector_type p = Kokkos::subview< vector_type >( pAll , std::pair<size_t,size_t>(0,count_owned) ); vector_type r ( "cg::r" , count_owned ); vector_type Ap( "cg::Ap", count_owned ); /* r = b - A * x ; */ /* p = x */ deep_copy( p , x ); /* Ap = A * p */ matrix_operator.apply( pAll , Ap ); /* r = b - Ap */ waxpby( count_owned , 1.0 , b , -1.0 , Ap , r ); /* p = r */ deep_copy( p , r ); double old_rdot = dot( count_owned , r , data_map.machine ); normr = sqrt( old_rdot ); iteration = 0 ; Kokkos::Impl::Timer wall_clock ; while ( tolerance < normr && iteration < maximum_iteration ) { /* pAp_dot = dot( p , Ap = A * p ) */ /* Ap = A * p */ matrix_operator.apply( pAll , Ap ); const double pAp_dot = dot( count_owned , p , Ap , data_map.machine ); const double alpha = old_rdot / pAp_dot ; /* x += alpha * p ; */ axpy( count_owned, alpha, p , x ); /* r -= alpha * Ap ; */ axpy( count_owned, -alpha, Ap, r ); const double r_dot = dot( count_owned , r , data_map.machine ); const double beta = r_dot / old_rdot ; /* p = r + beta * p ; */ xpby( count_owned , r , beta , p ); normr = sqrt( old_rdot = r_dot ); ++iteration ; } iter_time = wall_clock.seconds(); }
t_angled_dijkstra::t_angled_dijkstra (const t_angled_dijkstra& _origin) { deep_copy(_origin); }
void host_to_device() const { deep_copy(DV::d_view,DV::h_view); }
void device_to_host(){ deep_copy(DV::h_view,DV::d_view); }
int main() { //need this to get a memory leak dump at end of code execution _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Create binary search tree, give it values {2,3,5,11,13,17} BinarySearchTree bst; bst.insert(3); bst.insert(2); bst.insert(11); bst.insert(13); bst.insert(5); bst.insert(17); // Prints to the console: 2,3,5,11,13,17, for (auto x : bst) std::cout << x << ","; std::cout << std::endl; bst.erase(6); // {2,3,5,11,13,17}, no effect bst.erase(11); // {2,3,5,13,17} auto start = std::begin(bst); auto stop = std::end(bst); int value = 17; bool keep_looking = true; // find a 17 in the list while (start != stop && keep_looking){ if (*start++ == value){ keep_looking = false; } } --start; //// Prints "17 is in the list." if (start != stop) std::cout << *start << " is in the list." << std::endl; //Construct a deep copy of bst. //std::cout << "0.\n"; //bst.print(); //std::cout << "1.\n"; BinarySearchTree deep_copy(bst); //std::cout << "2.\n"; deep_copy.insert(11); deep_copy.insert(7); // Prints to the console: 2,3,5,7,11, 13, 17, for (auto x : deep_copy) std::cout << x << ","; std::cout << std::endl; //std::cout << "\n\n\n\n\n"; //bst.print(); //deep_copy.print(); return 0; }
CondorError::CondorError(CondorError& copy) { init(); deep_copy(copy); }