Data is send through a chain of compute nodes and every node increments the value.
#include <iostream>
#include <vector>
#include <array>
#include <functional>
#include <cmath>
#include <cstdlib>
#include <numeric>
#include <graybat/Cage.hpp>
#include <graybat/communicationPolicy/BMPI.hpp>
#include <graybat/graphPolicy/BGL.hpp>
#include <graybat/mapping/Consecutive.hpp>
#include <graybat/mapping/Random.hpp>
#include <graybat/mapping/Roundrobin.hpp>
#include <graybat/mapping/Filter.hpp>
#include <graybat/pattern/Chain.hpp>
int tag;
};
int exp() {
typedef CP::Config Config;
typedef typename Cage::Event Event;
typedef typename Cage::Vertex Vertex;
const unsigned nChainLinks = 6;
auto inc = [](unsigned &a){a++;};
Config config;
Cage cage(config);
std::vector<Event> events;
std::array<unsigned, 1> input {{0}};
std::array<unsigned, 1> output {{0}};
std::array<unsigned, 1> intermediate {{0}};
const Vertex entry = cage.getVertex(0);
const Vertex exit = cage.getVertex(nChainLinks-1);
for(Vertex v : cage.hostedVertices){
if(v == entry){
v.spread(input, events);
std::cout << "Input: " << input[0] << " " << cage.comm.getGlobalContext().getVAddr() << std::endl;
}
if(v == exit){
v.collect(output);
std::cout << "Output: " << output[0] << " " << cage.comm.getGlobalContext().getVAddr() << std::endl;
}
if(v != entry and v != exit){
v.collect(intermediate);
inc(intermediate[0]);
std::cout << "Increment: " << intermediate[0] << " " << cage.comm.getGlobalContext().getVAddr() << std::endl;
v.spread(intermediate, events);
}
}
for(unsigned i = 0; i < events.size(); ++i){
events.back().wait();
events.pop_back();
}
return 0;
}
int main(){
exp();
return 0;
}