From de96be4f10c46c8fd2278de58229b56592d8f09f Mon Sep 17 00:00:00 2001 From: Tapish Date: Thu, 23 May 2024 10:57:06 +0200 Subject: [PATCH 1/3] Construct task with worker_id --- redGrapes/redGrapes.hpp | 4 +--- redGrapes/task/task.hpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/redGrapes/redGrapes.hpp b/redGrapes/redGrapes.hpp index c29bd51b..6ccaed88 100644 --- a/redGrapes/redGrapes.hpp +++ b/redGrapes/redGrapes.hpp @@ -157,9 +157,7 @@ namespace redGrapes throw std::bad_alloc(); // construct task in-place - new(task) FunTask(*scheduler_map[TSchedTag{}]); - - task->worker_id = worker_id; + new(task) FunTask(worker_id, *scheduler_map[TSchedTag{}]); return std::move(TaskBuilder(task, std::move(f), std::forward(args)...)); } diff --git a/redGrapes/task/task.hpp b/redGrapes/task/task.hpp index 6a45bb83..f9dad60b 100644 --- a/redGrapes/task/task.hpp +++ b/redGrapes/task/task.hpp @@ -6,6 +6,7 @@ */ #pragma once +#include "redGrapes/TaskFreeCtx.hpp" #include "redGrapes/task/property/graph.hpp" #include "redGrapes/task/property/id.hpp" #include "redGrapes/task/property/inherit.hpp" @@ -47,8 +48,9 @@ namespace redGrapes std::atomic removal_countdown; scheduler::IScheduler>* scheduler_p; - Task(scheduler::IScheduler>& scheduler) - : removal_countdown(2) + Task(WorkerId worker_id, scheduler::IScheduler>& scheduler) + : worker_id(worker_id) + , removal_countdown(2) , scheduler_p(&scheduler) { } @@ -67,7 +69,7 @@ namespace redGrapes { Result result_data; - ResultTask(scheduler::IScheduler& scheduler) : TTask(scheduler) + ResultTask(WorkerId worker_id, scheduler::IScheduler& scheduler) : TTask(worker_id, scheduler) { } @@ -92,7 +94,7 @@ namespace redGrapes template struct ResultTask : TTask { - ResultTask(scheduler::IScheduler& scheduler) : TTask(scheduler) + ResultTask(WorkerId worker_id, scheduler::IScheduler& scheduler) : TTask(worker_id, scheduler) { } @@ -114,8 +116,8 @@ namespace redGrapes template struct FunTask : ResultTask, TTask> { - FunTask(scheduler::IScheduler& scheduler) - : ResultTask, TTask>(scheduler) + FunTask(WorkerId worker_id, scheduler::IScheduler& scheduler) + : ResultTask, TTask>(worker_id, scheduler) { } From 6a4d4effe0f4f27a8a60412394031d782ebdb97d Mon Sep 17 00:00:00 2001 From: Tapish Date: Thu, 30 May 2024 14:04:23 +0200 Subject: [PATCH 2/3] Onlly allocate using alloc_bind and pass worker id to all task properties --- examples/1_resources.cpp | 7 +-- redGrapes/TaskFreeCtx.hpp | 7 +++ redGrapes/dispatch/mpi/request_pool.hpp | 3 +- redGrapes/redGrapes.hpp | 6 +-- redGrapes/resource/fieldresource.hpp | 34 +++++++++--- redGrapes/resource/ioresource.hpp | 26 ++++++--- redGrapes/resource/resource.hpp | 71 ++++++++++++++++--------- redGrapes/resource/resource_user.hpp | 14 +++-- redGrapes/resource/resource_user.tpp | 20 +++---- redGrapes/scheduler/event.hpp | 7 +-- redGrapes/scheduler/event.tpp | 18 +++---- redGrapes/task/property/graph.hpp | 9 ++++ redGrapes/task/property/graph.tpp | 3 +- redGrapes/task/property/id.hpp | 10 ++-- redGrapes/task/property/inherit.hpp | 13 +++++ redGrapes/task/property/label.hpp | 13 +++-- redGrapes/task/property/resource.hpp | 9 +++- redGrapes/task/task.hpp | 5 +- test/resource.cpp | 3 +- test/resource_user.cpp | 12 ++--- 20 files changed, 197 insertions(+), 93 deletions(-) diff --git a/examples/1_resources.cpp b/examples/1_resources.cpp index b3303a29..b7527f54 100644 --- a/examples/1_resources.cpp +++ b/examples/1_resources.cpp @@ -21,11 +21,12 @@ int main(int, char*[]) redGrapes::ResourceUser user1( {a.read(), // complete resource a.write().area({0}, {10}), // write only indices 0 to 10 - b.write()}); + b.write()}, + 0); - redGrapes::ResourceUser user2({b.read()}); + redGrapes::ResourceUser user2({b.read()}, 0); - redGrapes::ResourceUser user3({b.read(), c.write()}); + redGrapes::ResourceUser user3({b.read(), c.write()}, 0); std::cout << "is_serial(user1,user1) = " << is_serial(user1, user1) << std::endl; std::cout << "is_serial(user1,user2) = " << is_serial(user1, user2) << std::endl; diff --git a/redGrapes/TaskFreeCtx.hpp b/redGrapes/TaskFreeCtx.hpp index 251a16ec..73d4cb4b 100644 --- a/redGrapes/TaskFreeCtx.hpp +++ b/redGrapes/TaskFreeCtx.hpp @@ -20,6 +20,7 @@ namespace redGrapes { using WorkerId = uint8_t; + using ResourceId = uint16_t; /** WorkerID of parser to wake it up * ID 0,1,2... are used for worker threads @@ -50,6 +51,12 @@ namespace redGrapes static inline WorkerAllocPool worker_alloc_pool; static inline CondVar cv{0}; + static inline ResourceId create_resource_uid() + { + static std::atomic id = 0; + return id++; + } + static inline std::function idle = [] { SPDLOG_TRACE("Parser::idle()"); diff --git a/redGrapes/dispatch/mpi/request_pool.hpp b/redGrapes/dispatch/mpi/request_pool.hpp index b11792bd..552a69e2 100644 --- a/redGrapes/dispatch/mpi/request_pool.hpp +++ b/redGrapes/dispatch/mpi/request_pool.hpp @@ -77,12 +77,13 @@ namespace redGrapes * yields until the request is done. While waiting * for this request, other tasks will be executed. * + * Must be called inside a running task * @param request The MPI request to wait for * @return the resulting MPI status of the request */ MPI_Status get_status(MPI_Request request) { - auto status = memory::alloc_shared(); + auto status = memory::alloc_shared_bind((*TaskCtx::current_task)->worker_id); auto event = *TaskCtx::create_event(); // SPDLOG_TRACE("MPI RequestPool: status event = {}", (void*)event.get()); diff --git a/redGrapes/redGrapes.hpp b/redGrapes/redGrapes.hpp index 6ccaed88..4830f284 100644 --- a/redGrapes/redGrapes.hpp +++ b/redGrapes/redGrapes.hpp @@ -188,7 +188,7 @@ namespace redGrapes template auto createFieldResource(Args&&... args) -> FieldResource { - return FieldResource(args...); + return FieldResource(std::forward(args)...); } template @@ -200,13 +200,13 @@ namespace redGrapes template auto createIOResource(Args&&... args) -> IOResource { - return IOResource(args...); + return IOResource(std::forward(args)...); } template auto createResource() -> Resource { - return Resource(); + return Resource(TaskFreeCtx::create_resource_uid()); } private: diff --git a/redGrapes/resource/fieldresource.hpp b/redGrapes/resource/fieldresource.hpp index 45e2598a..6403c2ef 100644 --- a/redGrapes/resource/fieldresource.hpp +++ b/redGrapes/resource/fieldresource.hpp @@ -11,6 +11,7 @@ #pragma once +#include "redGrapes/TaskFreeCtx.hpp" #include "redGrapes/resource/access/field.hpp" #include "redGrapes/resource/resource.hpp" @@ -89,8 +90,14 @@ namespace redGrapes } protected: - AreaGuard(std::shared_ptr obj) - : SharedResourceObject>(obj) + AreaGuard(ResourceId id, std::shared_ptr const& obj) + : SharedResourceObject>(id, obj) + { + } + + template + AreaGuard(ResourceId id, Args&&... args) + : SharedResourceObject>(id, std::forward(args)...) { } @@ -168,7 +175,12 @@ namespace redGrapes { } - ReadGuard(std::shared_ptr obj) : AreaGuard(obj) + ReadGuard(ResourceId id, std::shared_ptr const& obj) : AreaGuard(id, obj) + { + } + + template + ReadGuard(ResourceId id, Args&&... args) : AreaGuard(id, std::forward(args)...) { } }; @@ -219,7 +231,12 @@ namespace redGrapes { } - WriteGuard(std::shared_ptr obj) : ReadGuard(obj) + WriteGuard(ResourceId id, std::shared_ptr const& obj) : ReadGuard(id, obj) + { + } + + template + WriteGuard(ResourceId id, Args&&... args) : ReadGuard(id, std::forward(args)...) { } }; @@ -231,13 +248,18 @@ namespace redGrapes { static constexpr size_t dim = trait::Field::dim; - FieldResource(Container* c) : fieldresource::WriteGuard(std::shared_ptr(c)) + FieldResource(Container* c) + : fieldresource::WriteGuard( + TaskFreeCtx::create_resource_uid(), + std::shared_ptr(c)) { } template FieldResource(Args&&... args) - : fieldresource::WriteGuard(memory::alloc_shared(std::forward(args)...)) + : fieldresource::WriteGuard( + TaskFreeCtx::create_resource_uid(), + std::forward(args)...) { } }; diff --git a/redGrapes/resource/ioresource.hpp b/redGrapes/resource/ioresource.hpp index d1371b1f..5f809094 100644 --- a/redGrapes/resource/ioresource.hpp +++ b/redGrapes/resource/ioresource.hpp @@ -11,6 +11,7 @@ #pragma once +#include "redGrapes/TaskFreeCtx.hpp" #include "redGrapes/resource/access/io.hpp" #include "redGrapes/resource/resource.hpp" @@ -48,7 +49,14 @@ namespace redGrapes } protected: - ReadGuard(std::shared_ptr obj) : SharedResourceObject(obj) + ReadGuard(ResourceId id, std::shared_ptr const& obj) + : SharedResourceObject(id, obj) + { + } + + template + ReadGuard(ResourceId id, Args&&... args) + : SharedResourceObject(id, std::forward(args)...) { } }; @@ -82,7 +90,12 @@ namespace redGrapes } protected: - WriteGuard(std::shared_ptr obj) : ReadGuard(obj) + WriteGuard(ResourceId id, std::shared_ptr const& obj) : ReadGuard(id, obj) + { + } + + template + WriteGuard(ResourceId id, Args&&... args) : ReadGuard(id, std::forward(args)...) { } }; @@ -92,13 +105,14 @@ namespace redGrapes template struct IOResource : public ioresource::WriteGuard { - template - IOResource(Args&&... args) - : ioresource::WriteGuard(memory::alloc_shared(std::forward(args)...)) + IOResource(std::shared_ptr const& o) + : ioresource::WriteGuard(TaskFreeCtx::create_resource_uid(), o) { } - IOResource(std::shared_ptr o) : ioresource::WriteGuard(o) + template + IOResource(Args&&... args) + : ioresource::WriteGuard(TaskFreeCtx::create_resource_uid(), std::forward(args)...) { } diff --git a/redGrapes/resource/resource.hpp b/redGrapes/resource/resource.hpp index 3ed1c26b..ce5ef1ba 100644 --- a/redGrapes/resource/resource.hpp +++ b/redGrapes/resource/resource.hpp @@ -34,7 +34,30 @@ namespace redGrapes { - using ResourceID = uint16_t; + namespace mapping + { + template + struct MapResourceIdToWorker + { + MappingFunc mappingFunc; + + WorkerId operator()(ResourceId resourceId) + { + return mappingFunc(resourceId); + } + }; + + struct ModuloMapping + { + WorkerId operator()(ResourceId resourceId) + { + return resourceId % TaskFreeCtx::n_workers; + } + }; + + static MapResourceIdToWorker map_resource_to_worker{}; + + } // namespace mapping template class Resource; @@ -42,33 +65,21 @@ namespace redGrapes template class ResourceBase { - protected: - static ResourceID generateID() - { - static std::atomic id_counter; - return id_counter.fetch_add(1); - } - public: ChunkedList users; SpinLock users_mutex; - ResourceID id; + ResourceId id; uint8_t scope_level; /** * Create a new resource with an unused ID. */ - ResourceBase() - : users(memory::Allocator(get_arena_id())) - , id(generateID()) + ResourceBase(ResourceId id) + : users(memory::Allocator(mapping::map_resource_to_worker(id))) + , id(id) , scope_level(TaskCtx::scope_depth()) { } - - WorkerId get_arena_id() const - { - return id % TaskFreeCtx::n_workers; - } }; template @@ -159,7 +170,7 @@ namespace redGrapes return this->obj->resource->scope_level; } - ResourceID resource_id() const + ResourceId resource_id() const { return this->obj->resource->id; } @@ -321,12 +332,10 @@ namespace redGrapes } public: - Resource() - { - static ResourceID i = 0; + Resource(ResourceId id) + : base{redGrapes::memory::alloc_shared_bind>(mapping::map_resource_to_worker(id), id)} - i = i++ % TaskFreeCtx::n_workers; - base = redGrapes::memory::alloc_shared_bind>(i); + { } /** @@ -338,7 +347,8 @@ namespace redGrapes */ ResourceAccess make_access(AccessPolicy pol) const { - auto a = redGrapes::memory::alloc_shared_bind(base->get_arena_id(), base, pol); + auto a + = redGrapes::memory::alloc_shared_bind(mapping::map_resource_to_worker(base->id), base, pol); return ResourceAccess(a); } }; // class Resource @@ -349,11 +359,20 @@ namespace redGrapes // protected: std::shared_ptr obj; - SharedResourceObject(std::shared_ptr obj) : obj(obj) + SharedResourceObject(ResourceId id, std::shared_ptr obj) : Resource(id), obj(obj) + { + } + + SharedResourceObject(ResourceId id, SharedResourceObject const& other) + : Resource(id) + , obj(other.obj) { } - SharedResourceObject(SharedResourceObject const& other) : Resource(other), obj(other.obj) + template + SharedResourceObject(ResourceId id, Args&&... args) + : Resource(id) + , obj{memory::alloc_shared_bind(mapping::map_resource_to_worker(id), std::forward(args)...)} { } }; // struct SharedResourceObject diff --git a/redGrapes/resource/resource_user.hpp b/redGrapes/resource/resource_user.hpp index 5ac9d295..05a6fee9 100644 --- a/redGrapes/resource/resource_user.hpp +++ b/redGrapes/resource/resource_user.hpp @@ -42,9 +42,17 @@ namespace redGrapes template struct ResourceUser { - ResourceUser(); - ResourceUser(ResourceUser const& other); - ResourceUser(std::initializer_list> list); + ResourceUser(WorkerId worker_id); + ResourceUser(ResourceUser const& other) = delete; + + ResourceUser(ResourceUser const& other, WorkerId worker_id) + : access_list(memory::Allocator(worker_id), other.access_list) + , unique_resources(memory::Allocator(worker_id), other.unique_resources) + , scope_level(other.scope_level) + { + } + + ResourceUser(std::initializer_list> list, WorkerId worker_id); void add_resource_access(ResourceAccess ra); void rm_resource_access(ResourceAccess ra); diff --git a/redGrapes/resource/resource_user.tpp b/redGrapes/resource/resource_user.tpp index a893ae4d..515f8683 100644 --- a/redGrapes/resource/resource_user.tpp +++ b/redGrapes/resource/resource_user.tpp @@ -21,25 +21,17 @@ namespace redGrapes } template - ResourceUser::ResourceUser() - : access_list(memory::Allocator()) - , unique_resources(memory::Allocator()) + ResourceUser::ResourceUser(WorkerId worker_id) + : access_list(memory::Allocator(worker_id)) + , unique_resources(memory::Allocator(worker_id)) , scope_level(TaskCtx::scope_depth()) { } template - ResourceUser::ResourceUser(ResourceUser const& other) - : access_list(memory::Allocator(), other.access_list) - , unique_resources(memory::Allocator(), other.unique_resources) - , scope_level(other.scope_level) - { - } - - template - ResourceUser::ResourceUser(std::initializer_list> list) - : access_list(memory::Allocator()) - , unique_resources(memory::Allocator()) + ResourceUser::ResourceUser(std::initializer_list> list, WorkerId worker_id) + : access_list(memory::Allocator(worker_id)) + , unique_resources(memory::Allocator(worker_id)) , scope_level(TaskCtx::scope_depth()) { for(auto& ra : list) diff --git a/redGrapes/scheduler/event.hpp b/redGrapes/scheduler/event.hpp index ee883375..25d16531 100644 --- a/redGrapes/scheduler/event.hpp +++ b/redGrapes/scheduler/event.hpp @@ -7,6 +7,7 @@ #pragma once +#include "redGrapes/TaskFreeCtx.hpp" #include "redGrapes/scheduler/scheduler.hpp" #include "redGrapes/util/chunked_list.hpp" @@ -95,9 +96,9 @@ namespace redGrapes WakerId waker_id; - Event(); - Event(Event&); - Event(Event&&); + Event(WorkerId worker_id); + Event(WorkerId worker_id, Event&); + Event(WorkerId worker_id, Event&&); bool is_reached(); bool is_ready(); diff --git a/redGrapes/scheduler/event.tpp b/redGrapes/scheduler/event.tpp index 5c6b4076..4f44a279 100644 --- a/redGrapes/scheduler/event.tpp +++ b/redGrapes/scheduler/event.tpp @@ -20,25 +20,25 @@ namespace redGrapes namespace scheduler { template - Event::Event() : followers(memory::Allocator()) - , waker_id(-1) - , state(1) + Event::Event(WorkerId worker_id) : followers(memory::Allocator(worker_id)) + , state(1) + , waker_id(-1) { } template - Event::Event(Event& other) - : followers(memory::Allocator()) - , waker_id(other.waker_id) + Event::Event(WorkerId worker_id, Event& other) + : followers(memory::Allocator(worker_id)) , state((uint16_t) other.state) + , waker_id(other.waker_id) { } template - Event::Event(Event&& other) - : state((uint16_t) other.state) + Event::Event(WorkerId worker_id, Event&& other) + : followers(memory::Allocator(worker_id)) + , state((uint16_t) other.state) , waker_id(other.waker_id) - , followers(memory::Allocator()) { } diff --git a/redGrapes/task/property/graph.hpp b/redGrapes/task/property/graph.hpp index a32a1f41..03b748ec 100644 --- a/redGrapes/task/property/graph.hpp +++ b/redGrapes/task/property/graph.hpp @@ -7,6 +7,7 @@ #pragma once +#include "redGrapes/TaskFreeCtx.hpp" #include "redGrapes/scheduler/event.hpp" #include @@ -42,6 +43,14 @@ namespace redGrapes template struct GraphProperty { + GraphProperty(WorkerId worker_id) + : pre_event{worker_id} + , post_event{worker_id} + , result_set_event{worker_id} + , result_get_event{worker_id} + { + } + TTask& operator*() { return *task; diff --git a/redGrapes/task/property/graph.tpp b/redGrapes/task/property/graph.tpp index a348beca..b1caa0ca 100644 --- a/redGrapes/task/property/graph.tpp +++ b/redGrapes/task/property/graph.tpp @@ -20,7 +20,8 @@ namespace redGrapes template scheduler::EventPtr GraphProperty::make_event() { - auto event = memory::alloc_shared>(); + // create event on task->worker_id and pass it as arg also so event can create follower list on same worker + auto event = memory::alloc_shared_bind>(task->worker_id, task->worker_id); event->add_follower(get_post_event()); return scheduler::EventPtr{event, task, scheduler::T_EVT_EXT}; } diff --git a/redGrapes/task/property/id.hpp b/redGrapes/task/property/id.hpp index 09d23581..e38e5890 100644 --- a/redGrapes/task/property/id.hpp +++ b/redGrapes/task/property/id.hpp @@ -11,6 +11,8 @@ #pragma once +#include "redGrapes/TaskFreeCtx.hpp" + #include #include @@ -32,15 +34,15 @@ namespace redGrapes public: TaskID task_id; - IDProperty() : task_id(-1) // id_counter().fetch_add( 1, std::memory_order_seq_cst ) ) + IDProperty(WorkerId) : task_id(-1) // id_counter().fetch_add( 1, std::memory_order_seq_cst ) ) { } - IDProperty(IDProperty&& other) : task_id(other.task_id) + IDProperty(WorkerId, IDProperty&& other) : task_id(other.task_id) { } - IDProperty(IDProperty const& other) : task_id(other.task_id) + IDProperty(WorkerId, IDProperty const& other) : task_id(other.task_id) { } @@ -75,7 +77,7 @@ namespace redGrapes }; }; - void apply_patch(Patch const&){}; + void apply_patch(Patch const&) {}; }; } // namespace redGrapes diff --git a/redGrapes/task/property/inherit.hpp b/redGrapes/task/property/inherit.hpp index 8962bf87..2cb589e3 100644 --- a/redGrapes/task/property/inherit.hpp +++ b/redGrapes/task/property/inherit.hpp @@ -11,6 +11,7 @@ #pragma once +#include "redGrapes/TaskFreeCtx.hpp" #include "redGrapes/task/property/trait.hpp" #include @@ -24,6 +25,10 @@ namespace redGrapes : T_Head , TaskPropertiesInherit { + TaskPropertiesInherit(WorkerId worker_id) : TaskPropertiesInherit(worker_id), T_Head(worker_id) + { + } + template struct Builder : T_Head::template Builder @@ -65,6 +70,10 @@ namespace redGrapes template<> struct TaskPropertiesInherit { + TaskPropertiesInherit(WorkerId) + { + } + template struct Builder { @@ -92,6 +101,10 @@ namespace redGrapes template struct TaskProperties1 : public TaskPropertiesInherit { + TaskProperties1(WorkerId worker_id) : TaskPropertiesInherit(worker_id) + { + } + template struct Builder : TaskPropertiesInherit::template Builder { diff --git a/redGrapes/task/property/label.hpp b/redGrapes/task/property/label.hpp index 18465716..7c88ea76 100644 --- a/redGrapes/task/property/label.hpp +++ b/redGrapes/task/property/label.hpp @@ -11,7 +11,7 @@ #pragma once -#include "redGrapes/memory/allocator.hpp" +#include "redGrapes/TaskFreeCtx.hpp" #include @@ -22,9 +22,14 @@ namespace redGrapes struct LabelProperty { - using string = std::basic_string, memory::StdAllocator>; + // TODO Optimization, use the workerId to allocate the label string seperate from the task + // using string = std::basic_string, memory::StdAllocator>; - string label; + LabelProperty(WorkerId) + { + } + + std::string label; template struct Builder @@ -35,7 +40,7 @@ namespace redGrapes { } - TaskBuilder& label(string const& l) + TaskBuilder& label(std::string const& l) { builder.task->label = l; return builder; diff --git a/redGrapes/task/property/resource.hpp b/redGrapes/task/property/resource.hpp index f70c22c4..e772cb23 100644 --- a/redGrapes/task/property/resource.hpp +++ b/redGrapes/task/property/resource.hpp @@ -11,6 +11,8 @@ #pragma once +#include "redGrapes/TaskCtx.hpp" +#include "redGrapes/TaskFreeCtx.hpp" #include "redGrapes/resource/resource_user.hpp" #include @@ -25,6 +27,10 @@ namespace redGrapes template struct ResourceProperty : ResourceUser { + ResourceProperty(WorkerId worker_id) : ResourceUser(worker_id) + { + } + template struct Builder { @@ -112,9 +118,10 @@ namespace redGrapes this->rm_resource_access(ra); } + // Only to be called inside a running task to update property void apply_patch(Patch const& patch) { - ResourceUser before(*this); + ResourceUser before(*this, (*TaskCtx::current_task)->worker_id); for(auto x : patch.diff) { diff --git a/redGrapes/task/task.hpp b/redGrapes/task/task.hpp index f9dad60b..e53f858c 100644 --- a/redGrapes/task/task.hpp +++ b/redGrapes/task/task.hpp @@ -48,8 +48,9 @@ namespace redGrapes std::atomic removal_countdown; scheduler::IScheduler>* scheduler_p; - Task(WorkerId worker_id, scheduler::IScheduler>& scheduler) - : worker_id(worker_id) + Task(WorkerId _worker_id, scheduler::IScheduler>& scheduler) + : TaskProperties(_worker_id) + , worker_id(_worker_id) , removal_countdown(2) , scheduler_p(&scheduler) { diff --git a/test/resource.cpp b/test/resource.cpp index 1d933d46..142c2f53 100644 --- a/test/resource.cpp +++ b/test/resource.cpp @@ -46,7 +46,8 @@ TEST_CASE("Resource ID") { auto rg = redGrapes::init(1); using RGTask = decltype(rg)::RGTask; - redGrapes::Resource a, b; + auto a = rg.createResource(); + auto b = rg.createResource(); // same resource REQUIRE(redGrapes::ResourceAccess::is_serial(a.make_access(Access{}), a.make_access(Access{})) == true); diff --git a/test/resource_user.cpp b/test/resource_user.cpp index 4546b907..acd37b46 100644 --- a/test/resource_user.cpp +++ b/test/resource_user.cpp @@ -7,16 +7,16 @@ TEST_CASE("Resource User") { - auto rg = redGrapes::init(); + auto rg = redGrapes::init(1); using RGTask = decltype(rg)::RGTask; redGrapes::IOResource a, b; - redGrapes::ResourceUser f1({a.read()}); - redGrapes::ResourceUser f2({a.read(), a.write()}); - redGrapes::ResourceUser f3({b.read()}); - redGrapes::ResourceUser f4({b.read(), b.write()}); - redGrapes::ResourceUser f5({a.read(), a.write(), b.read(), b.write()}); + redGrapes::ResourceUser f1({a.read()}, 0); + redGrapes::ResourceUser f2({a.read(), a.write()}, 0); + redGrapes::ResourceUser f3({b.read()}, 0); + redGrapes::ResourceUser f4({b.read(), b.write()}, 0); + redGrapes::ResourceUser f5({a.read(), a.write(), b.read(), b.write()}, 0); REQUIRE(is_serial(f1, f1) == false); REQUIRE(is_serial(f1, f2) == true); From 1932002ed239fff0e7cfd051b4a3ab90ebac0a22 Mon Sep 17 00:00:00 2001 From: Tapish Date: Thu, 30 May 2024 14:17:00 +0200 Subject: [PATCH 3/3] Fix reordering --- redGrapes/task/future.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redGrapes/task/future.hpp b/redGrapes/task/future.hpp index d57f0162..63f6a123 100644 --- a/redGrapes/task/future.hpp +++ b/redGrapes/task/future.hpp @@ -76,11 +76,11 @@ namespace redGrapes template struct Future { - Future(TTask& task) : task(task), taken(false) + Future(TTask& task) : taken(false), task(task) { } - Future(Future&& other) : task(other.task), taken(other.taken) + Future(Future&& other) : taken(other.taken), task(other.task) { SPDLOG_TRACE("MOVE future"); other.taken = true;