Coupler.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
/****************************************************************************/
/* Paso: coupler */
/****************************************************************************/
/* Author: Lutz Gross, l.gross@uq.edu.au */
/****************************************************************************/
#ifndef __PASO_COUPLER_H__
#define __PASO_COUPLER_H__
#include "Paso.h"
#include "PasoException.h"
#include "SharedComponents.h"
namespace paso {
struct Connector;
typedef boost::shared_ptr<Connector> Connector_ptr;
typedef boost::shared_ptr<const Connector> const_Connector_ptr;
template<typename Scalar> struct Coupler;
template<typename T> using Coupler_ptr = boost::shared_ptr<Coupler<T> >;
template<typename T> using const_Coupler_ptr = boost::shared_ptr<const Coupler<T> >;
PASO_DLL_API
struct Connector
{
SharedComponents_ptr send;
SharedComponents_ptr recv;
Connector(SharedComponents_ptr s, SharedComponents_ptr r)
{
if (s->local_length != r->local_length) {
throw PasoException("Connector: local length of send and recv "
"SharedComponents must match.");
}
send = s;
recv = r;
}
inline Connector_ptr copy() const { return unroll(1); }
inline Connector_ptr unroll(index_t block_size) const
{
SharedComponents_ptr new_send_shcomp, new_recv_shcomp;
Connector_ptr out;
if (block_size > 1) {
new_send_shcomp.reset(new SharedComponents(send->local_length,
send->neighbour, send->shared, send->offsetInShared,
block_size, 0));
new_recv_shcomp.reset(new SharedComponents(recv->local_length,
recv->neighbour, recv->shared, recv->offsetInShared,
block_size, 0));
} else {
new_send_shcomp = send;
new_recv_shcomp = recv;
}
out.reset(new Connector(new_send_shcomp, new_recv_shcomp));
return out;
}
//inline debug() const
//{
// for (int i=0; i<recv->neighbour.size(); ++i)
// printf("Coupler: %d receive %d data at %d from %d\n",
// s->mpi_info->rank,recv->offsetInShared[i+1]-recv->offsetInShared[i],
// recv->offsetInShared[i],recv->neighbour[i]);
// for (int i=0; i<send->neighbour.size(); ++i)
// printf("Coupler: %d send %d data at %d to %d\n",
// s->mpi_info->rank,send->offsetInShared[i+1]-send->offsetInShared[i],
// send->offsetInShared[i],send->neighbour[i]);
//}
};
template<typename Scalar>
struct Coupler
{
Coupler(const_Connector_ptr, dim_t blockSize, escript::JMPI mpiInfo);
~Coupler();
void startCollect(const Scalar* in);
Scalar* finishCollect();
void copyAll(Coupler_ptr<Scalar> target) const;
void fillOverlap(dim_t n, Scalar* x);
void max(dim_t n, Scalar* x);
inline const Scalar* borrowLocalData() const { return data; }
inline const Scalar* borrowRemoteData() const { return recv_buffer; }
inline dim_t getNumSharedComponents() const
{
return connector->send->numSharedComponents;
}
inline dim_t getNumOverlapComponents() const
{
return connector->recv->numSharedComponents;
}
inline dim_t getNumSharedValues() const
{
return getNumSharedComponents() * block_size;
}
inline dim_t getNumOverlapValues() const
{
return getNumOverlapComponents() * block_size;
}
inline dim_t getLocalLength() const
{
return connector->send->local_length;
}
const_Connector_ptr connector;
dim_t block_size;
bool in_use;
// unmanaged pointer to data to be sent
Scalar* data;
Scalar* send_buffer;
Scalar* recv_buffer;
MPI_Request* mpi_requests;
MPI_Status* mpi_stati;
escript::JMPI mpi_info;
};
} // namespace paso
#endif // __PASO_COUPLER_H__
speckley::Brick::gradient_order3
void gradient_order3(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:98
MPI_Status
int MPI_Status
Definition: EsysMPI.h:45
paso::Coupler::block_size
dim_t block_size
Definition: Coupler.h:155
paso::Connector::recv
SharedComponents_ptr recv
Definition: Coupler.h:64
speckley::Brick::reduction_order2
void reduction_order2(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:39
speckley::Brick::integral_order2
void integral_order2(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:39
speckley::Brick::gradient_order2
void gradient_order2(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:39
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:79
paso::const_Coupler_ptr
boost::shared_ptr< const Coupler< T > > const_Coupler_ptr
Definition: Coupler.h:58
paso::Coupler::borrowLocalData
const Scalar * borrowLocalData() const
Definition: Coupler.h:125
speckley::Brick::reduction_order10
void reduction_order10(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:248
paso::Coupler::getNumSharedValues
dim_t getNumSharedValues() const
Definition: Coupler.h:139
speckley::Brick::gradient_order6
void gradient_order6(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:282
paso::Coupler::borrowRemoteData
const Scalar * borrowRemoteData() const
Definition: Coupler.h:127
paso::Coupler::copyAll
void copyAll(Coupler_ptr< Scalar > target) const
Definition: Coupler.cpp:146
escript::Data::requireWrite
void requireWrite()
Ensures data is ready for write access. This means that the data will be resolved if lazy and will be...
Definition: Data.cpp:1239
paso::const_Connector_ptr
boost::shared_ptr< const Connector > const_Connector_ptr
Definition: Coupler.h:54
INDEX4
#define INDEX4(_X1_, _X2_, _X3_, _X4_, _N1_, _N2_, _N3_)
Definition: index.h:27
speckley::Brick::gradient_order10
void gradient_order10(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:544
paso::Coupler::getNumOverlapValues
dim_t getNumOverlapValues() const
Definition: Coupler.h:144
speckley::Brick::reduction_order4
void reduction_order4(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:92
speckley::Brick::gradient_order7
void gradient_order7(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:346
escript::Data::getSampleDataRO
const DataTypes::real_t * getSampleDataRO(DataTypes::RealVectorType::size_type sampleNo, DataTypes::real_t dummy=0) const
Return the sample data for the given sample no. Please do not use this unless you NEED to access samp...
Definition: Data.h:1989
paso::Coupler
Definition: Coupler.h:56
speckley::Brick::integral_order6
void integral_order6(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:156
speckley::Brick::integral_order5
void integral_order5(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:127
speckley::Brick::gradient_order4
void gradient_order4(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:157
speckley::Brick::integral_order3
void integral_order3(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:69
paso::Coupler::connector
const_Connector_ptr connector
Definition: Coupler.h:154
speckley::Brick::reduction_order3
void reduction_order3(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:66
paso::Coupler::send_buffer
Scalar * send_buffer
Definition: Coupler.h:160
paso::SharedComponents
Definition: SharedComponents.h:55
paso::Connector::copy
Connector_ptr copy() const
creates a copy
Definition: Coupler.h:77
INDEX5
#define INDEX5(_X1_, _X2_, _X3_, _X4_, _X5_, _N1_, _N2_, _N3_, _N4_)
Definition: index.h:29
escript::Data::getDataPointSize
int getDataPointSize() const
Return the size of the data point. It is the product of the data point shape dimensions.
Definition: Data.cpp:1360
speckley::Brick::integral_order4
void integral_order4(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:98
paso::Coupler::mpi_info
escript::JMPI mpi_info
Definition: Coupler.h:164
speckley::Brick::integral_order7
void integral_order7(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:185
speckley
Definition: AbstractAssembler.cpp:19
paso::Coupler::startCollect
void startCollect(const Scalar *in)
Definition: Coupler.cpp:81
paso::Coupler::mpi_stati
MPI_Status * mpi_stati
Definition: Coupler.h:163
Paso.h
escript::Data
Data represents a collection of datapoints.
Definition: Data.h:64
paso::Coupler::Coupler
Coupler(const_Connector_ptr, dim_t blockSize, escript::JMPI mpiInfo)
Definition: Coupler.cpp:45
INDEX3
#define INDEX3(_X1_, _X2_, _X3_, _N1_, _N2_)
Definition: index.h:25
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:93
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:72
escript::Data::getSampleDataRW
DataTypes::real_t * getSampleDataRW(DataTypes::RealVectorType::size_type sampleNo, DataTypes::real_t dummy=0)
Return the sample data for the given sample no. Please do not use this unless you NEED to access samp...
Definition: Data.h:1954
paso::Coupler_ptr
boost::shared_ptr< Coupler< T > > Coupler_ptr
Definition: Coupler.h:57
speckley::Brick::gradient_order8
void gradient_order8(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:411
speckley::Brick::reduction_order7
void reduction_order7(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:170
paso::Coupler::max
void max(dim_t n, Scalar *x)
paso::Coupler::finishCollect
Scalar * finishCollect()
Definition: Coupler.cpp:129
paso::Coupler::getNumSharedComponents
dim_t getNumSharedComponents() const
Definition: Coupler.h:129
speckley::Brick::integral_order8
void integral_order8(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:214
paso::Coupler::mpi_requests
MPI_Request * mpi_requests
Definition: Coupler.h:162
paso::Coupler::~Coupler
~Coupler()
Definition: Coupler.cpp:70
paso::SharedComponents_ptr
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:50
paso::Coupler::in_use
bool in_use
Definition: Coupler.h:156
SharedComponents.h
speckley::Brick::integral_order9
void integral_order9(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:243
paso::Connector::unroll
Connector_ptr unroll(index_t block_size) const
Definition: Coupler.h:79
speckley::Brick::m_dx
double m_dx[3]
grid spacings / cell sizes of domain
Definition: speckley/src/Brick.h:386
MPI_DOUBLE
#define MPI_DOUBLE
Definition: EsysMPI.h:47
paso::Coupler::getNumOverlapComponents
dim_t getNumOverlapComponents() const
Definition: Coupler.h:134
speckley::Brick::gradient_order9
void gradient_order9(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:477
paso::PasoException
PasoException exception class.
Definition: PasoException.h:47
paso::Coupler::recv_buffer
Scalar * recv_buffer
Definition: Coupler.h:161
speckley::Brick::integral_order10
void integral_order10(std::vector< Scalar > &, const escript::Data &) const
Definition: BrickIntegrals.cpp:272
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:88
speckley::Brick::m_NE
dim_t m_NE[3]
number of elements for this rank in each dimension including shared
Definition: speckley/src/Brick.h:392
speckley::Brick::gradient_order5
void gradient_order5(escript::Data &, const escript::Data &) const
Definition: BrickGradients.cpp:219
paso::Coupler::data
Scalar * data
Definition: Coupler.h:159
PASO_DLL_API
#define PASO_DLL_API
Definition: Paso.h:60
speckley::Brick::reduction_order5
void reduction_order5(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:118
paso::Coupler::fillOverlap
void fillOverlap(dim_t n, Scalar *x)
Definition: Coupler.cpp:164
paso::Connector::send
SharedComponents_ptr send
Definition: Coupler.h:63
speckley::Brick::reduction_order6
void reduction_order6(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:144
MPI_Request
int MPI_Request
Definition: EsysMPI.h:43
PasoException.h
paso::Connector_ptr
boost::shared_ptr< Connector > Connector_ptr
Definition: Coupler.h:52
escript::Data::actsExpanded
bool actsExpanded() const
Return true if this Data is expanded or resolves to expanded. That is, if it has a separate value for...
Definition: Data.cpp:1118
Coupler.h
paso
Definition: BiCGStab.cpp:26
escript::DataTypes::cplx_t
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:82
escript::Scalar
Data Scalar(double value, const FunctionSpace &what, bool expanded)
A collection of factory functions for creating Data objects which contain data points of various shap...
Definition: DataFactory.cpp:63
paso::Connector::Connector
Connector(SharedComponents_ptr s, SharedComponents_ptr r)
Definition: Coupler.h:66
speckley::Brick::reduction_order9
void reduction_order9(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:222
paso::Coupler::getLocalLength
dim_t getLocalLength() const
Definition: Coupler.h:149
speckley::Brick::reduction_order8
void reduction_order8(const escript::Data &, escript::Data &) const
Definition: BrickReductions.cpp:196