| 1 | /**
|
|---|
| 2 | * @file comm_key.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Nov 21 13:27:22 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Class to distinguish the different communicators for
|
|---|
| 7 | * different grids.
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #ifdef HAVE_CONFIG_H
|
|---|
| 12 | #include <config.h>
|
|---|
| 13 | #endif
|
|---|
| 14 |
|
|---|
| 15 | #include "comm/mpi/comm_key.hpp"
|
|---|
| 16 | #include "grid/grid.hpp"
|
|---|
| 17 |
|
|---|
| 18 | using namespace VMG;
|
|---|
| 19 |
|
|---|
| 20 | VMG::MPI::CommKey::CommKey()
|
|---|
| 21 | {
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | VMG::MPI::CommKey::CommKey(const Grid& grid)
|
|---|
| 25 | {
|
|---|
| 26 | AddKey(grid);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | VMG::MPI::CommKey::CommKey(const Grid& grid_1, const Grid& grid_2)
|
|---|
| 30 | {
|
|---|
| 31 | AddKey(grid_1);
|
|---|
| 32 | AddKey(grid_2);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | VMG::MPI::CommKey::CommKey(const GlobalIndices& global, const void* addr)
|
|---|
| 36 | {
|
|---|
| 37 | AddKey(global, addr);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | void VMG::MPI::CommKey::AddKey(const Grid& grid)
|
|---|
| 41 | {
|
|---|
| 42 | for (int i=0; i<3; ++i) {
|
|---|
| 43 | int_key.push_back(grid.Global().BeginLocal()[i]);
|
|---|
| 44 | int_key.push_back(grid.Global().EndLocal()[i]);
|
|---|
| 45 | int_key.push_back(grid.Global().SizeGlobal()[i]);
|
|---|
| 46 | }
|
|---|
| 47 | addr_key.push_back(reinterpret_cast<const void*>(&grid));
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | void VMG::MPI::CommKey::AddKey(const GlobalIndices& global, const void* addr)
|
|---|
| 51 | {
|
|---|
| 52 | for (int i=0; i<3; ++i) {
|
|---|
| 53 | int_key.push_back(global.BeginLocal()[i]);
|
|---|
| 54 | int_key.push_back(global.EndLocal()[i]);
|
|---|
| 55 | int_key.push_back(global.SizeGlobal()[i]);
|
|---|
| 56 | }
|
|---|
| 57 | addr_key.push_back(addr);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | bool VMG::MPI::CommKey::operator<(const CommKey& other) const
|
|---|
| 61 | {
|
|---|
| 62 | if (this->int_key.size() < other.int_key.size())
|
|---|
| 63 | return true;
|
|---|
| 64 | else if (this->int_key.size() > other.int_key.size())
|
|---|
| 65 | return false;
|
|---|
| 66 |
|
|---|
| 67 | if (this->addr_key.size() < other.addr_key.size())
|
|---|
| 68 | return true;
|
|---|
| 69 | else if (this->addr_key.size() > other.addr_key.size())
|
|---|
| 70 | return false;
|
|---|
| 71 |
|
|---|
| 72 | for (unsigned int i=0; i<int_key.size(); ++i)
|
|---|
| 73 | if (this->int_key[i] < other.int_key[i])
|
|---|
| 74 | return true;
|
|---|
| 75 | else if (this->int_key[i] > other.int_key[i])
|
|---|
| 76 | return false;
|
|---|
| 77 |
|
|---|
| 78 | for (unsigned int i=0; i<addr_key.size(); ++i)
|
|---|
| 79 | if (this->addr_key[i] < other.addr_key[i])
|
|---|
| 80 | return true;
|
|---|
| 81 | else if (this->addr_key[i] > other.addr_key[i])
|
|---|
| 82 | return false;
|
|---|
| 83 |
|
|---|
| 84 | return false;
|
|---|
| 85 | }
|
|---|