[Trilinos-Users] Best practice to modify elements of a Tpetra::Vector with openmp?

Wen Yan wenyan4work at gmail.com
Fri May 12 17:36:42 EDT 2017

Hi Trilinos,

I was wondering what is the best practice to modify the elements of a Tpetra::Vector or a Tpetra::MultiVector. The document mentioned that ArrayRCP<T> is not thread safe, and suggested using Kokkos::View, but not much details are discussed. I am using Kokkos::OpenMP as the execution backend of Tpetra.

Assume xRcp is Teuchos::Rcp<Tpetra::MultiVector>

To use Kokkos::View, I can do this, but it is awkward and the Kokkos documentation does not include much useful information about these:

//   auto x_2d = xRcp->getLocalView<Kokkos::HostSpace>();
//   auto x_1d = Kokkos::subview(x_2d, Kokkos::ALL(), 0);
//   xRcp->modify<Kokkos::HostSpace>();
//   const size_t localLength = vecRcp->getLocalLength();
//   #pragma omp parallel for
//   for (size_t k = 0; k < localLength; ++k) {
//        x_1d[k]=k;
//   }

The ArrayRCP interface is more straightforward, but it is mentioned in the document that its reference counting is not compatible with multi threading. I was wondering if it is unsafe to write a simple for loop like this to modify the content of a Tpetra::Vector

// auto xArrayRcp = xRcp->getDataNonConst();
// const int localLength = xRcp->getLocalLength();
// #pragma omg parallel for
// for (int i = 0; i < localLength; i++) {
//     xArrayRcp[i]=I; 
// }

Thanks a lot!
Wen Yan

More information about the Trilinos-Users mailing list