#include <cmath>
#include <vector>
#include <diy/master.hpp>
#include <diy/reduce.hpp>
#include <diy/partners/merge.hpp>
#include <diy/decomposition.hpp>
#include <diy/assigner.hpp>
#include "../opts.h"
using namespace std;
struct Block
{
Block(const Bounds& bounds_):
bounds(bounds_) {}
static void* create()
{ return new Block; }
static void destroy(void* b)
{ delete static_cast<Block*>(b); }
{
diy::save(bb, static_cast<const Block*>(b)->bounds);
diy::save(bb, static_cast<const Block*>(b)->data);
}
{
diy::load(bb, static_cast<Block*>(b)->bounds);
}
void generate_data(size_t n)
{
data.resize(n);
for (size_t i = 0; i < n; ++i)
data[i] = i;
}
Bounds bounds;
vector<int> data;
private:
Block() {}
};
struct AddBlock
{
master(master_),
num_points(num_points_)
{}
void operator()(int gid,
const Bounds& core,
const Bounds& bounds,
const Bounds& domain,
const RCLink& link)
const
{
Block* b = new Block(core);
RCLink* l = new RCLink(link);
b->generate_data(num_points);
}
size_t num_points;
};
void sum(Block* b,
{
unsigned round = rp.
round();
for (
int i = 0; i < rp.
in_link().
size(); ++i)
{
int nbr_gid = rp.
in_link().
target(i).
gid;
{
fmt::print(stderr, "[{}:{}] Skipping receiving from self\n", rp.gid(), round);
continue;
}
std::vector<int> in_vals;
fmt::print(stderr, "[{}:{}] Received {} values from [{}]\n",
rp.gid(), round, (int)in_vals.size(), nbr_gid);
for (size_t j = 0; j < in_vals.size(); ++j)
(b->data)[j] += in_vals[j];
}
for (
int i = 0; i < rp.
out_link().size(); ++i)
{
if (rp.
out_link().target(i).gid != rp.gid())
{
fmt::print(stderr, "[{}:{}] Sent {} valuess to [{}]\n",
rp.gid(), round, (int)b->data.size(), rp.
out_link().target(i).gid);
} else
fmt::print(stderr, "[{}:{}] Skipping sending to self\n", rp.gid(), round);
}
}
void print_block(Block* b,
bool verbose)
{
fmt::print(stderr, "[{}] Bounds: {} {} {} -- {} {} {}\n",
cp.gid(),
b->bounds.min[0], b->bounds.min[1], b->bounds.min[2],
b->bounds.max[0], b->bounds.max[1], b->bounds.max[2]);
if (verbose && cp.gid() == 0)
{
fmt::print(stderr, "[{}] {} vals: ", cp.gid(), b->data.size());
for (size_t i = 0; i < b->data.size(); ++i)
fmt::print(stderr, "{} ", b->data[i]);
fmt::print(stderr, "\n");
}
}
int main(int argc, char* argv[])
{
int nblocks = world.
size();
size_t num_points = 10;
int mem_blocks = -1;
int threads = 1;
int dim = 3;
using namespace opts;
Options ops(argc, argv);
bool verbose = ops >> Present('v',
"verbose",
"verbose output");
bool contiguous = ops >> Present('c',
"contiguous",
"use contiguous partners");
ops
>> Option('d', "dim", dim, "dimension")
>> Option('b', "blocks", nblocks, "number of blocks")
>> Option('t', "thread", threads, "number of threads")
;
if (ops >> Present('h', "help", "show help"))
{
std::cout << "Usage: " << argv[0] << " [OPTIONS]\n";
std::cout << ops;
return 1;
}
threads,
mem_blocks,
&Block::create,
&Block::destroy,
&storage,
AddBlock create(master, num_points);
Bounds domain;
for (int i = 0; i < dim; ++i)
{
domain.min[i] = 0;
domain.max[i] = 128.;
}
decomposer.decompose(world.
rank(), assigner, create);
int k = 2;
k,
contiguous);
assigner,
partners,
&sum);
{ print_block(b, cp, verbose); });
}