コード例 #1
0
ファイル: boost_compute.hpp プロジェクト: 1ibrium/vexcl
void sort(vex::vector<T> &x) {
    auto queue = x.queue_list();

    for(unsigned d = 0; d < queue.size(); ++d) {
        if (x.part_size(d)) {
            boost::compute::command_queue q( queue[d]() );
            boost::compute::buffer buf( x(d).raw() );

            boost::compute::sort(
                    boost::compute::make_buffer_iterator<T>(buf, 0),
                    boost::compute::make_buffer_iterator<T>(buf, x.part_size(d)),
                    q
                    );
        }
    }

    if (queue.size() > 1) {
        // Get sorted partitions to host side and do multiway merge sort.

        std::vector<T> src(x.size()), dst(x.size());
        vex::copy(x, src);

        std::vector< typename std::vector<T>::const_iterator > begin(queue.size());
        std::vector< typename std::vector<T>::const_iterator > end  (queue.size());

        for(unsigned d = 0; d < queue.size(); ++d) {
            begin[d] = src.begin() + x.part_start(d);
            end  [d] = src.begin() + x.part_start(d + 1);
        }


        for(auto pos = dst.begin(); pos != dst.end(); ++pos) {
            int winner = -1;
            for(unsigned d = 0; d < queue.size(); ++d) {
                if (begin[d] == end[d])
                    continue;

                if (winner < 0 || *begin[d] < *begin[winner])
                    winner = d;
            }

            *pos = *begin[winner]++;
        }

        vex::copy(dst, x);
    }
}
コード例 #2
0
 static bool same_size( const vex::vector< T > &x1 , const vex::vector< T > &x2 )
 {
     return x1.size() == x2.size();
 }
コード例 #3
0
 static void resize( vex::vector< T > &x1 , const vex::vector< T > &x2 )
 {
     x1.resize( x2.queue_list() , x2.size() );
 }