diff --git a/Intro_Tutorial/lessons/04_raja_forall/04_raja_forall.cpp b/Intro_Tutorial/lessons/04_raja_forall/04_raja_forall.cpp index cc3a3bb..9036bcc 100644 --- a/Intro_Tutorial/lessons/04_raja_forall/04_raja_forall.cpp +++ b/Intro_Tutorial/lessons/04_raja_forall/04_raja_forall.cpp @@ -16,8 +16,8 @@ int main() std::cout << "Address of data: " << data << std::endl; - // TODO: write a RAJA forall loop to initialize each element of the array to the value - // of the index + // TODO: write a RAJA forall loop to set each element of the array 'data' to + // the value of the loop index std::cout << "data[50] = " << data[50] << std::endl; diff --git a/Intro_Tutorial/lessons/04_raja_forall/solution/04_raja_forall_solution.cpp b/Intro_Tutorial/lessons/04_raja_forall/solution/04_raja_forall_solution.cpp index c92bc9e..010c34f 100644 --- a/Intro_Tutorial/lessons/04_raja_forall/solution/04_raja_forall_solution.cpp +++ b/Intro_Tutorial/lessons/04_raja_forall/solution/04_raja_forall_solution.cpp @@ -16,8 +16,9 @@ int main() std::cout << "Address of data: " << data << std::endl; - // TODO: write a RAJA forall loop to initialize each element of the array to the value - // of the index + // TODO: write a RAJA forall loop to set each element of the array 'data' to + // the value of the loop index + RAJA::forall(RAJA::TypedRangeSegment(0, N), [=] (int i) { data[i] = i; }); diff --git a/Intro_Tutorial/lessons/05_raja_reduce/05_raja_reduce.cpp b/Intro_Tutorial/lessons/05_raja_reduce/05_raja_reduce.cpp index eabb2e7..79db58c 100644 --- a/Intro_Tutorial/lessons/05_raja_reduce/05_raja_reduce.cpp +++ b/Intro_Tutorial/lessons/05_raja_reduce/05_raja_reduce.cpp @@ -1,4 +1,5 @@ #include +#include #include "RAJA/RAJA.hpp" #include "umpire/Umpire.hpp" @@ -15,14 +16,26 @@ int main() a = static_cast(allocator.allocate(N*sizeof(double))); b = static_cast(allocator.allocate(N*sizeof(double))); - // TODO: Change this dot variable to instead use a RAJA reduction - // TODO: to calculate and output the dot product of a and b - double dot{0.0}; + std::srand(4793); + // Initialize data arrays to random positive and negative values RAJA::forall< RAJA::seq_exec >( RAJA::TypedRangeSegment(0, N), [=] (int i) { - a[i] = 1.0; - b[i] = 1.0; + double signfact = static_cast(std::rand()/RAND_MAX); + signfact = ( signfact < 0.5 ? -1.0 : 1.0 ); + + a[i] = signfact * (i + 1.1)/(i + 1.12); + b[i] = (i + 1.1)/(i + 1.12); + } + ); + + // TODO: Change this dot variable to instead use a RAJA OpenMP parallel + // reduction + double dot{0.0}; + + // TODO: Calculate and output the dot product of a and b using a RAJA::forall + RAJA::forall< RAJA::omp_parallel_for_exec >( + RAJA::TypedRangeSegment(0, N), [=] (int i) { } ); diff --git a/Intro_Tutorial/lessons/05_raja_reduce/solution/05_raja_reduce_solution.cpp b/Intro_Tutorial/lessons/05_raja_reduce/solution/05_raja_reduce_solution.cpp index 4544c61..4b76a48 100644 --- a/Intro_Tutorial/lessons/05_raja_reduce/solution/05_raja_reduce_solution.cpp +++ b/Intro_Tutorial/lessons/05_raja_reduce/solution/05_raja_reduce_solution.cpp @@ -1,4 +1,5 @@ #include +#include #include "RAJA/RAJA.hpp" #include "umpire/Umpire.hpp" @@ -15,12 +16,26 @@ int main() a = static_cast(allocator.allocate(N*sizeof(double))); b = static_cast(allocator.allocate(N*sizeof(double))); - RAJA::ReduceSum< RAJA::seq_reduce, double > dot(0.0); + std::srand(4793); + // Initialize data arrays to random positive and negative values RAJA::forall< RAJA::seq_exec >( RAJA::TypedRangeSegment(0, N), [=] (int i) { - a[i] = 1.0; - b[i] = 1.0; + double signfact = static_cast(std::rand()/RAND_MAX); + signfact = ( signfact < 0.5 ? -1.0 : 1.0 ); + + a[i] = signfact * (i + 1.1)/(i + 1.12); + b[i] = (i + 1.1)/(i + 1.12); + } + ); + + // TODO: Change this dot variable to instead use a RAJA OpenMP parallel + // reduction + RAJA::ReduceSum< RAJA::omp_reduce, double > dot(0.0); + + // TODO: Calculate and output the dot product of a and b using a RAJA::forall + RAJA::forall< RAJA::omp_parallel_for_exec >( + RAJA::TypedRangeSegment(0, N), [=] (int i) { dot += a[i] * b[i]; } );