Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Intro_Tutorial/lessons/04_raja_forall/04_raja_forall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 a 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 a 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::seq_exec>(RAJA::TypedRangeSegment<int>(0, N), [=] (int i) {
data[i] = i;
});
Expand Down
23 changes: 18 additions & 5 deletions Intro_Tutorial/lessons/05_raja_reduce/05_raja_reduce.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <cstdlib>

#include "RAJA/RAJA.hpp"
#include "umpire/Umpire.hpp"
Expand All @@ -15,14 +16,26 @@ int main()
a = static_cast<double*>(allocator.allocate(N*sizeof(double)));
b = static_cast<double*>(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<int>(0, N), [=] (int i) {
a[i] = 1.0;
b[i] = 1.0;
double signfact = static_cast<double>(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<int>(0, N), [=] (int i) {
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <cstdlib>

#include "RAJA/RAJA.hpp"
#include "umpire/Umpire.hpp"
Expand All @@ -15,12 +16,26 @@ int main()
a = static_cast<double*>(allocator.allocate(N*sizeof(double)));
b = static_cast<double*>(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<int>(0, N), [=] (int i) {
a[i] = 1.0;
b[i] = 1.0;
double signfact = static_cast<double>(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<int>(0, N), [=] (int i) {
dot += a[i] * b[i];
}
);
Expand Down