Skip to content

Commit

Permalink
Introduce AMGCL_USE_PROPERTY_TREE preprocessor macro
Browse files Browse the repository at this point in the history
* When defined, include <boost/property_tree/ptree.hpp>
  and allow conversion of boost::property_tree::ptree to amgcl params.
* When AMGCL_USE_PROPERTY_TREE is not defined, but BOOST_VERSION is,
  then define AMGCL_USE_PROPERTY_TREE anyway (Boost.PropertyTree is
  header-only and should not require any link options).
* When neither AMGCL_USE_PROPERTY_TREE nor BOOST_VERSION is defined, but a
  runtime header is included, use pragma error to complain.
  • Loading branch information
ddemidov committed Jul 16, 2018
1 parent e63c095 commit a385c6b
Show file tree
Hide file tree
Showing 51 changed files with 118 additions and 60 deletions.
2 changes: 1 addition & 1 deletion amgcl/amg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class amg {
#endif
{}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, coarsening),
AMGCL_PARAMS_IMPORT_CHILD(p, relax),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/backend/block_crs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct block_crs {

params(size_t block_size = 4) : block_size(block_size) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, block_size)
{
Expand Down
2 changes: 1 addition & 1 deletion amgcl/backend/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ struct cuda {

params(cusparseHandle_t handle = 0) : cusparse_handle(handle) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, cusparse_handle)
{
Expand Down
2 changes: 2 additions & 0 deletions amgcl/backend/hpx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ struct HPX {

params() : grain_size(4096) {}

#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, grain_size)
{
Expand All @@ -231,6 +232,7 @@ struct HPX {
void get(boost::property_tree::ptree &p, const std::string &path) const {
AMGCL_PARAMS_EXPORT_VALUE(p, path, grain_size);
}
#endif
};

typedef hpx_matrix<value_type> matrix;
Expand Down
2 changes: 2 additions & 0 deletions amgcl/backend/vexcl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct vexcl {

params() : fast_matrix_setup(true) {}

#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, fast_matrix_setup)
{
Expand All @@ -123,6 +124,7 @@ struct vexcl {
p.put(path + "q", &q);
AMGCL_PARAMS_EXPORT_VALUE(p, path, fast_matrix_setup);
}
#endif

const std::vector<vex::backend::command_queue>& context() const {
if (q.empty())
Expand Down
2 changes: 1 addition & 1 deletion amgcl/coarsening/aggregation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct aggregation {

params() : over_interp(1.5f) { }

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, aggr),
AMGCL_PARAMS_IMPORT_CHILD(p, nullspace),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/coarsening/plain_aggregates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct plain_aggregates {

params() : eps_strong(0.08f) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, eps_strong)
{
Expand Down
2 changes: 1 addition & 1 deletion amgcl/coarsening/pointwise_aggregates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class pointwise_aggregates {

params() : block_size(1) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: plain_aggregates::params(p),
AMGCL_PARAMS_IMPORT_VALUE(p, block_size)
Expand Down
2 changes: 1 addition & 1 deletion amgcl/coarsening/ruge_stuben.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct ruge_stuben {

params() : eps_strong(0.25f), do_trunc(true), eps_trunc(0.2f) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, eps_strong),
AMGCL_PARAMS_IMPORT_VALUE(p, do_trunc),
Expand Down
11 changes: 8 additions & 3 deletions amgcl/coarsening/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ THE SOFTWARE.

#include <iostream>
#include <stdexcept>

#include <type_traits>
#include <boost/property_tree/ptree.hpp>

#include <amgcl/util.hpp>
#ifndef AMGCL_USE_PROPERTY_TREE
# error \
Runtime interface relies on Boost.PropertyTree! \
Either define AMGCL_USE_PROPERTY_TREE, or \
include <boost/property_tree/ptree.hpp> before any of the amgcl headers.
#endif

#include <amgcl/backend/interface.hpp>
#include <amgcl/coarsening/ruge_stuben.hpp>
#include <amgcl/coarsening/aggregation.hpp>
#include <amgcl/coarsening/smoothed_aggregation.hpp>
#include <amgcl/coarsening/smoothed_aggr_emin.hpp>
#include <amgcl/util.hpp>

namespace amgcl {
namespace runtime {
Expand Down
2 changes: 1 addition & 1 deletion amgcl/coarsening/smoothed_aggr_emin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct smoothed_aggr_emin {

params() {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, aggr),
AMGCL_PARAMS_IMPORT_CHILD(p, nullspace)
Expand Down
2 changes: 1 addition & 1 deletion amgcl/coarsening/smoothed_aggregation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct smoothed_aggregation {

params() : relax(1.0f), estimate_spectral_radius(false), power_iters(0) { }

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, aggr),
AMGCL_PARAMS_IMPORT_CHILD(p, nullspace),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/coarsening/tentative_prolongation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct nullspace_params {

nullspace_params() : cols(0) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
nullspace_params(const boost::property_tree::ptree &p)
: cols(p.get("cols", nullspace_params().cols))
{
Expand Down
4 changes: 2 additions & 2 deletions amgcl/make_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class make_solver {

params() {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, precond),
AMGCL_PARAMS_IMPORT_CHILD(p, solver)
Expand Down Expand Up @@ -191,7 +191,7 @@ class make_solver {
return P.system_matrix();
}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
/// Stores the parameters used during construction into the property tree \p p.
void get_params(boost::property_tree::ptree &p) const {
prm.get(p);
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/amg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class amg {
npre(1), npost(1), ncycle(1), pre_cycles(1)
{}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, coarsening),
AMGCL_PARAMS_IMPORT_CHILD(p, relax),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/coarsening/aggregation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct aggregation {

params() : over_interp(1.5f) { }

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, aggr),
AMGCL_PARAMS_IMPORT_VALUE(p, over_interp)
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/coarsening/pmis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct pmis {

params() : eps_strong(0.08), block_size(1) { }

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, eps_strong),
AMGCL_PARAMS_IMPORT_VALUE(p, block_size)
Expand Down
9 changes: 7 additions & 2 deletions amgcl/mpi/coarsening/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ THE SOFTWARE.
* \brief Runtime wrapper for distributed coarsening schemes.
*/

#include <boost/property_tree/ptree.hpp>

#include <amgcl/util.hpp>
#ifndef AMGCL_USE_PROPERTY_TREE
# error \
Runtime interface relies on Boost.PropertyTree! \
Either define AMGCL_USE_PROPERTY_TREE, or \
include <boost/property_tree/ptree.hpp> before any of the amgcl headers.
#endif

#include <amgcl/mpi/util.hpp>
#include <amgcl/mpi/distributed_matrix.hpp>
#include <amgcl/mpi/coarsening/aggregation.hpp>
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/coarsening/smoothed_aggregation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct smoothed_aggregation {
: relax(1.0f), estimate_spectral_radius(false), power_iters(0)
{ }

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, aggr),
AMGCL_PARAMS_IMPORT_VALUE(p, relax),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/direct_solver/pastix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class pastix : public solver_base< value_type, pastix<value_type, Distrib> > {
: max_rows_per_process(50000)
{}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, max_rows_per_process)
{
Expand Down
9 changes: 7 additions & 2 deletions amgcl/mpi/direct_solver/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ THE SOFTWARE.
* \brief Runtime wrapper for distributed direct solvers.
*/

#include <boost/property_tree/ptree.hpp>

#include <amgcl/util.hpp>
#ifndef AMGCL_USE_PROPERTY_TREE
# error \
Runtime interface relies on Boost.PropertyTree! \
Either define AMGCL_USE_PROPERTY_TREE, or \
include <boost/property_tree/ptree.hpp> before any of the amgcl headers.
#endif

#include <amgcl/mpi/direct_solver/skyline_lu.hpp>
#ifdef AMGCL_HAVE_EIGEN
# include <amgcl/mpi/direct_solver/eigen_splu.hpp>
Expand Down
4 changes: 2 additions & 2 deletions amgcl/mpi/make_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class make_solver {

params() {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, precond),
AMGCL_PARAMS_IMPORT_CHILD(p, solver)
Expand Down Expand Up @@ -148,7 +148,7 @@ class make_solver {
return P.system_matrix();
}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
void get_params(boost::property_tree::ptree &p) const {
prm.get(p);
}
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/partition/merge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct merge {
enable(false), min_per_proc(10000), shrink_ratio(8)
{}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, enable),
AMGCL_PARAMS_IMPORT_VALUE(p, min_per_proc),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/partition/parmetis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct parmetis {
enable(false), min_per_proc(10000), shrink_ratio(8)
{}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, enable),
AMGCL_PARAMS_IMPORT_VALUE(p, min_per_proc),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/partition/ptscotch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ptscotch {
enable(false), min_per_proc(10000), shrink_ratio(8)
{}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, enable),
AMGCL_PARAMS_IMPORT_VALUE(p, min_per_proc),
Expand Down
9 changes: 8 additions & 1 deletion amgcl/mpi/partition/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ THE SOFTWARE.
*/

#include <memory>
#include <boost/property_tree/ptree.hpp>

#include <amgcl/util.hpp>
#ifndef AMGCL_USE_PROPERTY_TREE
# error \
Runtime interface relies on Boost.PropertyTree! \
Either define AMGCL_USE_PROPERTY_TREE, or \
include <boost/property_tree/ptree.hpp> before any of the amgcl headers.
#endif

#include <amgcl/mpi/partition/merge.hpp>

Expand Down
8 changes: 7 additions & 1 deletion amgcl/mpi/relaxation/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ THE SOFTWARE.

#include <memory>

#include <boost/property_tree/ptree.hpp>
#include <amgcl/util.hpp>
#ifndef AMGCL_USE_PROPERTY_TREE
# error \
Runtime interface relies on Boost.PropertyTree! \
Either define AMGCL_USE_PROPERTY_TREE, or \
include <boost/property_tree/ptree.hpp> before any of the amgcl headers.
#endif

#include <amgcl/backend/interface.hpp>
#include <amgcl/value_type/interface.hpp>
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/schur_pressure_correction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class schur_pressure_correction {

params() : approx_schur(true) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, usolver),
AMGCL_PARAMS_IMPORT_CHILD(p, psolver),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/mpi/subdomain_deflation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class subdomain_deflation {

params() {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, local),
AMGCL_PARAMS_IMPORT_CHILD(p, isolver),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/preconditioner/cpr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class cpr {

params() : block_size(2), active_rows(0) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, pprecond),
AMGCL_PARAMS_IMPORT_CHILD(p, sprecond),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/preconditioner/cpr_drs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class cpr_drs {

params() : block_size(2), active_rows(0), eps_dd(0.2), eps_ps(0.02) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, pprecond),
AMGCL_PARAMS_IMPORT_CHILD(p, sprecond),
Expand Down
9 changes: 8 additions & 1 deletion amgcl/preconditioner/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ THE SOFTWARE.
* \brief Runtime-configurable wrappers around amgcl classes.
*/

#include <boost/property_tree/ptree.hpp>
#include <amgcl/util.hpp>
#ifndef AMGCL_USE_PROPERTY_TREE
# error \
Runtime interface relies on Boost.PropertyTree! \
Either define AMGCL_USE_PROPERTY_TREE, or \
include <boost/property_tree/ptree.hpp> before any of the amgcl headers.
#endif

#include <amgcl/solver/runtime.hpp>
#include <amgcl/coarsening/runtime.hpp>
#include <amgcl/relaxation/runtime.hpp>
Expand Down
2 changes: 1 addition & 1 deletion amgcl/preconditioner/schur_pressure_correction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class schur_pressure_correction {

params() : approx_schur(true) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_CHILD(p, usolver),
AMGCL_PARAMS_IMPORT_CHILD(p, psolver),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/relaxation/chebyshev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class chebyshev {

params() : degree(5), lower(1.0f / 30), power_iters(0) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, degree),
AMGCL_PARAMS_IMPORT_VALUE(p, lower),
Expand Down
2 changes: 1 addition & 1 deletion amgcl/relaxation/cusparse_ilu0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct ilu0< backend::cuda<real> > {

params() : damping(1) {}

#ifdef BOOST_VERSION
#ifdef AMGCL_USE_PROPERTY_TREE
params(const boost::property_tree::ptree &p)
: AMGCL_PARAMS_IMPORT_VALUE(p, damping)
{
Expand Down

0 comments on commit a385c6b

Please sign in to comment.