| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Rapid Optimization Library (ROL) Package |
| 4 |
// |
| 5 |
// Copyright 2014 NTESS and the ROL contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef ROL_PINTVECTORCOMMUNICATION_STDTPETRACOMPOSITEVECTOR_H |
| 11 |
#define ROL_PINTVECTORCOMMUNICATION_STDTPETRACOMPOSITEVECTOR_H |
| 12 |
|
| 13 |
#include "ROL_PinTVectorCommunication.hpp" |
| 14 |
#include "ROL_PinTVectorCommunication_StdVector.hpp" |
| 15 |
#include "ROL_PinTVectorCommunication_Tpetra.hpp" |
| 16 |
|
| 17 |
/** @ingroup la_group |
| 18 |
\class ROL::PinTVector |
| 19 |
\brief Defines a parallel in time vector. |
| 20 |
*/ |
| 21 |
|
| 22 |
namespace ROL { |
| 23 |
|
| 24 |
template <class Real> |
| 25 |
class PinTVectorCommunication_StdTpetraComposite : public PinTVectorCommunication<Real> { |
| 26 |
|
| 27 |
PinTVectorCommunication_StdVector<Real> stdComm_; |
| 28 |
PinTVectorCommunication_Tpetra<Real> tpetraComm_; |
| 29 |
|
| 30 |
public: |
| 31 |
|
| 32 |
virtual ~PinTVectorCommunication_StdTpetraComposite() {} |
| 33 |
|
| 34 |
/** |
| 35 |
* \brief Send a vector to a neighboring processor. |
| 36 |
*/ |
| 37 |
void send(MPI_Comm comm,int rank,Vector<Real> & source,int tag=0) const override |
| 38 |
{ |
| 39 |
if(isTpetra(source)) { |
| 40 |
tpetraComm_.send(comm,rank,source,tag); |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
if(isStd(source)) { |
| 45 |
stdComm_.send(comm,rank,source,tag); |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
assert(false); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* \brief Recieve a vector from a neighboring processor. Uses blocking communication. |
| 54 |
*/ |
| 55 |
void recv(MPI_Comm comm,int rank,Vector<Real> & dest,int tag=0) const override |
| 56 |
{ |
| 57 |
if(isTpetra(dest)) { |
| 58 |
tpetraComm_.recv(comm,rank,dest,tag); |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
if(isStd(dest)) { |
| 63 |
stdComm_.recv(comm,rank,dest,tag); |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
assert(false); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* \brief Recieve a vector from a neighboring processor. Uses blocking communication. |
| 72 |
*/ |
| 73 |
void recvSumInto(MPI_Comm comm,int rank,Vector<Real> & dest,int tag=0) const override |
| 74 |
{ |
| 75 |
if(isTpetra(dest)) { |
| 76 |
tpetraComm_.recvSumInto(comm,rank,dest,tag); |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
if(isStd(dest)) { |
| 81 |
stdComm_.recvSumInto(comm,rank,dest,tag); |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
assert(false); |
| 86 |
} |
| 87 |
|
| 88 |
bool isTpetra(const Vector<Real> & vec) const |
| 89 |
{ |
| 90 |
auto tpetraVec = dynamicPtrCast<const TpetraMultiVector<Real>>(makePtrFromRef(vec)); |
| 91 |
|
| 92 |
return tpetraVec!=ROL::nullPtr; |
| 93 |
} |
| 94 |
|
| 95 |
bool isStd(const Vector<Real> & vec) const |
| 96 |
{ |
| 97 |
auto stdVec = dynamicPtrCast<const StdVector<Real>>(makePtrFromRef(vec)); |
| 98 |
|
| 99 |
return stdVec!=ROL::nullPtr; |
| 100 |
} |
| 101 |
}; |
| 102 |
|
| 103 |
} // namespace ROL |
| 104 |
|
| 105 |
#endif |