| 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_TPETRA_H |
| 11 |
#define ROL_PINTVECTORCOMMUNICATION_TPETRA_H |
| 12 |
|
| 13 |
#include "mpi.h" |
| 14 |
|
| 15 |
#include "ROL_PinTVectorCommunication.hpp" |
| 16 |
#include "ROL_StdVector.hpp" |
| 17 |
#include "ROL_TpetraMultiVector.hpp" |
| 18 |
#include "Tpetra_Access.hpp" |
| 19 |
|
| 20 |
/** @ingroup la_group |
| 21 |
\class ROL::PinTVector |
| 22 |
\brief Defines a parallel in time vector. |
| 23 |
*/ |
| 24 |
|
| 25 |
namespace ROL { |
| 26 |
|
| 27 |
template <class Real> |
| 28 |
class PinTVectorCommunication_Tpetra : public PinTVectorCommunication<Real> { |
| 29 |
public: |
| 30 |
/** |
| 31 |
* \brief Send a vector to a neighboring processor. |
| 32 |
*/ |
| 33 |
void send(MPI_Comm comm,int rank,Vector<Real> & source,int tag=0) const override |
| 34 |
{ |
| 35 |
auto & tp_source = *dynamic_cast<TpetraMultiVector<Real>&>(source).getVector(); |
| 36 |
auto view = tp_source.getLocalViewHost(Tpetra::Access::ReadOnly); |
| 37 |
|
| 38 |
// int myRank = -1; |
| 39 |
// MPI_Comm_rank(comm, &myRank); |
| 40 |
|
| 41 |
MPI_Send(const_cast<Real*>(&view(0,0)),int(view.extent(0)*view.extent(1)),MPI_DOUBLE,rank,tag,comm); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* \brief Recieve a vector from a neighboring processor. Uses blocking communication. |
| 46 |
*/ |
| 47 |
void recv(MPI_Comm comm,int rank,Vector<Real> & dest,int tag=0) const override |
| 48 |
{ |
| 49 |
auto & tp_dest = *dynamic_cast<TpetraMultiVector<Real>&>(dest).getVector(); |
| 50 |
auto view = tp_dest.getLocalViewHost(Tpetra::Access::ReadWrite); |
| 51 |
|
| 52 |
// int myRank = -1; |
| 53 |
// MPI_Comm_rank(comm, &myRank); |
| 54 |
|
| 55 |
MPI_Recv(&view(0,0),int(view.extent(0)*view.extent(1)),MPI_DOUBLE,rank,tag,comm,MPI_STATUS_IGNORE); |
| 56 |
|
| 57 |
// tp_source.template sync<Kokkos::DeviceSpace>(); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* \brief Recieve a vector from a neighboring processor. Uses blocking communication. |
| 62 |
*/ |
| 63 |
void recvSumInto(MPI_Comm comm,int rank,Vector<Real> & dest,int tag=0) const override |
| 64 |
{ |
| 65 |
auto & tp_dest = *dynamic_cast<TpetraMultiVector<Real>&>(dest).getVector(); |
| 66 |
auto view = tp_dest.getLocalViewHost(Tpetra::Access::ReadWrite); |
| 67 |
|
| 68 |
int myRank = -1; |
| 69 |
MPI_Comm_rank(comm, &myRank); |
| 70 |
|
| 71 |
assert(view.extent(1)==1); |
| 72 |
|
| 73 |
std::vector<Real> buffer(view.extent(0)*view.extent(1),0.0); |
| 74 |
MPI_Recv(&buffer[0],int(buffer.size()),MPI_DOUBLE,rank,tag,comm,MPI_STATUS_IGNORE); |
| 75 |
|
| 76 |
for(size_t i=0;i<buffer.size();i++) |
| 77 |
view(i,0) += buffer[i]; |
| 78 |
} |
| 79 |
}; |
| 80 |
|
| 81 |
} // namespace ROL |
| 82 |
|
| 83 |
#endif |