Skip to content

Commit

Permalink
Adding uninitialized_move and uninitialized_move_n
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed May 30, 2017
1 parent 59b11ef commit d15ade8
Show file tree
Hide file tree
Showing 9 changed files with 1,261 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/CMakeLists.txt
Expand Up @@ -101,6 +101,7 @@ set(doxygen_dependencies
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/transform_reduce_binary.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/uninitialized_copy.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/uninitialized_fill.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/algorithms/uninitialized_move.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/container_algorithms/copy.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/container_algorithms/for_each.hpp"
"${PROJECT_SOURCE_DIR}/hpx/parallel/container_algorithms/generate.hpp"
Expand Down
10 changes: 10 additions & 0 deletions docs/manual/parallel_algorithms.qbk
Expand Up @@ -468,6 +468,16 @@ __hpx__ provides implementations of the following parallel algorithms:
[`<hpx/include/parallel_uninitialized_fill.hpp>`]
[[cpprefmemdocs uninitialized_fill_n]]
]
[[ [algoref uninitialized_move] ]
[Copies a range of objects to an uninitialized area of memory.]
[`<hpx/include/parallel_uninitialized_move.hpp>`]
[[cpprefmemdocs uninitialized_move]]
]
[[ [algoref uninitialized_move_n] ]
[Copies a number of objects to an uninitialized area of memory.]
[`<hpx/include/parallel_uninitialized_move.hpp>`]
[[cpprefmemdocs uninitialized_move_n]]
]
]

[table Index-based for-loops (In Header: `<hpx/include/parallel_algorithm.hpp>`)
Expand Down
12 changes: 12 additions & 0 deletions hpx/include/parallel_uninitialized_move.hpp
@@ -0,0 +1,12 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(HPX_PARALLEL_UNINITIALIZED_MOVE_MAY_30_2017_0844AM)
#define HPX_PARALLEL_UNINITIALIZED_MOVE_MAY_30_2017_0844AM

#include <hpx/parallel/algorithms/uninitialized_move.hpp>

#endif

399 changes: 399 additions & 0 deletions hpx/parallel/algorithms/uninitialized_move.hpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion hpx/parallel/memory.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand All @@ -13,6 +13,7 @@

#include <hpx/parallel/algorithms/uninitialized_copy.hpp>
#include <hpx/parallel/algorithms/uninitialized_fill.hpp>
#include <hpx/parallel/algorithms/uninitialized_move.hpp>

#endif

10 changes: 6 additions & 4 deletions tests/unit/parallel/algorithms/CMakeLists.txt
Expand Up @@ -44,7 +44,6 @@ set(tests
foreach
foreach_executors
foreach_prefetching
foreach_prefetching_executors_v1
foreach_projection
foreachn
foreachn_exception
Expand All @@ -64,10 +63,8 @@ set(tests
generaten
includes
inclusive_scan
inclusive_scan_executors_v1
is_partitioned
is_sorted
is_sorted_executors_v1
is_sorted_until
lexicographical_compare
max_element
Expand Down Expand Up @@ -110,15 +107,20 @@ set(tests
transform_reduce_binary_exception
transform_reduce_binary_bad_alloc
uninitialized_copy
uninitialized_copy_executors_v1
uninitialized_copyn
uninitialized_fill
uninitialized_filln
uninitialized_move
uninitialized_moven
)

if(HPX_WITH_EXECUTOR_COMPATIBILITY)
set(tests ${tests}
foreach_executors_v1
foreach_prefetching_executors_v1
inclusive_scan_executors_v1
is_sorted_executors_v1
uninitialized_copy_executors_v1
)
endif()

Expand Down
164 changes: 164 additions & 0 deletions tests/unit/parallel/algorithms/uninitialized_move.cpp
@@ -0,0 +1,164 @@
// Copyright (c) 2014-2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/hpx_init.hpp>
#include <hpx/hpx.hpp>

#include <iostream>
#include <string>
#include <vector>

#include "uninitialized_move_tests.hpp"

////////////////////////////////////////////////////////////////////////////
template <typename IteratorTag>
void test_uninitialized_move()
{
using namespace hpx::parallel;
test_uninitialized_move(execution::seq, IteratorTag());
test_uninitialized_move(execution::par, IteratorTag());
test_uninitialized_move(execution::par_unseq, IteratorTag());

test_uninitialized_move_async(execution::seq(execution::task),
IteratorTag());
test_uninitialized_move_async(execution::par(execution::task),
IteratorTag());

#if defined(HPX_HAVE_GENERIC_EXECUTION_POLICY)
test_uninitialized_move(execution_policy(execution::seq), IteratorTag());
test_uninitialized_move(execution_policy(execution::par), IteratorTag());
test_uninitialized_move(execution_policy(execution::par_unseq),
IteratorTag());

test_uninitialized_move(execution_policy(execution::seq(execution::task)),
IteratorTag());
test_uninitialized_move(execution_policy(execution::par(execution::task)),
IteratorTag());
#endif
}

void uninitialized_move_test()
{
test_uninitialized_move<std::random_access_iterator_tag>();
test_uninitialized_move<std::forward_iterator_tag>();
test_uninitialized_move<std::input_iterator_tag>();
}

///////////////////////////////////////////////////////////////////////////////
template <typename IteratorTag>
void test_uninitialized_move_exception()
{
using namespace hpx::parallel;

// If the execution policy object is of type vector_execution_policy,
// std::terminate shall be called. therefore we do not test exceptions
// with a vector execution policy
test_uninitialized_move_exception(execution::seq, IteratorTag());
test_uninitialized_move_exception(execution::par, IteratorTag());

test_uninitialized_move_exception_async(execution::seq(execution::task),
IteratorTag());
test_uninitialized_move_exception_async(execution::par(execution::task),
IteratorTag());

#if defined(HPX_HAVE_GENERIC_EXECUTION_POLICY)
test_uninitialized_move_exception(execution_policy(execution::seq),
IteratorTag());
test_uninitialized_move_exception(execution_policy(execution::par),
IteratorTag());

test_uninitialized_move_exception(
execution_policy(execution::seq(execution::task)),
IteratorTag());
test_uninitialized_move_exception(
execution_policy(execution::par(execution::task)),
IteratorTag());
#endif
}

void uninitialized_move_exception_test()
{
test_uninitialized_move_exception<std::random_access_iterator_tag>();
test_uninitialized_move_exception<std::forward_iterator_tag>();
test_uninitialized_move_exception<std::input_iterator_tag>();
}

//////////////////////////////////////////////////////////////////////////////
template <typename IteratorTag>
void test_uninitialized_move_bad_alloc()
{
using namespace hpx::parallel;

// If the execution policy object is of type vector_execution_policy,
// std::terminate shall be called. therefore we do not test exceptions
// with a vector execution policy
test_uninitialized_move_bad_alloc(execution::seq, IteratorTag());
test_uninitialized_move_bad_alloc(execution::par, IteratorTag());

test_uninitialized_move_bad_alloc_async(execution::seq(execution::task),
IteratorTag());
test_uninitialized_move_bad_alloc_async(execution::par(execution::task),
IteratorTag());

#if defined(HPX_HAVE_GENERIC_EXECUTION_POLICY)
test_uninitialized_move_bad_alloc(execution_policy(execution::seq),
IteratorTag());
test_uninitialized_move_bad_alloc(execution_policy(execution::par),
IteratorTag());

test_uninitialized_move_bad_alloc(
execution_policy(execution::seq(execution::task)),
IteratorTag());
test_uninitialized_move_bad_alloc(
execution_policy(execution::par(execution::task)),
IteratorTag());
#endif
}

void uninitialized_move_bad_alloc_test()
{
test_uninitialized_move_bad_alloc<std::random_access_iterator_tag>();
test_uninitialized_move_bad_alloc<std::forward_iterator_tag>();
test_uninitialized_move_bad_alloc<std::input_iterator_tag>();
}

int hpx_main(boost::program_options::variables_map& vm)
{
unsigned int seed = (unsigned int)std::time(nullptr);
if (vm.count("seed"))
seed = vm["seed"].as<unsigned int>();

std::cout << "using seed: " << seed << std::endl;
std::srand(seed);

uninitialized_move_test();
uninitialized_move_exception_test();
uninitialized_move_bad_alloc_test();
return hpx::finalize();
}

int main(int argc, char* argv[])
{
// add command line option which controls the random number generator seed
using namespace boost::program_options;
options_description desc_commandline(
"Usage: " HPX_APPLICATION_STRING " [options]");

desc_commandline.add_options()
("seed,s", value<unsigned int>(),
"the random number generator seed to use for this run")
;

// By default this test should run on all available cores
std::vector<std::string> const cfg = {
"hpx.os_threads=all"
};

// Initialize and run HPX
HPX_TEST_EQ_MSG(hpx::init(desc_commandline, argc, argv, cfg), 0,
"HPX main exited with non-zero status");

return hpx::util::report_errors();
}

0 comments on commit d15ade8

Please sign in to comment.