1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/*
* This file is a part of TiledArray.
* Copyright (C) 2013 Virginia Tech
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "TiledArray/pmap/cyclic_pmap.h"
#include "TiledArray/pmap/hash_pmap.h"
#include "tiledarray.h"
std::vector<ProcessID> make_map(std::size_t m, std::size_t n,
std::shared_ptr<TiledArray::Pmap>& pmap) {
std::vector<ProcessID> map;
const std::size_t end = m * n;
map.reserve(end);
for (std::size_t i = 0ul; i < end; ++i) map.push_back(pmap->owner(i));
return map;
}
void print_map(std::size_t m, std::size_t n,
const std::vector<ProcessID>& map) {
for (std::size_t i = 0ul; i < m; ++i) {
for (std::size_t j = 0ul; j < n; ++j) std::cout << map[i * n + j] << " ";
std::cout << "\n";
}
}
void print_local(TiledArray::World& world,
const std::shared_ptr<TiledArray::Pmap>& pmap) {
for (ProcessID r = 0; r < world.size(); ++r) {
world.gop.fence();
if (r == world.rank()) {
std::cout << r << ": { ";
for (TiledArray::Pmap::const_iterator it = pmap->begin();
it != pmap->end(); ++it)
std::cout << *it << " ";
std::cout << "}\n";
}
}
}
int main(int argc, char** argv) {
TiledArray::World& world = TiledArray::initialize(argc, argv);
std::size_t m = 20;
std::size_t n = 10;
std::size_t M = 200;
std::size_t N = 100;
std::shared_ptr<TiledArray::Pmap> blocked_pmap(
new TiledArray::detail::BlockedPmap(world, m * n));
std::vector<ProcessID> blocked_map = make_map(m, n, blocked_pmap);
std::shared_ptr<TiledArray::Pmap> cyclic_pmap(
new TiledArray::detail::CyclicPmap(world, m, n, M, N));
std::vector<ProcessID> cyclic_map = make_map(m, n, cyclic_pmap);
std::shared_ptr<TiledArray::Pmap> hash_pmap(
new TiledArray::detail::HashPmap(world, m * n));
std::vector<ProcessID> hash_map = make_map(m, n, hash_pmap);
if (world.rank() == 0) {
std::cout << "Block\n";
print_map(m, n, blocked_map);
std::cout << "\n";
}
print_local(world, blocked_pmap);
world.gop.fence();
if (world.rank() == 0) {
std::cout << "\n\nCyclic\n";
print_map(m, n, cyclic_map);
std::cout << "\n";
}
print_local(world, cyclic_pmap);
world.gop.fence();
if (world.rank() == 0) {
std::cout << "\n\nHash\n";
print_map(m, n, hash_map);
std::cout << "\n";
}
print_local(world, hash_pmap);
TiledArray::finalize();
return 0;
}
|