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> >;
struct PASO_DLL_API 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 PASO_DLL_API 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__
MPI_Request
int MPI_Request
Definition: EsysMPI.h:45
MPI_Status
int MPI_Status
Definition: EsysMPI.h:47
PasoException.h
Paso.h
SharedComponents.h
paso::PasoException
PasoException exception class.
Definition: PasoException.h:34
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
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:49
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:74
paso
Definition: BiCGStab.cpp:25
paso::const_Coupler_ptr
boost::shared_ptr< const Coupler< T > > const_Coupler_ptr
Definition: Coupler.h:44
paso::const_Connector_ptr
boost::shared_ptr< const Connector > const_Connector_ptr
Definition: Coupler.h:40
paso::Connector_ptr
boost::shared_ptr< Connector > Connector_ptr
Definition: Coupler.h:38
paso::SharedComponents_ptr
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:36
paso::Coupler_ptr
boost::shared_ptr< Coupler< T > > Coupler_ptr
Definition: Coupler.h:43
PASO_DLL_API
#define PASO_DLL_API
Definition: paso/src/system_dep.h:29
paso::Connector
Definition: Coupler.h:47
paso::Connector::Connector
Connector(SharedComponents_ptr s, SharedComponents_ptr r)
Definition: Coupler.h:51
paso::Connector::copy
Connector_ptr copy() const
creates a copy
Definition: Coupler.h:62
paso::Connector::recv
SharedComponents_ptr recv
Definition: Coupler.h:49
paso::Connector::unroll
Connector_ptr unroll(index_t block_size) const
Definition: Coupler.h:64
paso::Connector::send
SharedComponents_ptr send
Definition: Coupler.h:48
paso::Coupler
Definition: Coupler.h:100
paso::Coupler::getNumOverlapValues
dim_t getNumOverlapValues() const
Definition: Coupler.h:129
paso::Coupler::max
void max(dim_t n, Scalar *x)
paso::Coupler::recv_buffer
Scalar * recv_buffer
Definition: Coupler.h:146
paso::Coupler::getLocalLength
dim_t getLocalLength() const
Definition: Coupler.h:134
paso::Coupler::mpi_info
escript::JMPI mpi_info
Definition: Coupler.h:149
paso::Coupler::connector
const_Connector_ptr connector
Definition: Coupler.h:139
paso::Coupler::in_use
bool in_use
Definition: Coupler.h:141
paso::Coupler::mpi_requests
MPI_Request * mpi_requests
Definition: Coupler.h:147
paso::Coupler::data
Scalar * data
Definition: Coupler.h:144
paso::Coupler::borrowLocalData
const Scalar * borrowLocalData() const
Definition: Coupler.h:110
paso::Coupler::getNumOverlapComponents
dim_t getNumOverlapComponents() const
Definition: Coupler.h:119
paso::Coupler::borrowRemoteData
const Scalar * borrowRemoteData() const
Definition: Coupler.h:112
paso::Coupler::mpi_stati
MPI_Status * mpi_stati
Definition: Coupler.h:148
paso::Coupler::send_buffer
Scalar * send_buffer
Definition: Coupler.h:145
paso::Coupler::getNumSharedComponents
dim_t getNumSharedComponents() const
Definition: Coupler.h:114
paso::Coupler::getNumSharedValues
dim_t getNumSharedValues() const
Definition: Coupler.h:124
paso::Coupler::block_size
dim_t block_size
Definition: Coupler.h:140
paso::SharedComponents
Definition: SharedComponents.h:41