The goal of this exercise is to manipulate the Kokkos parallel reduction.
- Open the file
main.cpp
- Create a 2D matrix of size
Nx
xNy
of typedouble
- Initialize the matrix with the values of your choice using
Kokkos::parallel_for
andKokkos::MDRangePolicy
with the default execution space
- Use the
Kokkos::parallel_reduce
to compute the sum of the matrix - Add the code to print the result
- Use
Kokkos::parallel_reduce
and the reducerKokkos::Max
to compute the max element - Add the code to print the result
- Compile the program using the OpenMP backend and run it. Check the output.
- If you can access a GPU, compile the program using a GPU backend and run it. Check the output and compare them with the OpenMP backend.
- Add timers to measure the time spent to compute the sum and the max of the matrix.
- Analyze the time spent on CPU and GPU for different Matrix sizes.