[Trilinos-Users] [EXTERNAL] Re: Best practice to modify elements of a Tpetra::Vector with openmp?
Wen Yan
wenyan4work at gmail.com
Thu Jun 8 19:02:57 EDT 2017
Thanks a lot!
Wen Yan
> On Jun 8, 2017, at 6:58 PM, Hoemmen, Mark <mhoemme at sandia.gov> wrote:
>
>
>
>
>
>
> On 6/8/17, 3:04 PM, "Wen Yan" <wenyan4work at gmail.com> wrote:
>> Could you please also confirm the following?
>>
>> 1. x_2d is a 2D Kokkos::View with Kokkos::LayoutLeft, and the entries x_2d(i,c) are continuous in memory for continuous index i. Here i ranges from 0 to local length - 1, and c ranges from 0 to the number of vectors in the Tpetra::MultiVector - 1
>
> Yes.
>
>>
>> 2. x_2d is safe to use with openmp, like:
>> for (int c = 0; c < x_2d.dimension_1(); c++) {
>> #pragma omp parallel for
>> for (int i = 0; i < x_2d.dimension_0(); i++) {
>> const double temp = x_2d(i, c);
>> x_2d(i, c) = temp < 0 ? 0 : temp;
>> }
>> }
>
> Yes. Also, why not use Kokkos?
>
> const int numCols = x_2d.dimension_1 ();
> for (int c = 0; c < numCols; ++c) {
> Kokkos::parallel_for (
> Kokkos::RangePolicy<Kokkos::OpenMP, int> (0, x_2d.dimension_0 ()),
> KOKKOS_LAMBDA (const int r) {
> const double temp = x_2d(r,c);
> x_2d(r,c) = temp < 0.0 ? 0.0 : temp;
> });
> }
>
>> 3. For read-only access there is no need to call modify<Kokkos::HostSpace>()
>
> That is correct. The example should explain.
>
> mfh
More information about the Trilinos-Users
mailing list