void linear_sort_streamed(vector_type& input, vector_type& output)
{
    unsigned_type sum1 = checksum(input);

    stxxl::stats_data stats_begin(*stxxl::stats::get_instance());
    double start = stxxl::timestamp();

    typedef stxxl::stream::streamify_traits<vector_type::iterator>::stream_type input_stream_type;

    input_stream_type input_stream = stxxl::stream::streamify(input.begin(), input.end());

    typedef cmp_less_key comparator_type;
    comparator_type cl;

    typedef stxxl::stream::sort<input_stream_type, comparator_type, block_size> sort_stream_type;

    sort_stream_type sort_stream(input_stream, cl, run_size);

    vector_type::iterator o = stxxl::stream::materialize(sort_stream, output.begin(), output.end());
    STXXL_CHECK(o == output.end());

    double stop = stxxl::timestamp();
    std::cout << stxxl::stats_data(*stxxl::stats::get_instance()) - stats_begin;

    unsigned_type sum2 = checksum(output);

    std::cout << sum1 << " ?= " << sum2 << std::endl;
    if (sum1 != sum2)
        STXXL_MSG("WRONG DATA");

    STXXL_CHECK(stxxl::is_sorted<vector_type::const_iterator>(output.begin(), output.end(), comparator_type()));

    std::cout << "Linear sorting streamed took " << (stop - start) << " seconds." << std::endl;
}
Example #2
0
 bool operator==(box const &b2) const
 {
   return 
     std::equal(m_lower.begin(), m_lower.end(), b2.m_lower.begin())
     &&
     std::equal(m_upper.begin(), m_upper.end(), b2.m_upper.begin());
 }
unsigned_type checksum(vector_type& input)
{
    unsigned_type sum = 0;
    for (vector_type::const_iterator i = input.begin(); i != input.end(); ++i)
        sum += (unsigned_type)((*i).m_key);
    return sum;
}
Example #4
0
 std::pair<iterator, iterator> get_all(const TId id) {
     const element_type element {
         id,
         osmium::index::empty_value<TValue>()
     };
     return std::equal_range(m_vector.begin(), m_vector.end(), element, [](const element_type& a, const element_type& b) {
         return a.first < b.first;
     });
 }
Example #5
0
 typename vector_type::const_iterator find_id(const TId id) const noexcept {
     const element_type element {
         id,
         osmium::index::empty_value<TValue>()
     };
     return std::lower_bound(m_vector.begin(), m_vector.end(), element, [](const element_type& a, const element_type& b) {
         return a.first < b.first;
     });
 }
    decorated_tuple(cow_pointer_type d, const vector_type& v)
        : super(tuple_impl_info::statically_typed)
        , m_decorated(std::move(d)), m_mapping(v) {
#       ifdef CPPA_DEBUG
        const cow_pointer_type& ptr = m_decorated; // prevent detaching
#       endif
        CPPA_REQUIRE(ptr->size() >= sizeof...(ElementTypes));
        CPPA_REQUIRE(v.size() == sizeof...(ElementTypes));
        CPPA_REQUIRE(*(std::max_element(v.begin(), v.end())) < ptr->size());
    }
    decorated_tuple(cow_pointer_type d, size_t offset)
        : super(tuple_impl_info::statically_typed), m_decorated(std::move(d)) {
#       ifdef CPPA_DEBUG
        const cow_pointer_type& ptr = m_decorated; // prevent detaching
#       endif
        CPPA_REQUIRE((ptr->size() - offset) >= sizeof...(ElementTypes));
        CPPA_REQUIRE(offset > 0);
        size_t i = offset;
        m_mapping.resize(sizeof...(ElementTypes));
        std::generate(m_mapping.begin(), m_mapping.end(), [&]() {return i++;});
    }
void linear_sort_normal(vector_type& input)
{
    unsigned_type sum1 = checksum(input);

    stxxl::stats_data stats_begin(*stxxl::stats::get_instance());
    double start = stxxl::timestamp();

    stxxl::sort(input.begin(), input.end(), cmp_less_key(), run_size);

    double stop = stxxl::timestamp();
    std::cout << stxxl::stats_data(*stxxl::stats::get_instance()) - stats_begin;

    unsigned_type sum2 = checksum(input);

    std::cout << sum1 << " ?= " << sum2 << std::endl;

    STXXL_CHECK(stxxl::is_sorted<vector_type::const_iterator>(input.begin(), input.end()));

    std::cout << "Linear sorting normal took " << (stop - start) << " seconds." << std::endl;
}
Example #9
0
 const TValue get(const TId id) const final {
     const element_type element {
         id,
         osmium::index::empty_value<TValue>()
     };
     const auto result = std::lower_bound(m_vector.begin(), m_vector.end(), element, [](const element_type& a, const element_type& b) {
         return a.first < b.first;
     });
     if (result == m_vector.end() || result->first != id) {
         not_found_error(id);
     } else {
         return result->second;
     }
 }
Example #10
0
      boost::logic::tribool eval(const partial_assignments_type& phi) {

        typedef std::set<value_type> set_type;
        set_type collected_values;
        typedef typename set_type::size_type size_type;
        size_type set_size = 0;

        typedef typename vector_type::const_iterator vector_iterator;
        const vector_iterator& end(variable_vector.end());
        for (vector_iterator i = variable_vector.begin(); i != end; ++i) {
          const domain_type& D(phi(*i));
          if (D.size() == 0) return false;
          if (D.size() == 1) {
            collected_values.insert(*(i -> second.begin()));
            if (collected_values == set_size++)
              return false;
          }
        }
        assert(set_size == collected_values.size());
        if (set_size == variable_vector.size())
          return true;
        else
          return boost::logic::indeterminate;
      }
Example #11
0
void lattice<dimension, float_type>::fcc(
    position_iterator first, position_iterator last
  , vector_type const& length, vector_type const& offset
)
{
    typedef fixed_vector<unsigned int, dimension> index_type;
    typedef close_packed_lattice<vector_type, index_type> lattice_type;

    scoped_timer_type timer(runtime_.set);

    LOG_TRACE("generating fcc lattice for " << last - first << " particles, box: " << length << ", offset: " << offset);
    size_t npart = last - first;
    double u = lattice_type(1).size();
    double V = accumulate(length.begin(), length.end(), 1., multiplies<double>()) / ceil(npart / u);
    double a = pow(V, 1. / dimension);
    index_type n(length / a);
    while (npart > u * accumulate(n.begin(), n.end(), 1, multiplies<unsigned int>())) {
        vector_type t;
        for (size_t i = 0; i < dimension; ++i) {
            t[i] = length[i] / (n[i] + 1);
        }
        typename vector_type::iterator it = max_element(t.begin(), t.end());
        a = *it;
        // recompute n to preserve aspect ratios of box, ensure that
        // no compoment decreases and that at least one component
        // is incremented
        index_type m = n;
        n = element_max(m, static_cast<index_type>(length / a));
        if (m == n) {
            n += index_type(1);
        }
    }
    LOG("placing particles on fcc lattice: a = " << a);
    LOG_DEBUG("number of fcc unit cells: " << n);

    unsigned int N = static_cast<unsigned int>(
        u * accumulate(n.begin(), n.end(), 1, multiplies<unsigned int>())
    );
    if (N > npart) {
        LOG_WARNING("lattice not fully occupied (" << N << " sites)");
    }

    // insert a vacancy every 'skip' sites
    unsigned int skip = (N - npart) ? static_cast<unsigned int>(ceil(static_cast<double>(N) / (N - npart))) : 0;
    if (skip) {
        LOG_TRACE("insert a vacancy at every " << skip << "th site");
    }

    lattice_type const lattice(n);

    size_t i = 0;
    for (position_iterator r_it = first; r_it != last; ++r_it, ++i) {
        // skip vacant lattice points
        if (skip && i % skip == skip - 1) {
            ++i;
        }

        vector_type& r = *r_it = lattice(i);
        // scale by lattice constant
        r *= a;
        // shift origin of lattice to offset
        r += offset;
    }
    assert(i <= N);
    LOG_DEBUG("number of particles inserted: " << last - first);
}
Example #12
0
//
// This function inserts "Clones" into the
// the view. 
//
// We need to pass the first argument
// as a non-const reference to be able to store
// 'T*' instead of 'const T*' objects. Alternatively,
// we might change the declaration of the 'view_type'
// to 
//     typedef boost::ptr_vector<const photon,boost::view_clone_manager> 
//               view_type;     ^^^^^^
//
void insert( vector_type& from, view_type& to )
{
        to.insert( to.end(), 
                   from.begin(),
                   from.end() );
}
Example #13
0
CDataStream::CDataStream(const vector_type& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
{
    Init(nTypeIn, nVersionIn);
}
Example #14
0
 void erase_removed() {
     m_vector.erase(
         std::remove_if(m_vector.begin(), m_vector.end(), is_removed),
         m_vector.end()
     );
 }
Example #15
0
 void consolidate() {
     std::sort(m_vector.begin(), m_vector.end());
 }
Example #16
0
 void sort() final {
     std::sort(m_vector.begin(), m_vector.end());
 }
Example #17
0
 iterator begin() {
     return m_vector.begin();
 }
Example #18
0
 void sort() override final {
     std::sort(m_vector.begin(), m_vector.end());
 }