Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gather scatter #52

Draft
wants to merge 58 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e5824d5
Start working on batchgather
pmarguinaud May 13, 2020
8906c08
First working test_batchgather.cc
pmarguinaud May 15, 2020
42ad722
Save
pmarguinaud May 16, 2020
b32d684
Drop view last dimension, create view without check
pmarguinaud May 17, 2020
6c16d78
dropDimension is an external template
pmarguinaud May 18, 2020
726e613
Convert a view to a list of ArrayView<byte,2>
pmarguinaud May 18, 2020
56ffc8a
Use ioFieldDesc
pmarguinaud May 19, 2020
f9a929e
Split into several files; first working gather
pmarguinaud May 19, 2020
6ffc7ca
Refactor
pmarguinaud May 20, 2020
8a38618
Split into several files
pmarguinaud May 20, 2020
f869fd2
Cleaning
pmarguinaud May 20, 2020
1acc57d
Cleaning
pmarguinaud May 20, 2020
1f31855
Add trace
pmarguinaud May 20, 2020
d38948f
Add trace
pmarguinaud May 20, 2020
ac62479
Cleaning
pmarguinaud May 20, 2020
192cf21
Try grep function
pmarguinaud May 20, 2020
fbb4699
Cleaning
pmarguinaud May 21, 2020
8e3671f
Cleaning
pmarguinaud May 21, 2020
b7d59aa
Cleaning
pmarguinaud May 21, 2020
0179045
Cleaning
pmarguinaud May 21, 2020
e894b5a
Cleaning
pmarguinaud May 21, 2020
5fd5172
Cleaning
pmarguinaud May 21, 2020
eb2980d
Cleaning
pmarguinaud May 21, 2020
d319595
Cleaning
pmarguinaud May 21, 2020
af51904
Cleaning
pmarguinaud May 21, 2020
457d403
Cleaning
pmarguinaud May 21, 2020
bb184ad
Cleaning
pmarguinaud May 21, 2020
0efd0d8
Cleaning
pmarguinaud May 21, 2020
61b1dc0
Cleaning
pmarguinaud May 21, 2020
ae522ab
Cleaning
pmarguinaud May 21, 2020
0019e26
Cleaning
pmarguinaud May 21, 2020
ce4fb69
Use size_t in vector.h
pmarguinaud May 21, 2020
cd4ad44
New GatherScatter routines
pmarguinaud May 21, 2020
d615126
Cleaning
pmarguinaud May 21, 2020
aea8531
Scatter works
pmarguinaud May 21, 2020
bd28475
Cleaning
pmarguinaud May 22, 2020
6683127
Add size accessor to distribution
pmarguinaud May 22, 2020
8630dd8
Cleaning
pmarguinaud May 22, 2020
8e8f79d
Add missing header
pmarguinaud May 22, 2020
e135172
Change printf format
pmarguinaud May 22, 2020
4e6926a
Cleaning
pmarguinaud May 22, 2020
064179f
Cleaning
pmarguinaud May 28, 2020
c824bff
Add block dimension
pmarguinaud May 28, 2020
f8aaa39
test_gatherscatter_ngptotxnflevg
pmarguinaud May 28, 2020
4908463
Fiddle with templates
pmarguinaud May 29, 2020
4bac9da
Fiddle with templates
pmarguinaud May 29, 2020
00c9641
Fiddle with templates
pmarguinaud May 29, 2020
81cf89e
Test gather
pmarguinaud May 29, 2020
3f14811
Test gather/scatter options
pmarguinaud May 29, 2020
6932a92
More Atlas traces
pmarguinaud Jun 3, 2020
b1179c5
Prepare for NPROMA blocks
pmarguinaud Jun 3, 2020
412ae85
Prepare for NPROMA blocks
pmarguinaud Jun 3, 2020
15aaf87
Test gather/scatter for (1:NPROMA,1:NFLEVG,1:NGPBLKS)
pmarguinaud Jun 3, 2020
1cec258
Clean simple test case
pmarguinaud Jun 4, 2020
44cba0d
Remove useless test case
pmarguinaud Jun 4, 2020
90753b2
Cleanup
pmarguinaud Jun 4, 2020
6724f9f
Handle other types/ranks
pmarguinaud Jun 4, 2020
196d2d8
Use viewLoop template
pmarguinaud Jun 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/atlas/array/ArrayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace array {
extern template class ArrayView<const TYPE, RANK>;

#define EXPLICIT_TEMPLATE_DECLARATION( RANK ) \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( char, RANK ); \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( int, RANK ); \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( long, RANK ); \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( float, RANK ); \
Expand Down
26 changes: 25 additions & 1 deletion src/atlas/array/DataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace array {
class DataType {
public:
typedef long kind_t;
static const kind_t KIND_INT8 = -1;
static const kind_t KIND_INT32 = -4;
static const kind_t KIND_INT64 = -8;
static const kind_t KIND_REAL32 = 4;
Expand All @@ -30,6 +31,7 @@ class DataType {
template <typename DATATYPE>
static DataType create();

static DataType int8() { return DataType( KIND_INT8 ); }
static DataType int32() { return DataType( KIND_INT32 ); }
static DataType int64() { return DataType( KIND_INT64 ); }
static DataType real32() { return DataType( KIND_REAL32 ); }
Expand All @@ -51,6 +53,7 @@ class DataType {
static bool kind_valid( kind_t );

private:
static std::string int8_str() { return "int8"; }
static std::string int32_str() { return "int32"; }
static std::string int64_str() { return "int64"; }
static std::string real32_str() { return "real32"; }
Expand Down Expand Up @@ -79,6 +82,14 @@ class DataType {
kind_t kind_;
};

template <>
inline std::string DataType::str<char>() {
return int8_str();
}
template <>
inline std::string DataType::str<const char>() {
return int8_str();
}
template <>
inline std::string DataType::str<int>() {
return int32_str();
Expand Down Expand Up @@ -140,6 +151,14 @@ inline std::string DataType::str( const double& ) {
return real64_str();
}
template <>
inline DataType::kind_t DataType::kind<char>() {
return KIND_INT8;
}
template <>
inline DataType::kind_t DataType::kind<const char>() {
return KIND_INT8;
}
template <>
inline DataType::kind_t DataType::kind<int>() {
return KIND_INT32;
}
Expand Down Expand Up @@ -201,7 +220,9 @@ inline DataType::kind_t DataType::kind( const double& ) {
}

inline DataType::kind_t DataType::str_to_kind( const std::string& datatype ) {
if ( datatype == "int32" )
if ( datatype == "int8" )
return KIND_INT8;
else if ( datatype == "int32" )
return KIND_INT32;
else if ( datatype == "int64" )
return KIND_INT64;
Expand All @@ -217,6 +238,8 @@ inline DataType::kind_t DataType::str_to_kind( const std::string& datatype ) {
}
inline std::string DataType::kind_to_str( kind_t kind ) {
switch ( kind ) {
case KIND_INT8:
return int8_str();
case KIND_INT32:
return int32_str();
case KIND_INT64:
Expand All @@ -233,6 +256,7 @@ inline std::string DataType::kind_to_str( kind_t kind ) {
}
inline bool DataType::kind_valid( kind_t kind ) {
switch ( kind ) {
case KIND_INT8:
case KIND_INT32:
case KIND_INT64:
case KIND_UINT64:
Expand Down
3 changes: 3 additions & 0 deletions src/atlas/array/MakeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "atlas/array/IndexView.h"
#include "atlas/array/LocalView.h"
#include "atlas/array_fwd.h"
#include "atlas/util/Config.h"

namespace atlas {
namespace array {
Expand All @@ -25,6 +26,7 @@ extern template IndexView<const idx_t, 2> make_indexview<const idx_t, 2>( Array&
extern template IndexView<const idx_t, 1> make_indexview<idx_t, 1>( const Array& );
extern template IndexView<const idx_t, 2> make_indexview<idx_t, 2>( const Array& );


#define EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( TYPE, RANK ) \
extern template ArrayView<TYPE, RANK> make_view<TYPE, RANK>( Array& ); \
extern template ArrayView<const TYPE, RANK> make_view<const TYPE, RANK>( Array& ); \
Expand All @@ -46,6 +48,7 @@ extern template IndexView<const idx_t, 2> make_indexview<idx_t, 2>( const Array&


#define EXPLICIT_TEMPLATE_DECLARATION( RANK ) \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( char, RANK ) \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( int, RANK ) \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( long, RANK ) \
EXPLICIT_TEMPLATE_DECLARATION_TYPE_RANK( float, RANK ) \
Expand Down
2 changes: 2 additions & 0 deletions src/atlas/array/native/NativeArray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Array* Array::create( DataType datatype, const ArrayShape& shape ) {
return new ArrayT<double>( shape );
case DataType::KIND_REAL32:
return new ArrayT<float>( shape );
case DataType::KIND_INT8:
return new ArrayT<char>( shape );
case DataType::KIND_INT32:
return new ArrayT<int>( shape );
case DataType::KIND_INT64:
Expand Down
4 changes: 4 additions & 0 deletions src/atlas/array/native/NativeArrayView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void ArrayView<Value, Rank>::dump( std::ostream& os ) const {
namespace atlas {
namespace array {
#define EXPLICIT_TEMPLATE_INSTANTIATION( Rank ) \
template class ArrayView<char, Rank>; \
template class ArrayView<const char, Rank>; \
template class ArrayView<int, Rank>; \
template class ArrayView<const int, Rank>; \
template class ArrayView<long, Rank>; \
Expand All @@ -69,10 +71,12 @@ namespace array {
template class ArrayView<const float, Rank>; \
template class ArrayView<double, Rank>; \
template class ArrayView<const double, Rank>; \
template void ArrayView<char, Rank>::assign<true, nullptr>( char const& ); \
template void ArrayView<int, Rank>::assign<true, nullptr>( int const& ); \
template void ArrayView<long, Rank>::assign<true, nullptr>( long const& ); \
template void ArrayView<float, Rank>::assign<true, nullptr>( float const& ); \
template void ArrayView<double, Rank>::assign<true, nullptr>( double const& ); \
template void ArrayView<char, Rank>::assign<true, nullptr>( std::initializer_list<char> const& ); \
template void ArrayView<int, Rank>::assign<true, nullptr>( std::initializer_list<int> const& ); \
template void ArrayView<long, Rank>::assign<true, nullptr>( std::initializer_list<long> const& ); \
template void ArrayView<float, Rank>::assign<true, nullptr>( std::initializer_list<float> const& ); \
Expand Down
1 change: 1 addition & 0 deletions src/atlas/array/native/NativeMakeView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace array {
template ArrayView<const TYPE, RANK> make_device_view<const TYPE, RANK>( const Array& );

#define EXPLICIT_TEMPLATE_INSTATIATION( RANK ) \
EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK( char, RANK ) \
EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK( int, RANK ) \
EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK( long, RANK ) \
EXPLICIT_TEMPLATE_INSTANTIATION_TYPE_RANK( float, RANK ) \
Expand Down
4 changes: 3 additions & 1 deletion src/atlas/functionspace/detail/StructuredColumns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ Field StructuredColumns::createField( const Field& other, const eckit::Configura
// ----------------------------------------------------------------------------
void StructuredColumns::gather( const FieldSet& local_fieldset, FieldSet& global_fieldset ) const {
ATLAS_ASSERT( local_fieldset.size() == global_fieldset.size() );

ATLAS_TRACE_SCOPE ("StructuredColumns::gather")
{
for ( idx_t f = 0; f < local_fieldset.size(); ++f ) {
const Field& loc = local_fieldset[f];
Field& glb = global_fieldset[f];
Expand Down Expand Up @@ -524,6 +525,7 @@ void StructuredColumns::gather( const FieldSet& local_fieldset, FieldSet& global
throw_Exception( "datatype not supported", Here() );
}
}
}
}
// ----------------------------------------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions src/atlas/grid/Distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class Distribution : DOXYGEN_HIDE( public util::ObjectHandle<DistributionImpl> )

const std::string& type() const;

gidx_t size () const
{
return get ()->size ();
}

friend std::ostream& operator<<( std::ostream& os, const Distribution& distribution );
};

Expand Down
7 changes: 5 additions & 2 deletions src/atlas/grid/detail/distribution/DistributionImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ DistributionImpl::DistributionImpl( const Grid& grid ) :
nb_pts_( nb_partitions_, grid.size() ),
max_pts_( grid.size() ),
min_pts_( grid.size() ),
type_( distribution_type( nb_partitions_ ) ) {}
type_( distribution_type( nb_partitions_ ) ),
size_( grid.size ()) {}

DistributionImpl::DistributionImpl( const Grid& grid, const Partitioner& partitioner ) : part_( grid.size() ) {
DistributionImpl::DistributionImpl( const Grid& grid, const Partitioner& partitioner ) : part_( grid.size() ), size_ (grid.size ()) {
partitioner.partition( grid, part_.data() );
nb_partitions_ = partitioner.nb_partitions();

Expand Down Expand Up @@ -99,6 +100,7 @@ DistributionImpl::DistributionImpl( int nb_partitions, idx_t npts, int part[], i
max_pts_ = *std::max_element( nb_pts_.begin(), nb_pts_.end() );
min_pts_ = *std::min_element( nb_pts_.begin(), nb_pts_.end() );
type_ = distribution_type( nb_partitions_ );
size_ = npts;
}

DistributionImpl::DistributionImpl( int nb_partitions, partition_t&& part ) :
Expand All @@ -123,6 +125,7 @@ DistributionImpl::DistributionImpl( int nb_partitions, partition_t&& part ) :
max_pts_ = *std::max_element( nb_pts_.begin(), nb_pts_.end() );
min_pts_ = *std::min_element( nb_pts_.begin(), nb_pts_.end() );
type_ = distribution_type( nb_partitions_ );
size_ = size;
}

DistributionImpl::~DistributionImpl() = default;
Expand Down
3 changes: 3 additions & 0 deletions src/atlas/grid/detail/distribution/DistributionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class DistributionImpl : public util::Object {
idx_t max_pts() const { return max_pts_; }
idx_t min_pts() const { return min_pts_; }

gidx_t size () const { return size_; }

const std::string& type() const { return type_; }

void print( std::ostream& ) const;
Expand All @@ -70,6 +72,7 @@ class DistributionImpl : public util::Object {
idx_t max_pts_;
idx_t min_pts_;
std::string type_;
gidx_t size_;
};

extern "C" {
Expand Down
8 changes: 7 additions & 1 deletion src/atlas/parallel/GatherScatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,21 @@ void GatherScatter::gather( parallel::Field<DATA_TYPE const> lfields[], parallel

/// Pack

pack_send_buffer( lfields[jfield], locmap_, loc_buffer.data() );
ATLAS_TRACE_SCOPE ("Pack")
{
pack_send_buffer( lfields[jfield], locmap_, loc_buffer.data() );
};

/// Gather

ATLAS_TRACE_MPI( GATHER ) { mpi::comm().gatherv( loc_buffer, glb_buffer, glb_counts, glb_displs, root ); }

ATLAS_TRACE_SCOPE ("Unpack")
{
/// Unpack
if ( myproc == root )
unpack_recv_buffer( glbmap_, glb_buffer.data(), gfields[jfield] );
}
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/atlas/util/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ class vector {

T* data() { return data_; }

idx_t size() const { return size_; }
size_t size() const { return size_; }

void assign( idx_t n, const value_type& value ) {
resize( n );
omp::fill( begin(), begin() + n, value );
}

void assign( size_t n, const value_type& value ) {
resize( n );
omp::fill( begin(), begin() + n, value );
}

template <typename Iter>
void assign( const Iter& first, const Iter& last ) {
size_t size = std::distance( first, last );
Expand All @@ -121,11 +126,11 @@ class vector {
}
template <typename size_t>
void resize( size_t size ) {
if ( static_cast<idx_t>( size ) > 0 ) {
if ( size > 0 ) {
if ( capacity_ == 0 ) {
reserve( size );
}
if ( static_cast<idx_t>( size ) > capacity_ ) {
if ( size > capacity_ ) {
ATLAS_NOTIMPLEMENTED;
}
size_ = size;
Expand All @@ -140,8 +145,8 @@ class vector {

private:
value_type* data_{nullptr};
idx_t size_{0};
idx_t capacity_{0};
size_t size_{0};
size_t capacity_{0};
};

} // namespace atlas
1 change: 1 addition & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ add_subdirectory( projection )
add_subdirectory( grid )
add_subdirectory( mesh )
add_subdirectory( functionspace )
add_subdirectory( gatherscatter )
add_subdirectory( io )
add_subdirectory( numerics )
add_subdirectory( trans )
Expand Down
20 changes: 20 additions & 0 deletions src/tests/gatherscatter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# (C) Copyright 2013 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.

ecbuild_add_test( TARGET test_gatherscatter
SOURCES test_gatherscatter.cc ioFieldDesc.cc GatherScatter.cc
LIBS atlas
ENVIRONMENT ${ATLAS_TEST_ENVIRONMENT}
)

ecbuild_add_test( TARGET test_arrayViewHelpers
SOURCES test_arrayViewHelpers.cc ioFieldDesc.cc
LIBS atlas
ENVIRONMENT ${ATLAS_TEST_ENVIRONMENT}
)

Loading