Skip to content
Snippets Groups Projects
Commit 3b864939 authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Fixing example to fail on error

parent 6b40cc04
No related branches found
No related tags found
No related merge requests found
SUBDIRS := $(wildcard */.)
all clean:
all: $(SUBDIRS)
clean:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir $@; \
$(MAKE) -C $$dir clean; \
done
clean: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
.PHONY: all clean $(SUBDIRS)
.PHONY: all clean $(SUBDIRS)
include ../../../example.mk
CC=mpic++
LDIR =
OBJ = main.o
%.o: %.cpp
$(CC) -O3 -g -c --std=c++11 -o $@ $< $(INCLUDE_PATH) -I/home/i-bird/HDF5/include
agsim: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS_PATH) $(LIBS)
all: agsim
.PHONY: clean all
clean:
rm -f *.o *~ core agsim
/*
* ### WIKI 1 ###
*
* ## Simple example
*
* In this example show an agent based simulation
*
* ### WIKI END ###
*
*/
#include "Vector/vector_dist.hpp"
#include "Decomposition/CartDecomposition.hpp"
#include "PSE/Kernels.hpp"
#include "Plot/util.hpp"
#include "Plot/GoogleChart.hpp"
#include "data_type/aggregate.hpp"
#include <cmath>
struct animal
{
typedef boost::fusion::vector<float[2], size_t, size_t, long int> type;
//! Attributes name
struct attributes
{
static const std::string name[];
};
//! type of the positional field
typedef float s_type;
//! The data
type data;
//! position property id in boost::fusion::vector
static const unsigned int pos = 0;
//! genre of animal property id in boost::fusion::vector
static const unsigned int genre = 1;
//! state property id in boost::fusion::vector
static const unsigned int status = 2;
//! alive time property id in boost::fusion::vector
static const unsigned int time_a = 3;
//! total number of properties boost::fusion::vector
static const unsigned int max_prop = 4;
animal()
{
}
inline animal(const animal & p)
{
boost::fusion::at_c<0>(data)[0] = boost::fusion::at_c<0>(p.data)[0];
boost::fusion::at_c<0>(data)[1] = boost::fusion::at_c<0>(p.data)[1];
//boost::fusion::at_c<0>(data)[2] = boost::fusion::at_c<0>(p.data)[2];
boost::fusion::at_c<1>(data) = boost::fusion::at_c<1>(p.data);
boost::fusion::at_c<2>(data) = boost::fusion::at_c<2>(p.data);
boost::fusion::at_c<3>(data) = boost::fusion::at_c<3>(p.data);
}
template<unsigned int id> inline auto get() -> decltype(boost::fusion::at_c < id > (data))
{
return boost::fusion::at_c<id>(data);
}
template<unsigned int id> inline auto get() const -> const decltype(boost::fusion::at_c < id > (data))
{
return boost::fusion::at_c<id>(data);
}
template<unsigned int dim, typename Mem> inline animal(const encapc<dim, animal, Mem> & p)
{
this->operator=(p);
}
template<unsigned int dim, typename Mem> inline animal & operator=(const encapc<dim, animal, Mem> & p)
{
boost::fusion::at_c<0>(data)[0] = p.template get<0>()[0];
boost::fusion::at_c<0>(data)[1] = p.template get<0>()[1];
//boost::fusion::at_c<0>(data)[2] = p.template get<0>()[2];
boost::fusion::at_c<1>(data) = p.template get<1>();
boost::fusion::at_c<2>(data) = p.template get<2>();
boost::fusion::at_c<3>(data) = p.template get<3>();
return *this;
}
static bool noPointers()
{
return true;
}
};
const std::string animal::attributes::name[] = { "pos", "genre", "status", "time_a", "j_repr" };
int main(int argc, char* argv[])
{
init_global_v_cluster(&argc,&argv);
Vcluster & v_cl = *global_v_cluster;
//time the animal stays alive without eating
size_t PRED_TIME_A = 14;
size_t PREY_TIME_A = 7;
size_t PREDATOR = 1, PREY = 0;
size_t ALIVE = 1, DEAD = 0;
// Predators reproducing probability
float PRED_REPR = 0.2;
// Predators eating probability
float PRED_EAT = 0.6;
// Prey reproducing probability
float PREY_REPR = 0.5;
// set the seed
// create the random generator engine
std::srand(v_cl.getProcessUnitID());
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine eg(seed);
std::uniform_real_distribution<float> ud(0.0f, 1.0f);
std::uniform_real_distribution<float> md(-1.0f, 1.0f);
std::uniform_real_distribution<float> uc(0.0f, 0.7f);
std::uniform_real_distribution<float> lc(0.3f, 1.0f);
size_t k = 100000;
Box<2, float> box( { 0.0, 0.0 }, { 1.0, 1.0 });
// Grid info
grid_sm<2, void> info( { 8, 8 });
// Boundary conditions
size_t bc[2] = { PERIODIC, PERIODIC };
// factor
float factor = pow(global_v_cluster->getProcessingUnits() / 2.0f, 1.0f / 3.0f);
// interaction radius
float r_cut = 0.01 / factor;
// ghost
Ghost<2, float> ghost(r_cut);
// Distributed vector
vector_dist<2, float, animal, CartDecomposition<2, float, HeapMemory, ParMetisDistribution<2, float>>> vd(k,box,bc,ghost);
// Init DLB tool
DLB dlb(v_cl);
// Set unbalance threshold
dlb.setHeurisitc(DLB::Heuristic::UNBALANCE_THRLD);
dlb.setThresholdLevel(DLB::ThresholdLevel::THRLD_MEDIUM);
auto it = vd.getIterator();
while (it.isNext())
{
auto key = it.get();
if(ud(eg) < 0.7 )
{
vd.template getPos<animal::pos>(key)[0] = lc(eg);
vd.template getPos<animal::pos>(key)[1] = lc(eg);
vd.template getProp<animal::genre>(key) = PREY;
vd.template getProp<animal::status>(key) = ALIVE;
vd.template getProp<animal::time_a>(key) = PREY_TIME_A;
}
else
{
vd.template getPos<animal::pos>(key)[0] = uc(eg);
vd.template getPos<animal::pos>(key)[1] = uc(eg);
vd.template getProp<animal::genre>(key) = PREDATOR;
vd.template getProp<animal::status>(key) = ALIVE;
vd.template getProp<animal::time_a>(key) = PRED_TIME_A;
}
++it;
}
vd.map();
vd.addComputationCosts();
vd.getDecomposition().rebalance(dlb);
vd.map();
//vd.getDecomposition().getDistribution().write("parmetis_prey_predators_" + std::to_string(0) + ".vtk");
//vd.write("particles_", 0, NO_GHOST);
// 100 step random walk
for (size_t j = 0; j < 100; j++)
{
size_t prey = 0, predators = 0;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
vd.template getPos<animal::pos>(key)[0] += 0.01 * md(eg);
vd.template getPos<animal::pos>(key)[1] += 0.01 * md(eg);
if(vd.template getProp<animal::genre>(key) == PREY)
prey++;
else
predators++;
++it;
}
vd.map();
/////// Interactions ///
// get ghosts
vd.ghost_get<0>();
// vector of dead animals
openfpm::vector<size_t> deads;
openfpm::vector<vect_dist_key_dx> reps_prey;
openfpm::vector<vect_dist_key_dx> reps_pred;
// get the cell list with a cutoff radius
bool error = false;
auto NN = vd.getCellList(0.01/factor);
// iterate across the domain particle
auto it2 = vd.getDomainIterator();
while (it2.isNext())
{
auto p = it2.get();
Point<2,float> xp = vd.getPos<0>(p);
size_t gp = vd.getProp<animal::genre>(p);
size_t sp = vd.getProp<animal::status>(p);
if(sp == ALIVE)
{
if(gp == PREY)
{
if( prey < k/1.5 && ud(eg) < PREY_REPR )
reps_prey.add(p);
vd.getProp<animal::time_a>(p)--;
if(vd.getProp<animal::time_a>(p) <= 0)
{
vd.getProp<animal::status>(p) = DEAD;
prey--;
}
}
else if(gp == PREDATOR)
{
vd.getProp<animal::time_a>(p)--;
if(vd.getProp<animal::time_a>(p) <= 0)
{
vd.getProp<animal::status>(p) = DEAD;
}
else
{
auto Np = NN.getIterator(NN.getCell(xp));
while (Np.isNext())
{
auto q = Np.get();
size_t gq = vd.getProp<animal::genre>(q);
size_t sq = vd.getProp<animal::status>(q);
Point<2,float> xq = vd.getPos<0>(q);
Point<2,float> f = (xp - xq);
float distance = f.norm();
if (distance < 2*r_cut*sqrt(2) && gq == PREY && sq == ALIVE)
{
if( ud(eg) < PRED_EAT )
{
vd.getProp<animal::status>(q) = DEAD;
vd.getProp<animal::time_a>(p) = PRED_TIME_A;
if( ud(eg) < PRED_REPR )
reps_pred.add(p);
}
}
++Np;
}
}
}
}
++it2;
}
vd.deleteGhost();
// Replicate
for (size_t i = 0 ; i < reps_prey.size() ; i++)
{
vd.add();
vd.getLastPos<animal::pos>()[0] = vd.getPos<0>(reps_prey.get(i))[0];
vd.getLastPos<animal::pos>()[1] = vd.getPos<0>(reps_prey.get(i))[1];
vd.getLastProp<animal::genre>() = PREY;
vd.getLastProp<animal::status>() = ALIVE;
vd.getLastProp<animal::time_a>() = PREY_TIME_A;
}
for (size_t i = 0 ; i < reps_pred.size() ; i++)
{
vd.add();
vd.getLastPos<animal::pos>()[0] = vd.getPos<0>(reps_pred.get(i))[0];
vd.getLastPos<animal::pos>()[1] = vd.getPos<0>(reps_pred.get(i))[1];
vd.getLastProp<animal::genre>() = PREDATOR;
vd.getLastProp<animal::status>() = ALIVE;
vd.getLastProp<animal::time_a>() = PRED_TIME_A;
}
auto it3 = vd.getDomainIterator();
while (it3.isNext())
{
auto key = it3.get();
if(vd.getProp<animal::status>(key.getKey()) == DEAD)
{
deads.add(key.getKey());
}
++it3;
}
deads.sort();
vd.remove(deads, 0);
deads.resize(0);
vd.deleteGhost();
////////////////////////
vd.addComputationCosts();
vd.getDecomposition().rebalance(dlb);
vd.map();
}
//
// ### WIKI 10 ###
//
// Deinitialize the library
//
delete_global_v_cluster();
}
/*
* vector_dist_cl_hilb_performance_tests.hpp
*
* Created on: May 24, 2016
* Author: Yaroslav Zaluzhnyi
*/
#ifndef SRC_VECTOR_VECTOR_DIST_CL_HILB_PERFORMANCE_TESTS_HPP_
#define SRC_VECTOR_VECTOR_DIST_CL_HILB_PERFORMANCE_TESTS_HPP_
#include "Vector/vector_dist.hpp"
#include "data_type/aggregate.hpp"
#include "Plot/GoogleChart.hpp"
#include "vector_dist_performance_util.hpp"
BOOST_AUTO_TEST_SUITE( vector_dist_celllist_hilb_performance_test )
///////////////////// INPUT DATA //////////////////////
// Cut-off radiuses. Can be put different number of values
openfpm::vector<float> r_cutoff {0.01, 0.02, 0.03};
// The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
size_t k_start = 100000;
// The lower threshold for number of particles
size_t k_min = 15000;
// Ghost part of distributed vector
double ghost_part = 0.03;
///////////////////////////////////////////////////////
// Numbers of particles vector
openfpm::vector<size_t> n_particles;
// Vectors to store the data for 2D
openfpm::vector<openfpm::vector<double>> time_rand;
openfpm::vector<openfpm::vector<double>> time_hilb;
openfpm::vector<openfpm::vector<double>> time_total_rand;
openfpm::vector<openfpm::vector<double>> time_total_hilb;
// Vectors to store the data for 3D
openfpm::vector<openfpm::vector<double>> time_rand_2;
openfpm::vector<openfpm::vector<double>> time_hilb_2;
openfpm::vector<openfpm::vector<double>> time_total_rand_2;
openfpm::vector<openfpm::vector<double>> time_total_hilb_2;
BOOST_AUTO_TEST_CASE( vector_dist_celllist_random_test )
{
//Benchmark test for 2D and 3D
vd_celllist_random_benchmark<2>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_rand,time_total_rand);
vd_celllist_random_benchmark<3>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_rand_2,time_total_rand_2);
}
BOOST_AUTO_TEST_CASE( vector_dist_celllist_hilbert_test )
{
//Benchmark test for 2D and 3D
vd_celllist_hilbert_benchmark<2>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_hilb,time_total_hilb);
vd_celllist_hilbert_benchmark<3>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_hilb_2,time_total_hilb_2);
}
BOOST_AUTO_TEST_CASE(vector_dist_cl_performance_write_report)
{
//Write report for 2D and 3D
vd_celllist_performance_write_report<2>(r_cutoff,n_particles,time_hilb,time_rand,time_total_hilb,time_total_rand);
vd_celllist_performance_write_report<3>(r_cutoff,n_particles,time_hilb_2,time_rand_2,time_total_hilb_2,time_total_rand_2);
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* SRC_VECTOR_VECTOR_DIST_CL_HILB_PERFORMANCE_TESTS_HPP_ */
/*
* vector_dist_cl_performance_tests.hpp
*
*
* Created on: Mar 22, 2016
* Author: Yaroslav Zaluzhnyi
*/
#ifndef SRC_VECTOR_VECTOR_DIST_CL_PERFORMANCE_TESTS_HPP_
#define SRC_VECTOR_VECTOR_DIST_CL_PERFORMANCE_TESTS_HPP_
#include "Vector/vector_dist.hpp"
#include "data_type/aggregate.hpp"
#include "Vector/vector_dist_unit_test.hpp"
#include "Plot/GoogleChart.hpp"
#include <functional>
BOOST_AUTO_TEST_SUITE( vector_dist_cl_perf_test )
///////////////////// INPUT DATA //////////////////////
// Cut-off radiuses. Can be put different number of values
openfpm::vector<float> r_cutoff {0.007,0.02};
// Orders of a curve. Can be put different number of values
openfpm::vector<size_t> orders = {1,2,3,5,7};
// Number of steps of moving the particles
size_t n_moving = 8;
// Moving distance (step size)
double dist = 0.1;
// The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
size_t k_start = 100000;
// The minimal amount of particles
size_t k_min = 15000;
// Ghost part of distributed vector
double ghost_part = 0.01;
///////////////////////////////////////////////////////
// Numbers of particles vector
openfpm::vector<size_t> n_particles;
// Vectors to store the data for 2D
openfpm::vector<openfpm::vector<double>> time_rand;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_hilb;
openfpm::vector<openfpm::vector<double>> time_total_rand;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_total_hilb;
openfpm::vector<openfpm::vector<openfpm::vector<openfpm::vector<double>>>> time_hilb_moved;
// Vectors to store the data for 3D
openfpm::vector<openfpm::vector<double>> time_rand_2;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_hilb_2;
openfpm::vector<openfpm::vector<double>> time_total_rand_2;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_total_hilb_2;
openfpm::vector<openfpm::vector<openfpm::vector<openfpm::vector<double>>>> time_hilb_moved_2;
BOOST_AUTO_TEST_CASE( vector_dist_cl_random_test )
{
//Benchmark test for 2D and 3D
vd_cl_random_benchmark<2>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_rand,time_total_rand);
vd_cl_random_benchmark<3>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_rand_2,time_total_rand_2);
}
BOOST_AUTO_TEST_CASE( vector_dist_cl_hilbert_test )
{
//Benchmark test for 2D and 3D
vd_cl_hilbert_benchmark<2>(k_start,k_min,ghost_part,n_moving,dist,r_cutoff,n_particles,orders,time_hilb,time_total_hilb,time_hilb_moved);
vd_cl_hilbert_benchmark<3>(k_start,k_min,ghost_part,n_moving,dist,r_cutoff,n_particles,orders,time_hilb_2,time_total_hilb_2,time_hilb_moved_2);
}
BOOST_AUTO_TEST_CASE(vector_dist_cl_performance_write_report)
{
//Write report for 2D and 3D
vd_cl_performance_write_report<2>(n_moving,r_cutoff,n_particles,orders,time_hilb,time_rand,time_total_hilb,time_total_rand,time_hilb_moved);
vd_cl_performance_write_report<3>(n_moving,r_cutoff,n_particles,orders,time_hilb_2,time_rand_2,time_total_hilb_2,time_total_rand_2,time_hilb_moved_2);
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* SRC_VECTOR_VECTOR_DIST_CL_PERFORMANCE_TESTS_HPP_ */
/*
* vector_dist_verlet_performance_tests.hpp
*
* Created on: Mar 9, 2016
* Author: Yaroslav Zaluzhnyi
*/
#ifndef SRC_VECTOR_VECTOR_DIST_VERLET_PERFORMANCE_TESTS_HPP_
#define SRC_VECTOR_VECTOR_DIST_VERLET_PERFORMANCE_TESTS_HPP_
#include "Vector/vector_dist.hpp"
#include "data_type/aggregate.hpp"
#include "Plot/GoogleChart.hpp"
#include "vector_dist_performance_util.hpp"
BOOST_AUTO_TEST_SUITE( vector_dist_verlet_perf_test )
///////////////////// INPUT DATA //////////////////////
// Cut-off radiuses. Can be put different number of values
openfpm::vector<float> r_cutoff {0.007,0.02};
// Orders of a curve. Can be put different number of values
openfpm::vector<size_t> orders = {1,2,3,5,7};
// The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
size_t k_start = 100000;
// The minimal amount of particles
size_t k_min = 15000;
// Ghost part of distributed vector
double ghost_part = 0.01;
///////////////////////////////////////////////////////
// Numbers of particles vector
openfpm::vector<size_t> n_particles;
// Vectors to store the data for 2D
openfpm::vector<openfpm::vector<double>> time_rand;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_hilb;
openfpm::vector<openfpm::vector<double>> time_total_rand;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_total_hilb;
// Vectors to store the data for 3D
openfpm::vector<openfpm::vector<double>> time_rand_2;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_hilb_2;
openfpm::vector<openfpm::vector<double>> time_total_rand_2;
openfpm::vector<openfpm::vector<openfpm::vector<double>>> time_total_hilb_2;
BOOST_AUTO_TEST_CASE( vector_dist_verlet_random_test )
{
//Benchmark test for 2D and 3D
vd_verlet_random_benchmark<2>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_rand,time_total_rand);
vd_verlet_random_benchmark<3>(k_start,k_min,ghost_part,r_cutoff,n_particles,time_rand_2,time_total_rand_2);
}
BOOST_AUTO_TEST_CASE( vector_dist_verlet_hilbert_test )
{
//Benchmark test for 2D and 3D
vd_verlet_hilbert_benchmark<2>(k_start,k_min,ghost_part,r_cutoff,n_particles,orders,time_hilb,time_total_hilb);
vd_verlet_hilbert_benchmark<3>(k_start,k_min,ghost_part,r_cutoff,n_particles,orders,time_hilb_2,time_total_hilb_2);
}
BOOST_AUTO_TEST_CASE(vector_dist_verlet_performance_write_report)
{
//Write report for 2D and 3D
vd_verlet_performance_write_report<2>(r_cutoff,n_particles,orders,time_hilb,time_rand,time_total_hilb,time_total_rand);
vd_verlet_performance_write_report<3>(r_cutoff,n_particles,orders,time_hilb_2,time_rand_2,time_total_hilb_2,time_total_rand_2);
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* SRC_VECTOR_VECTOR_DIST_VERLET_PERFORMANCE_TESTS_HPP_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment