Skip to content

Commit

Permalink
Merge pull request #103 from lanl/FOR_REDUCE
Browse files Browse the repository at this point in the history
For Reduce updates
  • Loading branch information
nathanielmorgan authored Oct 7, 2024
2 parents 0bb2d0c + a63df38 commit a56a3b2
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 159 deletions.
14 changes: 7 additions & 7 deletions examples/CSCKokkos.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************************************
© 2020. Triad National Security, LLC. All rights reserved.
2020. Triad National Security, LLC. All rights reserved.
This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
Department of Energy/National Nuclear Security Administration. All rights in the program are
Expand Down Expand Up @@ -98,21 +98,21 @@ int main(int argc, char* argv[])

int loc_total = 0;
loc_total += 0; // Get rid of warning
REDUCE_SUM(i, 0, nnz,
loc_total, {
FOR_REDUCE_SUM(i, 0, nnz,
loc_total, {
loc_total += values[i];
}, total);
printf("Sum of nnz from pointer method %d\n", total);
total = 0;
REDUCE_SUM(i, 0, nnz,
loc_total, {
FOR_REDUCE_SUM(i, 0, nnz,
loc_total, {
loc_total += a_start[i];
}, total);
printf("Sum of start indices form .get_starts() %d\n", total);
total = 0;

REDUCE_SUM(i, 0, dim1,
j, 0, dim2 - 1,
FOR_REDUCE_SUM(i, 0, dim1,
j, 0, dim2 - 1,
loc_total, {
loc_total += A(i, j);
}, total);
Expand Down
22 changes: 11 additions & 11 deletions examples/CSRKokkos.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************************************
© 2020. Triad National Security, LLC. All rights reserved.
2020. Triad National Security, LLC. All rights reserved.
This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
Department of Energy/National Nuclear Security Administration. All rights in the program are
Expand Down Expand Up @@ -96,22 +96,22 @@ int main(int argc, char* argv[])
printf("And has %ld non zero elements\n", A.nnz());
});
REDUCE_SUM(i, 0, nnz,
loc_total, {
loc_total += res[i];
FOR_REDUCE_SUM(i, 0, nnz,
loc_total, {
loc_total += res[i];
}, total);
printf("Sum of nnz from pointer method %d\n", total);
total = 0;
REDUCE_SUM(i, 0, nnz,
loc_total, {
loc_total += a_start[i];
FOR_REDUCE_SUM(i, 0, nnz,
loc_total, {
loc_total += a_start[i];
}, total);
printf("Sum of start indices form .get_starts() %d\n", total);
total = 0;
REDUCE_SUM(i, 0, dim1,
j, 0, dim2,
loc_total, {
loc_total += A(i,j);
FOR_REDUCE_SUM(i, 0, dim1,
j, 0, dim2,
loc_total, {
loc_total += A(i,j);
}, total);
printf("Sum of nnz in array notation %d\n", total);
auto ss = A.begin(0);
Expand Down
64 changes: 32 additions & 32 deletions examples/kokkos_for.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************************************
© 2020. Triad National Security, LLC. All rights reserved.
2020. Triad National Security, LLC. All rights reserved.
This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
Department of Energy/National Nuclear Security Administration. All rights in the program are
Expand Down Expand Up @@ -60,46 +60,46 @@ int main(int argc, char* argv[])
// Kokkos::View<int ***> arr_3D("ARR_3D", 10,10,10);
CArrayKokkos<int> arr_3D(10, 10, 10);
FOR_ALL(i, 0, 10,
j, 0, 10,
k, 0, 10, {
j, 0, 10,
k, 0, 10, {
arr_3D(i, j, k) = k * 10 * 10 + j * 10 + i;
});

int loc_sum = 0;
int result = 0;
REDUCE_SUM(i, 0, 10,
loc_sum, {
FOR_REDUCE_SUM(i, 0, 10,
loc_sum, {
loc_sum += arr(i) * arr(i);
}, result);
printf("1D reduce sum: %i vs. 985960\n", result);

loc_sum = 0;
result = 0;
REDUCE_SUM(i, 0, 10,
j, 0, 10,
loc_sum, {
FOR_REDUCE_SUM(i, 0, 10,
j, 0, 10,
loc_sum, {
loc_sum += arr_2D(i, j) * arr_2D(i, j);
}, result);

printf("2D reduce sum: %i vs. 9859600\n", result);

loc_sum = 0;
result = 0;
REDUCE_SUM(i, 0, 10,
j, 0, 10,
k, 0, 10,
loc_sum, {
FOR_REDUCE_SUM(i, 0, 10,
j, 0, 10,
k, 0, 10,
loc_sum, {
loc_sum += arr_3D(i, j, k) * arr_3D(i, j, k);
}, result);

printf("3D reduce: %i vs. 98596000\n", result);

result = 0;
int loc_max = 2000;
REDUCE_MAX(i, 0, 10,
j, 0, 10,
k, 0, 10,
loc_max, {
FOR_REDUCE_MAX(i, 0, 10,
j, 0, 10,
k, 0, 10,
loc_max, {
if (loc_max < arr_3D(i, j, k)) {
loc_max = arr_3D(i, j, k);
}
Expand All @@ -122,10 +122,10 @@ int main(int argc, char* argv[])

result = 0;
int loc_min = 2000;
REDUCE_MIN(i, 0, 10,
j, 0, 10,
k, 0, 10,
loc_min, {
FOR_REDUCE_MIN(i, 0, 10,
j, 0, 10,
k, 0, 10,
loc_min, {
if (loc_min > arr_3D(i, j, k)) {
loc_min = arr_3D(i, j, k);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ int main(int argc, char* argv[])
}); // end parallel do

DO_REDUCE_MAX(i, 1, 10,
loc_max, {
loc_max, {
if (loc_max < matrix1D(i)) {
loc_max = matrix1D(i);
}
Expand All @@ -180,45 +180,45 @@ int main(int argc, char* argv[])
printf("result max 1D matrix = %i\n", result);

DO_REDUCE_MAX(j, 1, 10,
i, 1, 10,
loc_max, {
i, 1, 10,
loc_max, {
if (loc_max < matrix2D(i, j)) {
loc_max = matrix2D(i, j);
}
}, result);
printf("result max 2D matrix = %i\n", result);

DO_REDUCE_MAX(k, 1, 10,
j, 1, 10,
i, 1, 10,
loc_max, {
j, 1, 10,
i, 1, 10,
loc_max, {
if (loc_max < matrix3D(i, j, k)) {
loc_max = matrix3D(i, j, k);
}
}, result);
printf("result max 3D matrix = %i\n", result);

DO_REDUCE_MIN(i, 1, 10,
loc_min, {
loc_min, {
if (loc_min > matrix1D(i)) {
loc_min = matrix1D(i);
}
}, result);
printf("result min 1D matrix = %i\n", result);

DO_REDUCE_MIN(j, 1, 10,
i, 1, 10,
loc_min, {
i, 1, 10,
loc_min, {
if (loc_min > matrix2D(i, j)) {
loc_min = matrix2D(i, j);
}
}, result);
printf("result min 2D matrix = %i\n", result);

DO_REDUCE_MIN(k, 1, 10,
j, 1, 10,
i, 1, 10,
loc_min, {
j, 1, 10,
i, 1, 10,
loc_min, {
if (loc_min > matrix3D(i, j, k)) {
loc_min = matrix3D(i, j, k);
}
Expand Down
8 changes: 4 additions & 4 deletions examples/laplaceMPI/laplace_mpi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************************************
© 2020. Triad National Security, LLC. All rights reserved.
2020. Triad National Security, LLC. All rights reserved.
This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S.
Department of Energy/National Nuclear Security Administration. All rights in the program are
Expand Down Expand Up @@ -292,9 +292,9 @@ int main(int argc, char* argv[])

// calculate max difference between temperature and temperature_previous
double loc_max_value = 100.0;
REDUCE_MAX(i, height_index_start, height_index_end,
j, 1, width_loc - 1,
loc_max_value, {
FOR_REDUCE_MAX(i, height_index_start, height_index_end,
j, 1, width_loc - 1,
loc_max_value, {
double value = fabs(temperature_loc(i, j) - temperature_previous_loc(i, j));
if (value > loc_max_value) {
loc_max_value = value;
Expand Down
24 changes: 12 additions & 12 deletions examples/main_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ class ModelA

// NOTE: if private vars are accessed, requires REDUCE_SUM_CLASS
// do summation in parallel on GPU
REDUCE_SUM_CLASS(k, 1, 6,
j, 1, 5,
i, 1, 4,
loc_sum, {
FOR_REDUCE_SUM_CLASS(k, 1, 6,
j, 1, 5,
i, 1, 4,
loc_sum, {
loc_sum += matrix(i, j, k, 1);
}, val);

Expand Down Expand Up @@ -182,10 +182,10 @@ class ModelB

// NOTE: if private vars are accessed, requires REDUCE_SUM_CLASS
// do summation in parallel on GPU
REDUCE_SUM_CLASS(k, 1, 6,
j, 1, 5,
i, 1, 4,
loc_sum, {
FOR_REDUCE_SUM_CLASS(k, 1, 6,
j, 1, 5,
i, 1, 4,
loc_sum, {
loc_sum += matrix(i, j, k, 1);
}, val);

Expand Down Expand Up @@ -960,10 +960,10 @@ void pass_by_ref_two(const FMatrixKokkos<int>& matrix)
int val = 0;

// do summation in parallel on GPU
REDUCE_SUM(k, 1, 6,
j, 1, 5,
i, 1, 4,
loc_sum, {
FOR_REDUCE_SUM(k, 1, 6,
j, 1, 5,
i, 1, 4,
loc_sum, {
loc_sum += matrix(i, j, k, 1);
}, val);

Expand Down
Loading

0 comments on commit a56a3b2

Please sign in to comment.