Skip to content

Commit

Permalink
fix modulo zero
Browse files Browse the repository at this point in the history
Modulo zero is not allowed and results into an arithmetic error.
  • Loading branch information
psychocoderHPC committed Dec 12, 2023
1 parent 7f2c3e4 commit d28f1e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion redGrapes/memory/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Allocator::Allocator()

Allocator::Allocator( dispatch::thread::WorkerId worker_id )
: worker_id(
worker_id % SingletonContext::get().n_workers
worker_id % SingletonContext::get().get_num_workers()
)
{}

Expand Down
5 changes: 5 additions & 0 deletions redGrapes/redGrapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Context::~Context()

}

uint32_t Context::get_num_workers() const
{
return n_workers == 0 ? 1 : n_workers;
}

std::shared_ptr<TaskSpace> Context::current_task_space() const
{
if( current_task )
Expand Down
6 changes: 5 additions & 1 deletion redGrapes/redGrapes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct Context

void execute_task( Task & task );

uint32_t get_num_workers() const;

/*! create a new task, as child of the currently running task (if there is one)
*
* @param f callable that takes "proprty-building" objects as args
Expand All @@ -83,7 +85,6 @@ struct Context
static thread_local scheduler::WakerId current_waker_id;
static thread_local std::shared_ptr< dispatch::thread::WorkerThread > current_worker;

unsigned n_workers;
static thread_local unsigned current_arena;
HwlocContext hwloc_ctx;
std::shared_ptr< dispatch::thread::WorkerPool > worker_pool;
Expand All @@ -94,6 +95,9 @@ struct Context
#if REDGRAPES_ENABLE_TRACE
std::shared_ptr< perfetto::TracingSession > tracing_session;
#endif

private:
unsigned n_workers;
};


Expand Down

0 comments on commit d28f1e9

Please sign in to comment.