Skip to content

Commit

Permalink
fix C++ unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrdar committed Nov 8, 2023
1 parent 5a4354b commit 7dd8d43
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/atlas/redistribution/Redistribution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Redistribution::Redistribution(const FunctionSpace& sourceFunctionSpace, const F
}()) {}

void Redistribution::execute(const Field& source, Field& target) const {
get()->execute(source.get(), target.get());
get()->execute(source, target);
return;
}

void Redistribution::execute(const FieldSet& source, FieldSet& target) const {
get()->execute(source.get(), target.get());
get()->execute(source, target);
return;
}

Expand Down
22 changes: 11 additions & 11 deletions src/atlas/redistribution/detail/RedistributeGeneric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ void RedistributeGeneric::do_setup() {
std::tie(targetLocalIdx_, targetDisps_) = getUidIntersection(mpi_comm_, targetUidVec, sourceGlobalUids, sourceGlobalDisps);
}

void RedistributeGeneric::execute(const field::FieldImpl* sf, field::FieldImpl* tf) const {
const field::FieldImpl& sourceField = *sf;
field::FieldImpl& targetField = *tf;
void RedistributeGeneric::execute(const Field& sourceField, Field& targetField) const {
//Check functionspaces match.
ATLAS_ASSERT(sourceField.functionspace().type() == source().type());
ATLAS_ASSERT(targetField.functionspace().type() == target().type());
Expand All @@ -301,21 +299,23 @@ void RedistributeGeneric::execute(const field::FieldImpl* sf, field::FieldImpl*
}

// Perform redistribution.
do_execute(sf, tf);
do_execute(sourceField, targetField);
}

void RedistributeGeneric::execute(const field::FieldSetImpl* sourceFieldSet, field::FieldSetImpl* targetFieldSet) const {
void RedistributeGeneric::execute(const FieldSet& sourceFieldSet, FieldSet& targetFieldSet) const {
// Check field set sizes match.
ATLAS_ASSERT(sourceFieldSet->size() == targetFieldSet->size());

// Redistribute fields.
for (idx_t i = 0; i < sourceFieldSet->size(); ++i) {
execute(&sourceFieldSet[i], &targetFieldSet[i]);
}
auto targetFieldSetIt = targetFieldSet->begin();
std::for_each(sourceFieldSet->cbegin(), sourceFieldSet->cend(), [&](const Field& sourceField) {
execute(sourceField, *targetFieldSetIt++);
return;
});
}

// Determine datatype.
void RedistributeGeneric::do_execute(const field::FieldImpl* sourceField, field::FieldImpl* targetField) const {
void RedistributeGeneric::do_execute(const Field& sourceField, Field& targetField) const {
// Available datatypes defined in array/LocalView.cc
switch (sourceField->datatype().kind()) {
case array::DataType::KIND_REAL64: {
Expand All @@ -338,7 +338,7 @@ void RedistributeGeneric::do_execute(const field::FieldImpl* sourceField, field:

// Determine rank.
template <typename Value>
void RedistributeGeneric::do_execute(const field::FieldImpl* sourceField, field::FieldImpl* targetField) const {
void RedistributeGeneric::do_execute(const Field& sourceField, Field& targetField) const {
// Available ranks defined in array/LocalView.cc
switch (sourceField->rank()) {
case 1: {
Expand Down Expand Up @@ -376,7 +376,7 @@ void RedistributeGeneric::do_execute(const field::FieldImpl* sourceField, field:

// Perform redistribution.
template <typename Value, int Rank>
void RedistributeGeneric::do_execute(const field::FieldImpl* sourceField, field::FieldImpl* targetField) const {
void RedistributeGeneric::do_execute(const Field& sourceField, Field& targetField) const {
// Get array views.
auto sourceView = array::make_view<Value, Rank>(*sourceField);
auto targetView = array::make_view<Value, Rank>(*targetField);
Expand Down
10 changes: 5 additions & 5 deletions src/atlas/redistribution/detail/RedistributeGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class RedistributeGeneric : public RedistributionImpl {

void do_setup() override;

void execute(const field::FieldImpl* source, field::FieldImpl* target) const override;
void execute(const Field& source, Field& target) const override;

void execute(const field::FieldSetImpl* source, field::FieldSetImpl* target) const override;
void execute(const FieldSet& source, FieldSet& target) const override;

private:
// Determine datatype.
void do_execute(const field::FieldImpl* source, field::FieldImpl* target) const;
void do_execute(const Field& source, Field& target) const;
// Determine rank.
template <typename Value>
void do_execute(const field::FieldImpl* source, field::FieldImpl* target) const;
void do_execute(const Field& source, Field& target) const;
// Perform redistribution.
template <typename Value, int Rank>
void do_execute(const field::FieldImpl* source, field::FieldImpl* target) const;
void do_execute(const Field& source, Field& target) const;

// Local indices to send to each PE
std::vector<idx_t> sourceLocalIdx_{};
Expand Down
19 changes: 7 additions & 12 deletions src/atlas/redistribution/detail/RedistributeStructuredColumns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ void RedistributeStructuredColumns::do_setup() {
return;
}

void RedistributeStructuredColumns::execute(const field::FieldImpl* sf, field::FieldImpl* tf) const {
const field::FieldImpl& sourceField = *sf;
field::FieldImpl& targetField = *tf;
void RedistributeStructuredColumns::execute(const Field& sourceField, Field& targetField) const {
// Assert that fields are defined on StructuredColumns.
ATLAS_ASSERT(functionspace::StructuredColumns(sourceField.functionspace()));
ATLAS_ASSERT(functionspace::StructuredColumns(targetField.functionspace()));
Expand Down Expand Up @@ -167,18 +165,15 @@ void RedistributeStructuredColumns::execute(const field::FieldImpl* sf, field::F
return;
}

void RedistributeStructuredColumns::execute(const field::FieldSetImpl* sourceFieldSet, field::FieldSetImpl* targetFieldSet) const {
void RedistributeStructuredColumns::execute(const FieldSet& sourceFieldSet, FieldSet& targetFieldSet) const {
// Check that both FieldSets are the same size.
ATLAS_ASSERT(sourceFieldSet->size() == targetFieldSet->size());

auto targetFieldSetIt = targetFieldSet->begin();
for (int i = 0; i < sourceFieldSet->size(); i++) {
execute(&sourceFieldSet[i], &targetFieldSet[i]);
}
//std::for_each(sourceFieldSet->cbegin(), sourceFieldSet->cend(), [&](const field::FieldImpl* sourceField) {
// execute(sourceField, targetFieldSetIt++);
// return;
//});
std::for_each(sourceFieldSet->cbegin(), sourceFieldSet->cend(), [&](const Field& sourceField) {
execute(sourceField, *targetFieldSetIt++);
return;
});

return;
}
Expand All @@ -188,7 +183,7 @@ void RedistributeStructuredColumns::execute(const field::FieldSetImpl* sourceFie
//========================================================================

template <typename fieldType>
void RedistributeStructuredColumns::do_execute(const field::FieldImpl& sourceField, field::FieldImpl& targetField) const {
void RedistributeStructuredColumns::do_execute(const Field& sourceField, Field& targetField) const {
// Make Atlas view objects.
const auto sourceView = array::make_view<fieldType, 2>(sourceField);
auto targetView = array::make_view<fieldType, 2>(targetField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RedistributeStructuredColumns : public RedistributionImpl {
///
/// \param[in] source input field matching sourceFunctionSpace.
/// \param[out] target output field matching targetFunctionSpace.
void execute(const field::FieldImpl* source, field::FieldImpl* target) const override;
void execute(const Field& source, Field& target) const override;

/// \brief Redistributes source field set to target fields set.
///
Expand All @@ -72,12 +72,12 @@ class RedistributeStructuredColumns : public RedistributionImpl {
///
/// \param[in] source input field set.
/// \param[out] target output field set.
void execute(const field::FieldSetImpl* source, field::FieldSetImpl* target) const override;
void execute(const FieldSet& source, FieldSet& target) const override;

private:
// Generic execute call to handle different field types.
template <typename fieldType>
void do_execute(const field::FieldImpl& source, field::FieldImpl& target) const;
void do_execute(const Field& source, Field& target) const;

// FunctionSpaces recast to StructuredColumns.
functionspace::StructuredColumns source_;
Expand Down
8 changes: 4 additions & 4 deletions src/atlas/redistribution/detail/RedistributionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace atlas {
namespace field {
class FieldImpl;
class FieldSetImpl;
class Field;
class FieldSet;
}
namespace functionspace {
class FunctionSpace;
Expand Down Expand Up @@ -46,10 +46,10 @@ class RedistributionImpl : public util::Object {
virtual std::string type() const = 0;

/// \brief Maps source field to target field.
virtual void execute(const field::FieldImpl* source, field::FieldImpl* target) const = 0;
virtual void execute(const Field& source, Field& target) const = 0;

/// \brief Maps source field set to target field set.
virtual void execute(const field::FieldSetImpl* source, field::FieldSetImpl* target) const = 0;
virtual void execute(const FieldSet& source, FieldSet& target) const = 0;

/// \brief Get const reference to source function space.
const FunctionSpace& source() const;
Expand Down
9 changes: 7 additions & 2 deletions src/atlas/redistribution/detail/RedistributionInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "RedistributionImpl.h"
#include "RedistributionInterface.h"

#include "atlas/functionspace/FunctionSpace.h"
#include "atlas/redistribution/detail/RedistributionImplFactory.h"

namespace atlas {
Expand All @@ -32,13 +33,17 @@ detail::RedistributionImpl* atlas__Redistribution__new__config(
std::string type = detail::RedistributeGeneric::static_type();
config->get("type", type);
auto redist = redistribution::detail::RedistributionImplFactory::build(type);
redist->setup(fspace1, fspace2);
FunctionSpace fs1(fspace1);
FunctionSpace fs2(fspace2);
redist->setup(fs1, fs2);
return redist;
}

void atlas__Redistribution__execute(
const detail::RedistributionImpl* This, const field::FieldImpl* field_1, field::FieldImpl* field_2) {
This->execute(field_1, field_2);
Field f1(field_1);
Field f2(field_2);
This->execute(f1, f2);
}

const functionspace::FunctionSpaceImpl* atlas__Redistribution__source(
Expand Down
10 changes: 5 additions & 5 deletions src/atlas/redistribution/detail/RedistributionInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class Configuration;
}

namespace atlas {
namespace functionspace{
class FunctionSpaceImpl;
namespace functionspace {
class FunctionSpace;
}
namespace field{
class FieldImpl;
class FieldSetImpl;
namespace field {
class Field;
class FieldSet;
}
} // namespace atlas

Expand Down

0 comments on commit 7dd8d43

Please sign in to comment.