Skip to content

Commit 3d01a18

Browse files
authored
Merge pull request #76 from SCOREC/cws/supportFetchContent
support cmake FetchContent: - remove the set_property call on omega_h - silence type comparison and unused var errors - the parent package is building with stricter error checking - disable building and running tests when MeshFields_IS_TESTING is off (off is default) - a kokkos, cabana, and omegah based test are marked as smoke tests that always build and run
2 parents 472f9f7 + 01cd408 commit 3d01a18

File tree

9 files changed

+68
-55
lines changed

9 files changed

+68
-55
lines changed

CMakeLists.txt

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ option(MeshFields_USE_Cabana "Build with the Cabana storage backend" OFF)
99

1010
find_package(Kokkos REQUIRED)
1111
find_package(Omega_h REQUIRED)
12-
#Clear the omegah compilation flags that it passes to cuda. Using the
13-
# kokkos target, and nvcc_wrapper, provide sufficient flags.
14-
set_property(TARGET Omega_h::omega_h PROPERTY INTERFACE_COMPILE_OPTIONS "")
1512

1613
if(MeshFields_USE_Cabana)
1714
find_package(Cabana 0.7.0 REQUIRED)
@@ -112,8 +109,8 @@ endif()
112109
enable_testing()
113110
include(CTest)
114111

115-
option(IS_TESTING "Build for CTest" OFF)
116-
message(STATUS "IS_TESTING: ${IS_TESTING}")
112+
option(MeshFields_IS_TESTING "Build for CTest" OFF)
113+
message(STATUS "MeshFields_IS_TESTING: ${MeshFields_IS_TESTING}")
117114

118115
#check for valgrind
119116
find_program(VALGRIND_CMD valgrind DOC "Location of the valgrind program")
@@ -124,72 +121,87 @@ function(test_func_impl TEST_NAME)
124121
# need to run as a cmake script to capture assert and other 'system failures'
125122
# https://cmake.org/cmake/help/latest/prop_test/WILL_FAIL.html#prop_test:WILL_FAIL
126123
add_test(NAME ${TEST_NAME} COMMAND ${CMAKE_COMMAND} -E env ${TEST_STR})
124+
if(TEST ${TEST_NAME})
125+
set_property(TEST ${TEST_NAME} PROPERTY LABELS "meshfields::base")
126+
endif()
127127
endfunction(test_func_impl)
128128

129-
function(test_func TEST_NAME)
129+
#smoke tests that are always enabled
130+
function(smoke_test_func TEST_NAME)
130131
test_func_impl(${TEST_NAME} ${ARGN})
131132
if(TEST ${TEST_NAME})
132-
set_property(TEST ${TEST_NAME} PROPERTY LABELS "base")
133+
set_property(TEST ${TEST_NAME} PROPERTY LABELS "meshfields::smoke")
134+
endif()
135+
endfunction(smoke_test_func)
136+
137+
function(test_func TEST_NAME)
138+
if(MeshFields_IS_TESTING)
139+
test_func_impl(${TEST_NAME} ${ARGN})
133140
endif()
134141
endfunction(test_func)
135142

136143
# Unlike test_func, will_fail_test_func assumes the command for the test will fail
137144
function(will_fail_test_func TEST_NAME)
138-
test_func_impl(${TEST_NAME} ${ARGN})
139-
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
140-
if(TEST ${TEST_NAME})
141-
set_property(TEST ${TEST_NAME} PROPERTY LABELS "base")
145+
if(MeshFields_IS_TESTING)
146+
test_func_impl(${TEST_NAME} ${ARGN})
147+
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
142148
endif()
143149
endfunction()
144150

145151
function(will_fail_valgrind_test_func TEST_NAME)
146-
if(VALGRIND_CMD)
147-
test_func_impl(${TEST_NAME} ${VALGRIND_CMD} ${ARGN})
148-
set_property(TEST ${TEST_NAME} PROPERTY
149-
FAIL_REGULAR_EXPRESSION "Invalid read;Invalid write"
150-
)
151-
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
152-
if(TEST ${TEST_NAME})
153-
set_property(TEST ${TEST_NAME} PROPERTY LABELS "base")
152+
if(MeshFields_IS_TESTING)
153+
if(VALGRIND_CMD)
154+
test_func_impl(${TEST_NAME} ${VALGRIND_CMD} ${ARGN})
155+
set_property(TEST ${TEST_NAME} PROPERTY
156+
FAIL_REGULAR_EXPRESSION "Invalid read;Invalid write"
157+
)
158+
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
154159
endif()
155160
endif()
156161
endfunction()
157162

158-
function(meshfields_add_exe EXE_NAME EXE_SRC)
163+
#smoke executables are always built
164+
function(meshfields_add_smoke_exe EXE_NAME EXE_SRC)
159165
add_executable(${EXE_NAME} ${EXE_SRC})
160166
target_link_libraries(${EXE_NAME} PRIVATE meshfields)
161167
endfunction()
162168

163-
# Creating minimal reproduction of error
164-
meshfields_add_exe(KokkosTests test/testKokkos.cpp)
169+
function(meshfields_add_exe EXE_NAME EXE_SRC)
170+
if(MeshFields_IS_TESTING)
171+
add_executable(${EXE_NAME} ${EXE_SRC})
172+
target_link_libraries(${EXE_NAME} PRIVATE meshfields)
173+
endif()
174+
endfunction()
175+
176+
meshfields_add_smoke_exe(KokkosTests test/testKokkos.cpp)
165177
meshfields_add_exe(SerializationTests test/testSerialize.cpp)
166178
meshfields_add_exe(ElementTests test/testElement.cpp)
167179
meshfields_add_exe(ElementJacobian1d test/testElementJacobian1d.cpp)
168180
meshfields_add_exe(ElementJacobian2d test/testElementJacobian2d.cpp)
169181
meshfields_add_exe(ElementJacobian3d test/testElementJacobian3d.cpp)
170182
meshfields_add_exe(CountIntegrator test/testCountIntegrator.cpp)
171-
meshfields_add_exe(OmegahTriTests test/testOmegahTri.cpp)
183+
meshfields_add_smoke_exe(OmegahTriTests test/testOmegahTri.cpp)
172184
meshfields_add_exe(ExceptionTest test/testExceptions.cpp)
173185
meshfields_add_exe(PointMapping test/testPointMapping.cpp)
174186
meshfields_add_exe(OmegahTetTest test/testOmegahTet.cpp)
175187

176188
if(MeshFields_USE_Cabana)
177189
meshfields_add_exe(ControllerPerformance test/testControllerPerformance.cpp)
178-
meshfields_add_exe(CabanaTests test/testCabana.cpp)
179-
test_func(CabanaTests ./CabanaTests)
190+
meshfields_add_smoke_exe(CabanaTests test/testCabana.cpp)
191+
smoke_test_func(CabanaTests ./CabanaTests)
180192
test_func(ControllerPerformance ./ControllerPerformance)
181193
endif()
182194

183-
test_func(KokkosTests ./KokkosTests)
195+
smoke_test_func(KokkosTests ./KokkosTests)
184196
test_func(SerializationTests ./SerializationTests)
185197
test_func(ElementTests ./ElementTests)
186198
test_func(ElementJacobian1d ./ElementJacobian1d)
187199
test_func(ElementJacobian2d ./ElementJacobian2d)
188200
test_func(ElementJacobian3d ./ElementJacobian3d)
189201
test_func(CountIntegrator ./CountIntegrator)
190-
test_func(OmegahTriTests ./OmegahTriTests)
202+
smoke_test_func(OmegahTriTests ./OmegahTriTests)
191203
test_func(PointMapping ./PointMapping)
192-
test_func(OmegahTetTest, ./OmegahTetTest)
204+
test_func(OmegahTetTest ./OmegahTetTest)
193205
if(MeshFields_USE_EXCEPTIONS)
194206
# exception caught - no error
195207
test_func(ExceptionTest ./ExceptionTest)

src/MeshField_Element.hpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,15 @@ struct FieldElement {
170170
*/
171171
KOKKOS_INLINE_FUNCTION ValArray
172172
getValue(int ent, Kokkos::Array<Real, MeshEntDim + 1> localCoord) const {
173-
assert(ent < numMeshEnts);
173+
assert(ent >= 0);
174+
assert(static_cast<size_t>(ent) < numMeshEnts);
174175
ValArray c;
175176
const auto shapeValues = shapeFn.getValues(localCoord);
176-
for (int ci = 0; ci < NumComponents; ++ci)
177+
for (size_t ci = 0; ci < NumComponents; ++ci)
177178
c[ci] = 0;
178179
for (auto topo : elm2dof.getTopology()) { // element topology
179-
for (int ni = 0; ni < shapeFn.numNodes; ++ni) {
180-
for (int ci = 0; ci < NumComponents; ++ci) {
180+
for (size_t ni = 0; ni < shapeFn.numNodes; ++ni) {
181+
for (size_t ci = 0; ci < NumComponents; ++ci) {
181182
auto map = elm2dof(ni, ci, ent, topo);
182183
const auto fval =
183184
field(map.entity, map.node, map.component, map.topo);
@@ -194,8 +195,8 @@ struct FieldElement {
194195
KOKKOS_INLINE_FUNCTION NodeArray getNodeValues(int ent) const {
195196
NodeArray c;
196197
for (auto topo : elm2dof.getTopology()) { // element topology
197-
for (int ni = 0; ni < ShapeType::numNodes; ++ni) {
198-
for (int d = 0; d < ShapeType::meshEntDim; ++d) {
198+
for (size_t ni = 0; ni < ShapeType::numNodes; ++ni) {
199+
for (size_t d = 0; d < ShapeType::meshEntDim; ++d) {
199200
auto map = elm2dof(ni, d, ent, topo);
200201
const auto fval =
201202
field(map.entity, map.node, map.component, map.topo);
@@ -219,11 +220,12 @@ struct FieldElement {
219220
* @return the result of evaluation
220221
*/
221222
KOKKOS_INLINE_FUNCTION Real getJacobian1d(int ent) const {
222-
assert(ent < numMeshEnts);
223+
assert(ent >= 0);
224+
assert(static_cast<size_t>(ent) < numMeshEnts);
223225
const auto nodalGradients = shapeFn.getLocalGradients();
224226
const auto nodeValues = getNodeValues(ent);
225227
auto g = nodalGradients[0] * nodeValues[0];
226-
for (int i = 1; i < shapeFn.numNodes; ++i) {
228+
for (size_t i = 1; i < shapeFn.numNodes; ++i) {
227229
g = g + nodalGradients[i] * nodeValues[i];
228230
}
229231
return g;
@@ -328,7 +330,7 @@ struct FieldElement {
328330
KOKKOS_LAMBDA(const int &ent, LO &lerrors) {
329331
Real sum = 0;
330332
LO isError = 0;
331-
for (int i = 0; i < localCoords.extent(1); i++) {
333+
for (size_t i = 0; i < localCoords.extent(1); i++) {
332334
if (localCoords(ent, i) < 0)
333335
isError++;
334336
sum += localCoords(ent, i);
@@ -449,7 +451,7 @@ evaluate(FieldElement &fes, Kokkos::View<Real **> localCoords,
449451
KOKKOS_LAMBDA(const int &ent, LO &lerrors) {
450452
Real sum = 0;
451453
LO isError = 0;
452-
for (int i = 0; i < localCoords.extent(1); i++) {
454+
for (size_t i = 0; i < localCoords.extent(1); i++) {
453455
if (localCoords(ent, i) < 0)
454456
isError++;
455457
sum += localCoords(ent, i);
@@ -477,7 +479,7 @@ evaluate(FieldElement &fes, Kokkos::View<Real **> localCoords,
477479
LO numLocalCoords;
478480
Kokkos::deep_copy(numLocalCoords,
479481
Kokkos::subview(offsets, offsets.size() - 1));
480-
if (localCoords.extent(0) != numLocalCoords) {
482+
if (localCoords.extent(0) != static_cast<size_t>(numLocalCoords)) {
481483
fail("The size of dimension 0 of the local coordinates input array (%zu) "
482484
"does not match the last entry of the offsets array (%d).\n",
483485
localCoords.extent(0), numLocalCoords);
@@ -491,10 +493,10 @@ evaluate(FieldElement &fes, Kokkos::View<Real **> localCoords,
491493
Kokkos::Array<Real, FieldElement::MeshEntDim + 1> lc;
492494
// TODO use nested parallel for?
493495
for (auto pt = offsets(ent); pt < offsets(ent + 1); pt++) {
494-
for (int i = 0; i < localCoords.extent(1); i++) // better way?
496+
for (size_t i = 0; i < localCoords.extent(1); i++) // better way?
495497
lc[i] = localCoords(pt, i);
496498
const auto val = fes.getValue(ent, lc);
497-
for (int i = 0; i < numComponents; i++)
499+
for (size_t i = 0; i < numComponents; i++)
498500
res(pt, i) = val[i];
499501
}
500502
});

src/MeshField_Field.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ template <class Slice> class Field {
115115
* @return the size/extent
116116
*/
117117
KOKKOS_INLINE_FUNCTION
118-
auto size(int i) const { return slice.size(i); }
118+
size_t size(int i) const { return slice.size(i); }
119119

120120
/**
121121
* access the underlying field at the specified index

src/MeshField_Integrate.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ Kokkos::View<Real *> getIntegrationPointWeights(
159159
std::vector<IntegrationPoint<FieldElement::MeshEntDim + 1>> ip) {
160160
const auto numPtsPerElm = ip.size();
161161
const auto numMeshEnts = fes.numMeshEnts;
162-
const auto meshEntDim = fes.MeshEntDim;
163162
Kokkos::View<Real *> weights("weights", numMeshEnts * numPtsPerElm);
164163
// broadcast the points into the view - FIXME this is an inefficient use of
165164
// memory

src/MeshField_Shape.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace {
99
template <typename Array> KOKKOS_INLINE_FUNCTION bool sumsToOne(Array &xi) {
1010
auto sum = 0.0;
11-
for (int i = 0; i < xi.size(); i++) {
11+
for (size_t i = 0; i < xi.size(); i++) {
1212
sum += xi[i];
1313
}
1414
return (Kokkos::fabs(sum - 1) <= MeshField::MachinePrecision);
@@ -17,7 +17,7 @@ template <typename Array> KOKKOS_INLINE_FUNCTION bool sumsToOne(Array &xi) {
1717
template <typename Array>
1818
KOKKOS_INLINE_FUNCTION bool greaterThanOrEqualZero(Array &xi) {
1919
auto gt = true;
20-
for (int i = 0; i < xi.size(); i++) {
20+
for (size_t i = 0; i < xi.size(); i++) {
2121
gt = gt && (xi[i] >= 0);
2222
}
2323
return gt;

test/testCountIntegrator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void doRun(Omega_h::Mesh &mesh,
7474

7575
CountIntegrator countInt(fes);
7676
countInt.process(fes);
77-
assert(mesh.nelems() == countInt.getCount());
77+
assert(static_cast<size_t>(mesh.nelems()) == countInt.getCount());
7878
}
7979

8080
int main(int argc, char **argv) {

test/testKokkos.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void kokkosControllerSizeTest() {
338338
void kokkosFieldSizeTest() {
339339
printf("== START kokkosFieldSizeTest ==\n");
340340
const int a = 5, b = 4, c = 3, d = 2, e = 1;
341-
const int psi[5] = {a, b, c, d, e};
341+
const size_t psi[5] = {a, b, c, d, e};
342342
{
343343
using simple_static =
344344
MeshField::KokkosController<MemorySpace, ExecutionSpace, int[a],

test/testOmegahTet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool checkResult(Omega_h::Mesh &mesh, Result &result, CoordField coordField,
6767
const auto y = globalCoords(pt, 1);
6868
const auto z = globalCoords(pt, 2);
6969
const auto expected = func(x, y, z);
70-
for (int i = 0; i < numComp; ++i) {
70+
for (size_t i = 0; i < numComp; ++i) {
7171
const auto computed = result(pt, i);
7272
MeshField::LO isError = 0;
7373
if (Kokkos::fabs(computed - expected) >
@@ -96,7 +96,7 @@ void setVertices(Omega_h::Mesh &mesh, AnalyticFunction func, ShapeField field) {
9696
const auto x = coords[vtx * MeshDim];
9797
const auto y = coords[vtx * MeshDim + 1];
9898
const auto z = coords[vtx * MeshDim + 2];
99-
for (int i = 0; i < field.numComp; ++i) {
99+
for (size_t i = 0; i < field.numComp; ++i) {
100100
field(vtx, 0, i, MeshField::Vertex) = func(x, y, z);
101101
}
102102
};
@@ -121,7 +121,7 @@ void setEdges(Omega_h::Mesh &mesh, AnalyticFunction func, ShapeField field) {
121121
(coords[left * MeshDim + 1] + coords[right * MeshDim + 1]) / 2.0;
122122
const auto z =
123123
(coords[left * MeshDim + 2] + coords[right * MeshDim + 2]) / 2.0;
124-
for (int i = 0; i < field.numComp; ++i) {
124+
for (size_t i = 0; i < field.numComp; ++i) {
125125
field(edge, 0, i, MeshField::Edge) = func(x, y, z);
126126
}
127127
};
@@ -137,7 +137,7 @@ createElmAreaCoords(size_t numElements,
137137
numElements * NumPtsPerElem);
138138
Kokkos::parallel_for(
139139
"setLocalCoords", numElements, KOKKOS_LAMBDA(const int &elm) {
140-
for (int pt = 0; pt < NumPtsPerElem; pt++) {
140+
for (size_t pt = 0; pt < NumPtsPerElem; pt++) {
141141
lc(elm * NumPtsPerElem + pt, 0) = coords[pt * 4 + 0];
142142
lc(elm * NumPtsPerElem + pt, 1) = coords[pt * 4 + 1];
143143
lc(elm * NumPtsPerElem + pt, 2) = coords[pt * 4 + 2];

test/testOmegahTri.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool checkResult(Omega_h::Mesh &mesh, Result &result, CoordField coordField,
6464
const auto x = globalCoords(pt, 0);
6565
const auto y = globalCoords(pt, 1);
6666
const auto expected = func(x, y);
67-
for (int i = 0; i < numComp; ++i) {
67+
for (size_t i = 0; i < numComp; ++i) {
6868
const auto computed = result(pt, i);
6969
MeshField::LO isError = 0;
7070
if (Kokkos::fabs(computed - expected) >
@@ -92,7 +92,7 @@ void setVertices(Omega_h::Mesh &mesh, AnalyticFunction func, ShapeField field) {
9292
// - TODO should be encoded in the field?
9393
const auto x = coords[vtx * MeshDim];
9494
const auto y = coords[vtx * MeshDim + 1];
95-
for (int i = 0; i < field.numComp; ++i) {
95+
for (size_t i = 0; i < field.numComp; ++i) {
9696
field(vtx, 0, i, MeshField::Vertex) = func(x, y);
9797
}
9898
};
@@ -115,7 +115,7 @@ void setEdges(Omega_h::Mesh &mesh, AnalyticFunction func, ShapeField field) {
115115
const auto x = (coords[left * MeshDim] + coords[right * MeshDim]) / 2.0;
116116
const auto y =
117117
(coords[left * MeshDim + 1] + coords[right * MeshDim + 1]) / 2.0;
118-
for (int i = 0; i < field.numComp; ++i) {
118+
for (size_t i = 0; i < field.numComp; ++i) {
119119
field(edge, 0, i, MeshField::Edge) = func(x, y);
120120
}
121121
};
@@ -131,7 +131,7 @@ createElmAreaCoords(size_t numElements,
131131
numElements * NumPtsPerElem);
132132
Kokkos::parallel_for(
133133
"setLocalCoords", numElements, KOKKOS_LAMBDA(const int &elm) {
134-
for (int pt = 0; pt < NumPtsPerElem; pt++) {
134+
for (size_t pt = 0; pt < NumPtsPerElem; pt++) {
135135
lc(elm * NumPtsPerElem + pt, 0) = coords[pt * 3 + 0];
136136
lc(elm * NumPtsPerElem + pt, 1) = coords[pt * 3 + 1];
137137
lc(elm * NumPtsPerElem + pt, 2) = coords[pt * 3 + 2];

0 commit comments

Comments
 (0)