| [dfed1c] | 1 | /**
|
|---|
| 2 | * @file global_grid_partitioning.hpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Thu May 19 14:02:46 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Class to store global grid partitioning.
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #include <cassert>
|
|---|
| 15 |
|
|---|
| 16 | #include "grid/global_grid_partitioning.hpp"
|
|---|
| 17 |
|
|---|
| 18 | using namespace VMG;
|
|---|
| 19 |
|
|---|
| 20 | GlobalGridPartitioning::GlobalGridPartitioning(Index pos, Index procs, Index size, int points_min)
|
|---|
| 21 | {
|
|---|
| 22 | Index i;
|
|---|
| 23 | Index index_beg, index_end;
|
|---|
| 24 | Index local_size;
|
|---|
| 25 |
|
|---|
| 26 | const Index active_procs = size / points_min;
|
|---|
| 27 | const Index size_per_proc = size / active_procs;
|
|---|
| 28 | const Index remainder = size % active_procs;
|
|---|
| 29 |
|
|---|
| 30 | for (i.X() = 0; i.X() < active_procs.X(); ++i.X())
|
|---|
| 31 | for (i.Y() = 0; i.Y() < active_procs.Y(); ++i.Y())
|
|---|
| 32 | for (i.Z() = 0; i.Z() < active_procs.Z(); ++i.Z()) {
|
|---|
| 33 |
|
|---|
| 34 | local_size = size_per_proc;
|
|---|
| 35 |
|
|---|
| 36 | for (int j=0; j<3; ++j)
|
|---|
| 37 | if (pos[j] < remainder[j])
|
|---|
| 38 | ++(local_size[j]);
|
|---|
| 39 |
|
|---|
| 40 | index_beg = i * local_size;
|
|---|
| 41 |
|
|---|
| 42 | for (int j=0; j<3; ++j)
|
|---|
| 43 | if (i[j] >= remainder[j])
|
|---|
| 44 | index_beg[j] += remainder[j];
|
|---|
| 45 |
|
|---|
| 46 | index_end = index_beg + local_size;
|
|---|
| 47 |
|
|---|
| 48 | begin.insert(std::make_pair(i, index_beg));
|
|---|
| 49 | end.insert(std::make_pair(i, index_end));
|
|---|
| 50 |
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | const Index& GlobalGridPartitioning::GlobalBegin(const Index& pos) const
|
|---|
| 56 | {
|
|---|
| 57 | std::map<Index, Index>::const_iterator iter = begin.find(pos);
|
|---|
| 58 |
|
|---|
| 59 | assert(iter != begin.end());
|
|---|
| 60 |
|
|---|
| 61 | return iter->second;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | const Index& GlobalGridPartitioning::GlobalEnd(const Index& pos) const
|
|---|
| 65 | {
|
|---|
| 66 | std::map<Index, Index>::const_iterator iter = end.find(pos);
|
|---|
| 67 |
|
|---|
| 68 | assert(iter != end.end());
|
|---|
| 69 |
|
|---|
| 70 | return iter->second;
|
|---|
| 71 | }
|
|---|