8#ifndef SRC_PARTICLECONTAINER_LINKEDCELLTRAVERSALS_QUICKSCHEDTRAVERSAL_H
9#define SRC_PARTICLECONTAINER_LINKEDCELLTRAVERSALS_QUICKSCHEDTRAVERSAL_H
11#include "C08BasedTraversals.h"
12#include "utils/Logger.h"
13#include "Simulation.h"
14#include "particleContainer/LinkedCells.h"
17#include "quicksched.h"
23 std::array<unsigned long, 3> taskBlockSize;
26template<
class CellTemplate>
30 const std::array<unsigned long, 3> &dims,
31 const std::array<unsigned long, 3> &taskBlockSize);
36 virtual void rebuild(std::vector<CellTemplate> &cells,
37 const std::array<unsigned long, 3> &dims,
double cellLength[3],
double cutoff,
44 void traverseCellPairsInner(
CellProcessor &cellProcessor,
unsigned stage,
unsigned stageCount);
53 static void runner(
int type,
void *data);
55 array<unsigned long, 3> _taskBlocksize;
58 struct qsched *_scheduler;
59 taskType _taskTypeSelector;
62template<
class CellTemplate>
64 const std::array<unsigned long, 3> &dims,
65 const std::array<unsigned long, 3> &taskBlockSize)
68 _taskBlocksize(taskBlockSize),
69 _contextCellProcessor(
nullptr),
70 _scheduler(
new struct qsched),
71 _taskTypeSelector(PackedAdjustable) {
72 mardyn_assert((is_base_of<ParticleCellBase, CellTemplate>::value));
73 qsched_init(_scheduler, mardyn_get_max_threads(), qsched_flag_none);
80template<
class CellTemplate>
82 const std::array<unsigned long, 3> &dims,
double cellLength[3],
double cutoff,
87 qsched_reset(_scheduler);
88 _taskBlocksize = qui_data->taskBlockSize;
91 global_log->error() <<
"QuickschedTraversal::rebuild was called with incompatible Traversal data!" << endl;
96template<
class CellTemplate>
99 qsched_res_t resourceId;
100 qsched_task_t taskId;
101 unsigned long cellIndex;
105 vector<ParticleCell> m_cells = *((vector<ParticleCell> *)(this->_cells));
107 switch (_taskTypeSelector) {
108 case PackedAdjustable: {
110 for (
int i = 0; i < 3; ++i) {
111 if (_taskBlocksize[i] > this->_dims[i]) {
112 global_log->error() <<
"Blocksize is bigger than number of cells in dimension "
113 << (char) (
'x' + i) <<
". (" << _taskBlocksize[i] <<
" > "
114 << this->_dims[i] <<
")" << std::endl;
119 global_log->info() <<
"Generating resource and task ids" << std::endl;
120 for (
unsigned long z = 0; z < this->_dims[2]; ++z) {
121 for (
unsigned long y = 0; y < this->_dims[1]; ++y) {
122 for (
unsigned long x = 0; x < this->_dims[0]; ++x) {
123 cellIndex = threeDimensionalMapping::threeToOneD(x, y, z, this->_dims);
124 resourceId = qsched_addres(_scheduler, qsched_owner_none, qsched_res_none);
125 m_cells[cellIndex].setResourceId(resourceId);
129 if ((z % (_taskBlocksize[2] - 1) == 0
130 && y % (_taskBlocksize[1] - 1) == 0
131 && x % (_taskBlocksize[0] - 1) == 0)
133 (x < this->_dims[0] - 1
134 && y < this->_dims[1] - 1
135 && z < this->_dims[2] - 1)) {
137 unsigned long payload[]{x, y, z, (
unsigned long)
this};
138 taskId = qsched_addtask(_scheduler,
144 m_cells[cellIndex].setTaskId(taskId);
151 global_log->info() <<
"Setting task dependencies" << std::endl;
152 for (
unsigned long z = 0; z < this->_dims[2] - 1; z += _taskBlocksize[2] - 1) {
153 for (
unsigned long y = 0; y < this->_dims[1] - 1; y += _taskBlocksize[1] - 1) {
154 for (
unsigned long x = 0; x < this->_dims[0] - 1; x += _taskBlocksize[0] - 1) {
155 cellIndex = threeDimensionalMapping::threeToOneD(x, y, z, this->_dims);
158 for (
unsigned long i = 0; i < _taskBlocksize[0]
159 && x + i < this->_dims[0]; i += _taskBlocksize[0] - 1) {
160 for (
unsigned long j = 0; j < _taskBlocksize[1]
161 && y + j < this->_dims[1]; j += _taskBlocksize[1] - 1) {
162 for (
unsigned long k = 0; k < _taskBlocksize[2]
163 && z + k < this->_dims[2]; k += _taskBlocksize[2] - 1) {
164 qsched_addlock(_scheduler,
165 m_cells[cellIndex].getTaskId(),
166 m_cells[threeDimensionalMapping::threeToOneD(x + i,
169 this->_dims)].getRescourceId());
179 global_log->error() <<
"QuickschedHandler::init() received non existing task type!"
185template<
class CellTemplate>
188 qsched_free(_scheduler);
193template<
class CellTemplate>
198#ifdef PRINT_SCHEDULING_TIMINGS
199 struct VectorizedCellProcessor::Timings timing ;
200 if(_simulation.getSimStep() > 10){
201 timing.start = _rdtsc();
205 case PackedAdjustable: {
207 unsigned long x = ((
unsigned long *) data)[0];
208 unsigned long y = ((
unsigned long *) data)[1];
209 unsigned long z = ((
unsigned long *) data)[2];
212 for (
unsigned long i = 0; i < context->_taskBlocksize[0] - 1
213 && i < context->_dims[0] - 1; ++i) {
214 for (
unsigned long j = 0; j < context->_taskBlocksize[1] - 1
215 && j < context->_dims[1] - 1; ++j) {
216 for (
unsigned long k = 0; k < context->_taskBlocksize[2] - 1
217 && k < context->_dims[2] - 1; ++k) {
220 unsigned long baseIndex = threeDimensionalMapping::threeToOneD(x + i,
224 context->processBaseCell(
225 *(context->_contextCellProcessor),
233 global_log->error() <<
"Undefined Quicksched task type: " <<
type << std::endl;
235#ifdef PRINT_SCHEDULING_TIMINGS
236 if(_simulation.getSimStep() > 10){
237 timing.end = _rdtsc();
238 (
dynamic_cast<VectorizedCellProcessor*
>(_contextCellProcessor))->getThreadData()[omp_get_thread_num()]->_timings.push_back(timing);
244template<
class CellTemplate>
246 _contextCellProcessor = &cellProcessor;
248 qsched_run(_scheduler, mardyn_get_max_threads(), runner);
252template<
class CellTemplate>
254 unsigned stageCount) {
255 global_log->error() <<
"QuickschedTraversal::traverseCellPairsInner is not implemented!" << std::endl;
258template<
class CellTemplate>
260 global_log->error() <<
"QuickschedTraversal::traverseCellPairsOuter is not implemented!" << std::endl;
Definition: C08BasedTraversals.h:17
virtual void rebuild(std::vector< CellTemplate > &cells, const std::array< unsigned long, 3 > &dims, double cellLength[3], double cutoff, CellPairTraversalData *data)
Definition: CellPairTraversals.h:32
Definition: CellProcessor.h:29
Definition: QuickschedTraversal.h:27
virtual void rebuild(std::vector< CellTemplate > &cells, const std::array< unsigned long, 3 > &dims, double cellLength[3], double cutoff, CellPairTraversalData *data)
Definition: QuickschedTraversal.h:81
static void exit(int exitcode)
Terminate simulation with given exit code.
Definition: Simulation.cpp:155
Vectorized calculation of the force.
Definition: VectorizedCellProcessor.h:29
Enumeration class corresponding to the type schema type.
Definition: vtk-unstructured.h:1746
Definition: CellPairTraversals.h:16
Definition: QuickschedTraversal.h:22