-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example code referenced in issue #452 #556
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of the entire code block does not look right
Fixed indentation (w/ spaces), so it now looks like example in |
#include <Kokkos_Core.hpp> | ||
|
||
struct Idx3D_t { | ||
int value[3]; | ||
int& operator[] (int i) { return value[i]; } | ||
const int& operator[] (int i) const { return value[i]; } | ||
}; | ||
|
||
template<> | ||
struct Kokkos::reduction_identity<Idx3D_t> { | ||
static constexpr Idx3D_t min() { return {0,0,0}; } | ||
}; | ||
|
||
int main(int argc, char* argv[]) { | ||
Kokkos::initialize(argc, argv); | ||
{ | ||
Kokkos::View<double***> a("A",5,5,5); | ||
Kokkos::deep_copy(a,10); | ||
a(2,3,1) = 5; | ||
using MinLoc_t = Kokkos::MinLoc<double, Idx3D_t>; | ||
using MinLocVal_t = typename MinLoc_t::value_type; | ||
MinLocVal_t result; | ||
Kokkos::parallel_reduce(Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0,0,0},{5,5,5}), | ||
KOKKOS_LAMBDA(int i, int j, int k, MinLocVal_t& val) { | ||
if(a(i,j,k)<val.val) { | ||
val.val = a(i,j,k); | ||
val.loc[0] = i; | ||
val.loc[1] = j; | ||
val.loc[2] = k; | ||
} | ||
},MinLoc_t(result)); | ||
printf("%lf %i %i %i\n",result.val,result.loc[0],result.loc[1],result.loc[2]); | ||
} | ||
Kokkos::finalize(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format-8
gives
#include <Kokkos_Core.hpp>
struct Idx3D_t {
int value[3];
int& operator[](int i) { return value[i]; }
const int& operator[](int i) const { return value[i]; }
};
template <>
struct Kokkos::reduction_identity<Idx3D_t> {
static constexpr Idx3D_t min() { return {0, 0, 0}; }
};
int main(int argc, char* argv[]) {
Kokkos::initialize(argc, argv);
{
Kokkos::View<double***> a("A", 5, 5, 5);
Kokkos::deep_copy(a, 10);
a(2, 3, 1) = 5;
using MinLoc_t = Kokkos::MinLoc<double, Idx3D_t>;
using MinLocVal_t = typename MinLoc_t::value_type;
MinLocVal_t result;
Kokkos::parallel_reduce(
Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0}, {5, 5, 5}),
KOKKOS_LAMBDA(int i, int j, int k, MinLocVal_t& val) {
if (a(i, j, k) < val.val) {
val.val = a(i, j, k);
val.loc[0] = i;
val.loc[1] = j;
val.loc[2] = k;
}
},
MinLoc_t(result));
printf("%lf %i %i %i\n", result.val, result.loc[0], result.loc[1],
result.loc[2]);
}
Kokkos::finalize();
}
(without the preceding whitespace).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I tried your clang-formatted version (above), but it did not render correctly, and had many warnings (e.g., "WARNING: Block quote ends without a blank line; unexpected unindent"). It is possible that we do not have our project set up correctly / completely for C++ (see #451). Example formatting can be a topic for tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to tab over the output of clang format, directives need to be tabbed
|
||
.. code-block:: cpp | ||
|
||
#include <Kokkos_Core.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use four whitespaces instead of one tab?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. I'll have to do it by hand, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like %s/\t/ /g
in vi
.
19e9804
to
dc69c6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with me.
This PR adds example code from Compiler Explorer to
MinLoc
built-in reducer.