job/dispatch: add index uniqueness test
This commit is contained in:
parent
e0f4fdc308
commit
4a73a3cea7
@ -586,6 +586,7 @@ if (TESTS)
|
||||
io
|
||||
introspection
|
||||
iterator
|
||||
job/dispatch
|
||||
job/queue
|
||||
kmeans
|
||||
maths
|
||||
|
@ -17,16 +17,16 @@
|
||||
#include <vector>
|
||||
|
||||
namespace cruft::job {
|
||||
// call a function across all elements of a container using the supplied
|
||||
// job queue.
|
||||
//
|
||||
// threads will have work sizes dictated by a supplied extent.
|
||||
//
|
||||
// returns a cookie that will block at destruction until all jobs have
|
||||
// completed. it will take ownership of an forwarding-reference function
|
||||
// if one is supplied.
|
||||
//
|
||||
// TODO: extend to 1d and 3d
|
||||
/// call a function across all elements of a container using the supplied
|
||||
/// job queue.
|
||||
///
|
||||
/// threads will have work sizes dictated by a supplied extent.
|
||||
///
|
||||
/// returns a cookie that will block at destruction until all jobs have
|
||||
/// completed. it will take ownership of an forwarding-reference function
|
||||
/// if one is supplied.
|
||||
///
|
||||
/// TODO: extend to 1d and 3d
|
||||
template <
|
||||
typename ContainerT,
|
||||
typename FunctionT,
|
||||
@ -48,7 +48,7 @@ namespace cruft::job {
|
||||
for (auto p: param) {
|
||||
if (!inner_data.extent ().exclusive (p))
|
||||
continue;
|
||||
inner_data[p][0] = std::invoke (func, p, inner_args...);
|
||||
inner_data[p] = std::invoke (func, p, inner_args...);
|
||||
}
|
||||
};
|
||||
|
||||
|
59
test/job/dispatch.cpp
Normal file
59
test/job/dispatch.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include <cruft/util/coord/comparator.hpp>
|
||||
#include <cruft/util/job/dispatch.hpp>
|
||||
#include <cruft/util/tap.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct value {
|
||||
template <typename T>
|
||||
void operator= (T &&) { }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
struct data_t {
|
||||
cruft::extent2i extent (void) const { return { 4, 4 }; }
|
||||
auto operator[] (cruft::point2i) { return value {};};
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void test_dispatch_uniqueness (cruft::TAP::logger &tap)
|
||||
{
|
||||
std::vector<cruft::point2i> points;
|
||||
data_t data;
|
||||
|
||||
cruft::job::queue q (1, 512 * 512 + 1);
|
||||
cruft::job::dispatch (
|
||||
q, data,
|
||||
cruft::extent2i {2},
|
||||
[&] (cruft::point2i p)
|
||||
{
|
||||
points.push_back (p);
|
||||
return 0;
|
||||
});
|
||||
|
||||
cruft::coord::ordering<cruft::point2i> comp {};
|
||||
std::sort (points.begin (), points.end (), comp);
|
||||
auto const pos = std::adjacent_find (points.begin (), points.end ());
|
||||
tap.expect (pos == points.end (), "job::queue indices are unique");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
int main ()
|
||||
{
|
||||
cruft::TAP::logger tap;
|
||||
test_dispatch_uniqueness (tap);
|
||||
return tap.status ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user