From f7d8de75d24ccbef0c18021171f944ca88955c75 Mon Sep 17 00:00:00 2001 From: Oskar Lappi Date: Thu, 4 Jun 2020 13:42:34 +0300 Subject: [PATCH] Reduction test pipeline added to mpitest, Error struct changed: new label field - CHANGED: Error struct has a new label field for labeling an error - The label is what is printed to screen - vtxbuf name lookup moved out of printErrorToScreen/print_error_to_screen - NEW: acScalReductionTestCase and acVecReductionTestCase - Define new test cases by adding them to a list in samples/mpitest/main.cc:main - Minor style change in verification.c to make all Verification functions similar and fit one screen --- include/astaroth_utils.h | 34 ++++++++++++++++++++++++----- samples/mpitest/main.cc | 37 +++++++++++++++++++++++-------- src/utils/verification.c | 47 +++++++++++++++++++++++++++++++++++----- 3 files changed, 98 insertions(+), 20 deletions(-) diff --git a/include/astaroth_utils.h b/include/astaroth_utils.h index 0422b7b..88c5a05 100644 --- a/include/astaroth_utils.h +++ b/include/astaroth_utils.h @@ -29,9 +29,12 @@ extern "C" { #endif - #include +#include + +#define ERROR_LABEL_LENGTH 30 typedef struct { + char label[ERROR_LABEL_LENGTH]; VertexBufferHandle handle; AcReal model; AcReal candidate; @@ -42,6 +45,22 @@ typedef struct { AcReal minimum_magnitude; } Error; +typedef struct { + char label[ERROR_LABEL_LENGTH]; + VertexBufferHandle vtxbuf; + ReductionType rtype; + AcReal candidate; +} AcScalReductionTestCase; + +typedef struct { + char label[ERROR_LABEL_LENGTH]; + VertexBufferHandle a; + VertexBufferHandle b; + VertexBufferHandle c; + ReductionType rtype; + AcReal candidate; +} AcVecReductionTestCase; + /** TODO comment */ Error acGetError(AcReal model, AcReal candidate); @@ -76,17 +95,20 @@ AcResult acMeshClear(AcMesh* mesh); AcResult acModelIntegrateStep(AcMesh mesh, const AcReal dt); /** TODO */ -AcReal -acModelReduceScal(const AcMesh mesh, const ReductionType rtype, const VertexBufferHandle a); +AcReal acModelReduceScal(const AcMesh mesh, const ReductionType rtype, const VertexBufferHandle a); /** TODO */ -AcReal -acModelReduceVec(const AcMesh mesh, const ReductionType rtype, const VertexBufferHandle a, - const VertexBufferHandle b, const VertexBufferHandle c); +AcReal acModelReduceVec(const AcMesh mesh, const ReductionType rtype, const VertexBufferHandle a, const VertexBufferHandle b, const VertexBufferHandle c); /** */ AcResult acVerifyMesh(const AcMesh model, const AcMesh candidate); +/** */ +AcResult acVerifyScalReductions(const AcMesh model, const AcScalReductionTestCase* testCases, const size_t numCases); + +/** */ +AcResult acVerifyVecReductions(const AcMesh model, const AcVecReductionTestCase* testCases, const size_t numCases); + #ifdef __cplusplus } // extern "C" #endif diff --git a/samples/mpitest/main.cc b/samples/mpitest/main.cc index 7b12fe2..b25d990 100644 --- a/samples/mpitest/main.cc +++ b/samples/mpitest/main.cc @@ -25,6 +25,7 @@ #if AC_MPI_ENABLED #include +#include int main(void) @@ -53,12 +54,32 @@ main(void) acGridIntegrate(STREAM_DEFAULT, FLT_EPSILON); acGridPeriodicBoundconds(STREAM_DEFAULT); - // Do reductions - AcReal cand_reduce_res = 0; - VertexBufferHandle vtxbuf = VTXBUF_UUX; - ReductionType rtype = RTYPE_MAX; - acGridReduceScal(STREAM_DEFAULT, rtype, vtxbuf, &cand_reduce_res); // TODO + // clang-format off + // Define scalar reduction tests here + std::vector scalarReductionTests{ + AcScalReductionTestCase{"Scalar MAX", VTXBUF_UUX, RTYPE_MAX, 0}, + AcScalReductionTestCase{"Scalar MIN", VTXBUF_UUX, RTYPE_MIN, 0}, + AcScalReductionTestCase{"Scalar RMS", VTXBUF_UUX, RTYPE_RMS, 0}, + AcScalReductionTestCase{"Scalar RMS_EXP", VTXBUF_UUX, RTYPE_RMS_EXP, 0}, + AcScalReductionTestCase{"Scalar SUM", VTXBUF_UUX, RTYPE_SUM, 0} + }; + // Define vector reduction tests here + std::vector vectorReductionTests{ + AcVecReductionTestCase{"Vector MAX", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_MAX, 0}, + AcVecReductionTestCase{"Vector MIN", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_MIN, 0}, + AcVecReductionTestCase{"Vector RMS", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_RMS, 0}, + AcVecReductionTestCase{"Vector RMS_EXP", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_RMS_EXP, 0}, + AcVecReductionTestCase{"Vector SUM", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_SUM, 0} + }; + // clang-format on + for (auto& testCase : scalarReductionTests) { + acGridReduceScal(STREAM_DEFAULT, testCase.rtype, testCase.vtxbuf, &testCase.candidate); + } + for (auto& testCase : vectorReductionTests) { + acGridReduceVec(STREAM_DEFAULT, testCase.rtype, testCase.a, testCase.b, testCase.c, + &testCase.candidate); + } acGridStoreMesh(STREAM_DEFAULT, &candidate); acGridQuit(); @@ -71,10 +92,8 @@ main(void) acVerifyMesh(model, candidate); // Check reductions - AcReal model_reduce_res = acModelReduceScal(model, RTYPE_MAX, vtxbuf); - Error error = acGetError(model_reduce_res, cand_reduce_res); - error.handle = vtxbuf; - printErrorToScreen(error); + acVerifyScalReductions(model, scalarReductionTests.data(), scalarReductionTests.size()); + acVerifyVecReductions(model, vectorReductionTests.data(), vectorReductionTests.size()); acMeshDestroy(&model); acMeshDestroy(&candidate); diff --git a/src/utils/verification.c b/src/utils/verification.c index a3ddb18..fcae0bc 100644 --- a/src/utils/verification.c +++ b/src/utils/verification.c @@ -2,6 +2,7 @@ #include #include +#include #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) @@ -105,6 +106,7 @@ get_max_abs_error(const VertexBufferHandle vtxbuf_handle, const AcMesh model_mes } error.handle = vtxbuf_handle; + strcpy(error.label, vtxbuf_names[vtxbuf_handle]); error.maximum_magnitude = get_maximum_magnitude(model_vtxbuf, model_mesh.info); error.minimum_magnitude = get_minimum_magnitude(model_vtxbuf, model_mesh.info); @@ -141,7 +143,7 @@ printErrorToScreen(const Error error) { bool errors_found = false; - printf("\t%-15s... ", vtxbuf_names[error.handle]); + printf("\t%-15s... ", error.label); if (is_acceptable(error)) { printf(GRN "OK! " RESET); } @@ -172,8 +174,43 @@ acVerifyMesh(const AcMesh model, const AcMesh candidate) printf("%s\n", errors_found ? "Failure. Found errors in one or more vertex buffers" : "Success. No errors found."); - if (errors_found) - return AC_FAILURE; - else - return AC_SUCCESS; + return errors_found ? AC_FAILURE : AC_SUCCESS; +} + +/** Verification function for scalar reductions*/ +AcResult +acVerifyScalReductions(const AcMesh model, const AcScalReductionTestCase* testCases, const size_t numCases) +{ + printf("\nTesting scalar reductions:\n"); + + bool errors_found = false; + for (size_t i = 0; i < numCases; i++){ + AcReal model_reduction = acModelReduceScal(model, testCases[i].rtype, testCases[i].vtxbuf); + Error error = acGetError(model_reduction, testCases[i].candidate); + strcpy(error.label, testCases[i].label); + errors_found |= printErrorToScreen(error); + } + printf("%s\n", errors_found ? "Failure. Found errors in one or more scalar reductions" + : "Success. No errors found."); + + return errors_found ? AC_FAILURE : AC_SUCCESS; +} + +/** Verification function for vector reductions*/ +AcResult +acVerifyVecReductions(const AcMesh model, const AcVecReductionTestCase* testCases, const size_t numCases) +{ + printf("\nTesting vector reductions:\n"); + + bool errors_found = false; + for (size_t i = 0; i < numCases; i++){ + AcReal model_reduction = acModelReduceVec(model, testCases[i].rtype, testCases[i].a, testCases[i].b, testCases[i].c); + Error error = acGetError(model_reduction, testCases[i].candidate); + strcpy(error.label, testCases[i].label); + errors_found |= printErrorToScreen(error); + } + printf("%s\n", errors_found ? "Failure. Found errors in one or more vector reductions" + : "Success. No errors found."); + + return errors_found ? AC_FAILURE : AC_SUCCESS; }