Skip to content

Commit

Permalink
Adding more tests to execution, solving argument mismatch compilation…
Browse files Browse the repository at this point in the history
… problem for HPX tasks

- fixing startup of HPX driver
- enable MPI only if available
- disable processor_type_t::mpi for now
- fixing a ton of warning in various places (mostly integral conversion issues)
  • Loading branch information
hkaiser committed Sep 13, 2020
1 parent 4132173 commit 06fe5e0
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 82 deletions.
6 changes: 3 additions & 3 deletions flecsi/coloring/crs.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ operator<<(std::ostream & stream, const crs_t & crs) {
struct dcrs_t : public crs_t {
std::vector<size_t> distribution;

define_as(distribution)
define_as(distribution);

/// \brief clears the current storage
void clear() {
/// \brief clears the current storage
void clear() {
crs_t::clear();
distribution.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion flecsi/coloring/dcrs_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ color_entities(const flecsi::coloring::crs_t & cells2entity,
}

// shared and ghost
for(const auto pair : entities2rank) {
for(const auto & pair : entities2rank) {
auto global_id = pair.first;
auto owner = pair.second;
// if i am the owner, shared
Expand Down
9 changes: 5 additions & 4 deletions flecsi/coloring/parmetis_colorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ struct parmetis_colorer_t : public colorer_t {
idx_t wgtflag = 0;
idx_t numflag = 0;
idx_t ncon = 1;
std::vector<real_t> tpwgts(ncon * size, 1.0 / size);
std::vector<real_t> tpwgts(ncon * size, static_cast<real_t>(1.0 / size));

// We may need to expose some of the ParMETIS configuration options.
std::vector<real_t> ubvec(ncon, 1.05);
std::vector<real_t> ubvec(ncon, static_cast<real_t>(1.05));
idx_t options[3] = {0, 0, 0};
idx_t edgecut;
MPI_Comm comm = MPI_COMM_WORLD;
std::vector<idx_t> part(dcrs.size(), std::numeric_limits<idx_t>::max());
std::vector<idx_t> part(dcrs.size(), (std::numeric_limits<idx_t>::max)());

// Get the dCRS information using ParMETIS types.
std::vector<idx_t> vtxdist = dcrs.distribution_as<idx_t>();
Expand All @@ -281,8 +281,9 @@ struct parmetis_colorer_t : public colorer_t {
int result = ParMETIS_V3_PartKway(&vtxdist[0], &xadj[0], &adjncy[0],
nullptr, nullptr, &wgtflag, &numflag, &ncon, &size, &tpwgts[0],
ubvec.data(), options, &edgecut, &part[0], &comm);
if(result != METIS_OK)
if(result != METIS_OK) {
clog_error("Parmetis failed!");
}

std::vector<size_t> partitioning(part.begin(), part.end());

Expand Down
2 changes: 1 addition & 1 deletion flecsi/data/data_client_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct data_client_handle_base_u : public DATA_CLIENT_TYPE,
data_client_handle_base_u(const data_client_handle_base_u<DATA_CLIENT_TYPE,
UNMAPPED_PERMISSIONS,
DATA_POLICY> & h)
: DATA_POLICY(h), DATA_CLIENT_TYPE(h), type_hash(h.type_hash),
: DATA_CLIENT_TYPE(h), DATA_POLICY(h), type_hash(h.type_hash),
name_hash(h.name_hash), namespace_hash(h.namespace_hash) {
static_assert(
UNMAPPED_PERMISSIONS == 0, "passing mapped client handle to task args");
Expand Down
2 changes: 0 additions & 2 deletions flecsi/data/hpx/dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ struct storage_class_u<storage_label_type_t::dense> {

auto & context = execution::context_t::instance();

using client_type = typename DATA_CLIENT_TYPE::type_identifier_t;

// get field_info for this data handle
auto & field_info = context.get_field_info_from_name(
typeid(typename DATA_CLIENT_TYPE::type_identifier_t).hash_code(),
Expand Down
4 changes: 1 addition & 3 deletions flecsi/execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ endif()
"Tests/Execution/Devel"
)

if(NOT FLECSI_RUNTIME_MODEL STREQUAL "hpx")
cinch_add_unit(reduction_interface
SOURCES
test/reduction_interface.cc
Expand All @@ -363,7 +362,6 @@ if(NOT FLECSI_RUNTIME_MODEL STREQUAL "hpx")
THREADS 4
)


cinch_add_devel_target(concept_coloring
SOURCES
test/concept_coloring.cc
Expand Down Expand Up @@ -499,7 +497,6 @@ if(NOT FLECSI_RUNTIME_MODEL STREQUAL "hpx")
)
endif()


cinch_add_unit(data_handle_task
SOURCES
test/data_handle_task.cc
Expand All @@ -522,6 +519,7 @@ if(NOT FLECSI_RUNTIME_MODEL STREQUAL "hpx")
"Tests/Execution"
)

if(NOT FLECSI_RUNTIME_MODEL STREQUAL "hpx")
cinch_add_unit(handle_accessor
SOURCES
test/handle_accessor.cc
Expand Down
5 changes: 3 additions & 2 deletions flecsi/execution/hpx/context_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <hpx/hpx_init.hpp>

#include <cstddef>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
Expand Down Expand Up @@ -58,8 +59,8 @@ hpx_context_policy_t::hpx_main(void (*driver)(int, char *[]),
char * argv[]) {

// initialize executors (possible only after runtime is active)
exec_ = flecsi::execution::pool_executor{"default"};
mpi_exec_ = flecsi::execution::pool_executor{"mpi"};
exec_ = std::make_unique<flecsi::execution::pool_executor>("default");
mpi_exec_ = std::make_unique<flecsi::execution::pool_executor>("mpi");

// execute user code (driver)
(*driver)(argc, argv);
Expand Down
20 changes: 12 additions & 8 deletions flecsi/execution/hpx/context_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cstddef>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <tuple>
Expand Down Expand Up @@ -346,14 +347,16 @@ struct hpx_context_policy_t {
MPI_Datatype origin_type;
MPI_Datatype target_type;

MPI_Type_indexed(compact_origin_lengs[ghost_owner].size(),
MPI_Type_indexed(
static_cast<int>(compact_origin_lengs[ghost_owner].size()),
compact_origin_lengs[ghost_owner].data(),
compact_origin_disps[ghost_owner].data(), metadata.data_type,
&origin_type);
MPI_Type_commit(&origin_type);
metadata.origin_types.insert({ghost_owner, origin_type});

MPI_Type_indexed(compact_target_lengs[ghost_owner].size(),
MPI_Type_indexed(
static_cast<int>(compact_target_lengs[ghost_owner].size()),
compact_target_lengs[ghost_owner].data(),
compact_target_disps[ghost_owner].data(), metadata.data_type,
&target_type);
Expand All @@ -363,8 +366,9 @@ struct hpx_context_policy_t {

auto data = field_data[fid].data();
auto shared_data = data + coloring_info.exclusive * sizeof(T);
MPI_Win_create(shared_data, coloring_info.shared * sizeof(T), sizeof(T),
MPI_INFO_NULL, MPI_COMM_WORLD, &metadata.win);
MPI_Win_create(shared_data, coloring_info.shared * sizeof(T),
static_cast<int>(sizeof(T)), MPI_INFO_NULL, MPI_COMM_WORLD,
&metadata.win);

field_metadata.insert({fid, metadata});
#else
Expand Down Expand Up @@ -840,11 +844,11 @@ struct hpx_context_policy_t {

public:
flecsi::execution::pool_executor & get_default_executor() {
return exec_;
return *exec_;
}

flecsi::execution::pool_executor & get_mpi_executor() {
return mpi_exec_;
return *mpi_exec_;
}

int rank;
Expand Down Expand Up @@ -872,8 +876,8 @@ struct hpx_context_policy_t {
std::map<size_t, task_info_t> task_registry_;

private:
flecsi::execution::pool_executor exec_;
flecsi::execution::pool_executor mpi_exec_;
std::unique_ptr<flecsi::execution::pool_executor> exec_;
std::unique_ptr<flecsi::execution::pool_executor> mpi_exec_;

}; // struct hpx_context_policy_t

Expand Down
77 changes: 42 additions & 35 deletions flecsi/execution/hpx/execution_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <hpx/include/async.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/include/parallel_execution.hpp>
#include <hpx/include/parallel_executors.hpp>
#include <hpx/include/thread_executors.hpp>

#include <cinchlog.h>
Expand All @@ -29,11 +30,11 @@
#include <flecsi/execution/common/launch.h>
#include <flecsi/execution/common/processor.h>
#include <flecsi/execution/context.h>
#include <flecsi/execution/hpx/finalize_handles.h>
#include <flecsi/execution/hpx/future.h>
#include <flecsi/execution/hpx/reduction_wrapper.h>
#include <flecsi/execution/hpx/task_epilog.h>
#include <flecsi/execution/hpx/task_prolog.h>
#include <flecsi/execution/mpi/finalize_handles.h>
#include <flecsi/utils/annotation.h>
#include <flecsi/utils/const_string.h>
#include <flecsi/utils/export_definitions.h>
Expand All @@ -53,7 +54,7 @@ struct executor_u {
*/
template<typename Exec, typename T, typename A>
static decltype(auto) execute(Exec && exec, T function, A && targs) {
auto user_fun = reinterpret_cast<RETURN (*)(ARG_TUPLE)>(function);
auto user_fun = reinterpret_cast<RETURN (*)(std::decay_t<A>)>(function);
return hpx::async(
std::forward<Exec>(exec), user_fun, std::forward<A>(targs));
} // execute_task
Expand All @@ -67,7 +68,7 @@ struct executor_u {
The hpx_execution_policy_t is the backend runtime execution policy
for HPX.
@ingroup mpi-execution
@ingroup hpx-execution
*/

struct FLECSI_EXPORT hpx_execution_policy_t {
Expand All @@ -87,7 +88,7 @@ struct FLECSI_EXPORT hpx_execution_policy_t {
*/

struct runtime_state_t {};
// using runtime_state_t = mpi_runtime_state_t;
// using runtime_state_t = hpx_runtime_state_t;

/*!
Return the runtime state of the calling FleCSI task.
Expand All @@ -102,7 +103,7 @@ struct FLECSI_EXPORT hpx_execution_policy_t {
//--------------------------------------------------------------------------//

/*!
MPI backend task registration. For documentation on this
HPX backend task registration. For documentation on this
method please see task_u::register_task.
*/

Expand Down Expand Up @@ -163,24 +164,27 @@ struct FLECSI_EXPORT hpx_execution_policy_t {

annotation::begin<annotation::execute_task_user>(tname);

hpx_future_u<RETURN> future;
auto processor_type = context_.processor_type<TASK>();
if(processor_type == processor_type_t::mpi) {

{
clog_tag_guard(execution);
clog(info) << "Executing MPI task: " << TASK << std::endl;
}

future = executor_u<RETURN, ARG_TUPLE>::execute(
context_t::instance().get_mpi_executor(), std::move(function),
task_args);
}
else {
future = executor_u<RETURN, ARG_TUPLE>::execute(
context_t::instance().get_default_executor(), std::move(function),
task_args);
}
// hpx_future_u<RETURN> future;
// auto processor_type = context_.processor_type<TASK>();
// if(processor_type == processor_type_t::mpi) {
//
// {
// clog_tag_guard(execution);
// clog(info) << "Executing MPI task: " << TASK << std::endl;
// }
//
// future = executor_u<RETURN, ARG_TUPLE>::execute(
// context_t::instance().get_mpi_executor(), std::move(function),
// task_args);
// }
// else {
// future = executor_u<RETURN, ARG_TUPLE>::execute(
// context_t::instance().get_default_executor(),
// std::move(function), task_args);
// }
hpx_future_u<RETURN> future = executor_u<RETURN, ARG_TUPLE>::execute(
context_t::instance().get_default_executor(), std::move(function),
task_args);

annotation::end<annotation::execute_task_user>();

Expand All @@ -199,22 +203,25 @@ struct FLECSI_EXPORT hpx_execution_policy_t {

if constexpr(REDUCTION != ZERO) {

return future.then([this](hpx_future_u<RETURN> && future) {
MPI_Datatype datatype = flecsi::utils::mpi_typetraits_u<RETURN>::type();
return future
.then([&](hpx_future_u<RETURN> && future) {
MPI_Datatype datatype =
flecsi::utils::mpi_typetraits_u<RETURN>::type();

auto reduction_op = context_.reduction_operations().find(REDUCTION);
auto reduction_op = context_.reduction_operations().find(REDUCTION);

clog_assert(reduction_op != context_.reduction_operations().end(),
"invalid reduction operation");
clog_assert(reduction_op != context_.reduction_operations().end(),
"invalid reduction operation");

const RETURN sendbuf = future.get();
RETURN recvbuf;
const RETURN sendbuf = future.get();
RETURN recvbuf;

MPI_Allreduce(&sendbuf, &recvbuf, 1, datatype, reduction_op->second,
MPI_COMM_WORLD);
MPI_Allreduce(&sendbuf, &recvbuf, 1, datatype, reduction_op->second,
MPI_COMM_WORLD);

return RETURN;
});
return recvbuf;
})
.share();
}

return future;
Expand All @@ -225,7 +232,7 @@ struct FLECSI_EXPORT hpx_execution_policy_t {
//--------------------------------------------------------------------------//

/*!
MPI backend reduction registration. For documentation on this
HPX backend reduction registration. For documentation on this
method please see task_u::register_reduction_operation.
*/

Expand Down
4 changes: 2 additions & 2 deletions flecsi/execution/hpx/reduction_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct reduction_wrapper_u {
for(size_t i{0}; i < *len; ++i) {
TYPE::apply(lhs[i], rhs[i]);
} // for
} // mpi_wrapper
} // hpx_wrapper

/*!
Register the user-defined reduction operator with the runtime.
Expand All @@ -74,7 +74,7 @@ struct reduction_wrapper_u {

// Create the operator and register it with the runtime
MPI_Op mpiop;
MPI_Op_create(mpi_wrapper, true, &mpiop);
MPI_Op_create(hpx_wrapper, true, &mpiop);
reduction_ops[HASH] = mpiop;
} // registration_callback

Expand Down
1 change: 0 additions & 1 deletion flecsi/execution/hpx/task_epilog.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ struct task_epilog_t : public flecsi::utils::tuple_walker_u<task_epilog_t> {
clog_error("Error communicating vertices");

// unpack data
using id_t = std::decay_t<decltype(entities->global_id())>;
constexpr auto num_domains = T::num_domains;

size_t i{0};
Expand Down
8 changes: 4 additions & 4 deletions flecsi/execution/hpx/task_prolog.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ struct task_prolog_t : public flecsi::utils::tuple_walker_u<task_prolog_t> {
execution::context_t::instance().register_field_data(
adj.index_fid, size);
}
adj.indices_buf =
reinterpret_cast<id_t *>(registered_field_data[adj.index_fid].data());
adj.indices_buf = reinterpret_cast<utils::id_t *>(
registered_field_data[adj.index_fid].data());

h.storage.init_connectivity(adj.from_domain, adj.to_domain, adj.from_dim,
adj.to_dim, reinterpret_cast<utils::offset_t *>(adj.offsets_buf),
Expand All @@ -247,8 +247,8 @@ struct task_prolog_t : public flecsi::utils::tuple_walker_u<task_prolog_t> {
iss.index_fid, size);
}
// assign the storage to the buffer
iss.indices_buf =
reinterpret_cast<id_t *>(registered_field_data[iss.index_fid].data());
iss.indices_buf = reinterpret_cast<utils::id_t *>(
registered_field_data[iss.index_fid].data());
// now initialize the index subspace
h.storage.init_index_subspace(iss.index_space, iss.index_subspace,
iss.domain, iss.dim, reinterpret_cast<utils::id_t *>(iss.indices_buf),
Expand Down
4 changes: 2 additions & 2 deletions flecsi/execution/test/reduction_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ min_task(mesh<ro> m, field<rw, rw, ro> v) {
double min{1000000.0};

for(auto c : m.cells(owned)) {
min = std::min(v(c), min);
min = (std::min)(v(c), min);
} // for

return min;
Expand All @@ -71,7 +71,7 @@ max_task(mesh<ro> m, field<rw, rw, ro> v) {
double max{0.0};

for(auto c : m.cells(owned)) {
max = std::max(v(c), max);
max = (std::max)(v(c), max);
} // for

return max;
Expand Down
Loading

0 comments on commit 06fe5e0

Please sign in to comment.