Changes after code review by Johannes, and clang-format
This commit is contained in:
@@ -79,6 +79,12 @@ AcResult acMeshCreate(const AcMeshInfo mesh_info, AcMesh* mesh);
|
|||||||
/** */
|
/** */
|
||||||
AcResult acMeshDestroy(AcMesh* mesh);
|
AcResult acMeshDestroy(AcMesh* mesh);
|
||||||
|
|
||||||
|
/** */
|
||||||
|
AcScalReductionTestCase acCreateScalReductionTestCase(const char* label, const VertexBufferHandle vtxbuf, const ReductionType rtype);
|
||||||
|
|
||||||
|
/** */
|
||||||
|
AcVecReductionTestCase acCreateVecReductionTestCase(const char* label, const VertexBufferHandle a, const VertexBufferHandle b, const VertexBufferHandle c, const ReductionType rtype);
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
AcResult acMeshSet(const AcReal value, AcMesh* mesh);
|
AcResult acMeshSet(const AcReal value, AcMesh* mesh);
|
||||||
|
|
||||||
|
@@ -57,19 +57,19 @@ main(void)
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
// Define scalar reduction tests here
|
// Define scalar reduction tests here
|
||||||
std::vector<AcScalReductionTestCase> scalarReductionTests{
|
std::vector<AcScalReductionTestCase> scalarReductionTests{
|
||||||
AcScalReductionTestCase{"Scalar MAX", VTXBUF_UUX, RTYPE_MAX, 0},
|
acCreateScalReductionTestCase("Scalar MAX", VTXBUF_UUX, RTYPE_MAX),
|
||||||
AcScalReductionTestCase{"Scalar MIN", VTXBUF_UUX, RTYPE_MIN, 0},
|
acCreateScalReductionTestCase("Scalar MIN", VTXBUF_UUX, RTYPE_MIN),
|
||||||
AcScalReductionTestCase{"Scalar RMS", VTXBUF_UUX, RTYPE_RMS, 0},
|
acCreateScalReductionTestCase("Scalar RMS", VTXBUF_UUX, RTYPE_RMS),
|
||||||
AcScalReductionTestCase{"Scalar RMS_EXP", VTXBUF_UUX, RTYPE_RMS_EXP, 0},
|
acCreateScalReductionTestCase("Scalar RMS_EXP", VTXBUF_UUX, RTYPE_RMS_EXP),
|
||||||
AcScalReductionTestCase{"Scalar SUM", VTXBUF_UUX, RTYPE_SUM, 0}
|
acCreateScalReductionTestCase("Scalar SUM", VTXBUF_UUX, RTYPE_SUM)
|
||||||
};
|
};
|
||||||
// Define vector reduction tests here
|
// Define vector reduction tests here
|
||||||
std::vector<AcVecReductionTestCase> vectorReductionTests{
|
std::vector<AcVecReductionTestCase> vectorReductionTests{
|
||||||
AcVecReductionTestCase{"Vector MAX", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_MAX, 0},
|
acCreateVecReductionTestCase("Vector MAX", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_MAX),
|
||||||
AcVecReductionTestCase{"Vector MIN", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_MIN, 0},
|
acCreateVecReductionTestCase("Vector MIN", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_MIN),
|
||||||
AcVecReductionTestCase{"Vector RMS", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_RMS, 0},
|
acCreateVecReductionTestCase("Vector RMS", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_RMS),
|
||||||
AcVecReductionTestCase{"Vector RMS_EXP", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_RMS_EXP, 0},
|
acCreateVecReductionTestCase("Vector RMS_EXP", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_RMS_EXP),
|
||||||
AcVecReductionTestCase{"Vector SUM", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_SUM, 0}
|
acCreateVecReductionTestCase("Vector SUM", VTXBUF_UUX, VTXBUF_UUY, VTXBUF_UUZ, RTYPE_SUM)
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
@@ -1285,7 +1285,7 @@ acGridIntegrate(const Stream stream, const AcReal dt)
|
|||||||
|
|
||||||
const Device device = grid.device;
|
const Device device = grid.device;
|
||||||
const int3 nn = grid.nn;
|
const int3 nn = grid.nn;
|
||||||
//CommData corner_data = grid.corner_data; // Do not rm: required for corners
|
// CommData corner_data = grid.corner_data; // Do not rm: required for corners
|
||||||
CommData edgex_data = grid.edgex_data;
|
CommData edgex_data = grid.edgex_data;
|
||||||
CommData edgey_data = grid.edgey_data;
|
CommData edgey_data = grid.edgey_data;
|
||||||
CommData edgez_data = grid.edgez_data;
|
CommData edgez_data = grid.edgez_data;
|
||||||
@@ -1621,7 +1621,6 @@ acGridPeriodicBoundconds(const Stream stream)
|
|||||||
return AC_SUCCESS;
|
return AC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static AcResult
|
static AcResult
|
||||||
acMPIReduceScal(const AcReal local_result, const ReductionType rtype, AcReal* result)
|
acMPIReduceScal(const AcReal local_result, const ReductionType rtype, AcReal* result)
|
||||||
{
|
{
|
||||||
@@ -1629,19 +1628,22 @@ acMPIReduceScal(const AcReal local_result, const ReductionType rtype, AcReal* re
|
|||||||
MPI_Op op;
|
MPI_Op op;
|
||||||
if (rtype == RTYPE_MAX) {
|
if (rtype == RTYPE_MAX) {
|
||||||
op = MPI_MAX;
|
op = MPI_MAX;
|
||||||
} else if (rtype == RTYPE_MIN) {
|
}
|
||||||
|
else if (rtype == RTYPE_MIN) {
|
||||||
op = MPI_MIN;
|
op = MPI_MIN;
|
||||||
} else if (rtype == RTYPE_RMS || rtype == RTYPE_RMS_EXP || rtype == RTYPE_SUM) {
|
}
|
||||||
|
else if (rtype == RTYPE_RMS || rtype == RTYPE_RMS_EXP || rtype == RTYPE_SUM) {
|
||||||
op = MPI_SUM;
|
op = MPI_SUM;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
ERROR("Unrecognised rtype");
|
ERROR("Unrecognised rtype");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if AC_DOUBLE_PRECISION == 1
|
#if AC_DOUBLE_PRECISION == 1
|
||||||
MPI_Datatype datatype = MPI_DOUBLE;
|
MPI_Datatype datatype = MPI_DOUBLE;
|
||||||
#else
|
#else
|
||||||
MPI_Datatype datatype = MPI_FLOAT;
|
MPI_Datatype datatype = MPI_FLOAT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int rank;
|
int rank;
|
||||||
@@ -1655,12 +1657,12 @@ acMPIReduceScal(const AcReal local_result, const ReductionType rtype, AcReal* re
|
|||||||
MPI_Allreduce(&local_result, &mpi_res, 1, datatype, op, MPI_COMM_WORLD);
|
MPI_Allreduce(&local_result, &mpi_res, 1, datatype, op, MPI_COMM_WORLD);
|
||||||
|
|
||||||
if (rtype == RTYPE_RMS || rtype == RTYPE_RMS_EXP) {
|
if (rtype == RTYPE_RMS || rtype == RTYPE_RMS_EXP) {
|
||||||
const AcReal inv_n = AcReal(1.) / (grid.nn.x*grid.decomposition.x * grid.nn.y*grid.decomposition.y * grid.nn.z*grid.decomposition.z);
|
const AcReal inv_n = AcReal(1.) / (grid.nn.x * grid.decomposition.x * grid.nn.y *
|
||||||
|
grid.decomposition.y * grid.nn.z * grid.decomposition.z);
|
||||||
mpi_res = sqrt(inv_n * mpi_res);
|
mpi_res = sqrt(inv_n * mpi_res);
|
||||||
}
|
}
|
||||||
*result = mpi_res;
|
*result = mpi_res;
|
||||||
return AC_SUCCESS;
|
return AC_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AcResult
|
AcResult
|
||||||
@@ -1668,10 +1670,8 @@ acGridReduceScal(const Stream stream, const ReductionType rtype,
|
|||||||
const VertexBufferHandle vtxbuf_handle, AcReal* result)
|
const VertexBufferHandle vtxbuf_handle, AcReal* result)
|
||||||
{
|
{
|
||||||
ERRCHK(grid.initialized);
|
ERRCHK(grid.initialized);
|
||||||
// acGridSynchronizeStream(stream);
|
|
||||||
|
|
||||||
const Device device = grid.device;
|
const Device device = grid.device;
|
||||||
//const int3 nn = grid.nn;
|
|
||||||
|
|
||||||
acGridSynchronizeStream(STREAM_ALL);
|
acGridSynchronizeStream(STREAM_ALL);
|
||||||
MPI_Barrier(MPI_COMM_WORLD);
|
MPI_Barrier(MPI_COMM_WORLD);
|
||||||
@@ -1679,20 +1679,16 @@ acGridReduceScal(const Stream stream, const ReductionType rtype,
|
|||||||
AcReal local_result;
|
AcReal local_result;
|
||||||
acDeviceReduceScal(device, stream, rtype, vtxbuf_handle, &local_result);
|
acDeviceReduceScal(device, stream, rtype, vtxbuf_handle, &local_result);
|
||||||
|
|
||||||
return acMPIReduceScal(local_result,rtype,result);
|
return acMPIReduceScal(local_result, rtype, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AcResult
|
AcResult
|
||||||
acGridReduceVec(const Stream stream, const ReductionType rtype,
|
acGridReduceVec(const Stream stream, const ReductionType rtype, const VertexBufferHandle vtxbuf0,
|
||||||
const VertexBufferHandle vtxbuf0, const VertexBufferHandle vtxbuf1,
|
const VertexBufferHandle vtxbuf1, const VertexBufferHandle vtxbuf2, AcReal* result)
|
||||||
const VertexBufferHandle vtxbuf2, AcReal* result)
|
|
||||||
{
|
{
|
||||||
ERRCHK(grid.initialized);
|
ERRCHK(grid.initialized);
|
||||||
// acGridSynchronizeStream(stream);
|
|
||||||
|
|
||||||
const Device device = grid.device;
|
const Device device = grid.device;
|
||||||
//const int3 nn = grid.nn;
|
|
||||||
|
|
||||||
acGridSynchronizeStream(STREAM_ALL);
|
acGridSynchronizeStream(STREAM_ALL);
|
||||||
MPI_Barrier(MPI_COMM_WORLD);
|
MPI_Barrier(MPI_COMM_WORLD);
|
||||||
@@ -1700,7 +1696,7 @@ acGridReduceVec(const Stream stream, const ReductionType rtype,
|
|||||||
AcReal local_result;
|
AcReal local_result;
|
||||||
acDeviceReduceVec(device, stream, rtype, vtxbuf0, vtxbuf1, vtxbuf2, &local_result);
|
acDeviceReduceVec(device, stream, rtype, vtxbuf0, vtxbuf1, vtxbuf2, &local_result);
|
||||||
|
|
||||||
return acMPIReduceScal(local_result,rtype,result);
|
return acMPIReduceScal(local_result, rtype, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // AC_MPI_ENABLED
|
#endif // AC_MPI_ENABLED
|
||||||
|
@@ -106,7 +106,8 @@ get_max_abs_error(const VertexBufferHandle vtxbuf_handle, const AcMesh model_mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
error.handle = vtxbuf_handle;
|
error.handle = vtxbuf_handle;
|
||||||
strcpy(error.label, vtxbuf_names[vtxbuf_handle]);
|
strncpy(error.label, vtxbuf_names[vtxbuf_handle], ERROR_LABEL_LENGTH - 1);
|
||||||
|
error.label[ERROR_LABEL_LENGTH - 1] = '\0';
|
||||||
error.maximum_magnitude = get_maximum_magnitude(model_vtxbuf, model_mesh.info);
|
error.maximum_magnitude = get_maximum_magnitude(model_vtxbuf, model_mesh.info);
|
||||||
error.minimum_magnitude = get_minimum_magnitude(model_vtxbuf, model_mesh.info);
|
error.minimum_magnitude = get_minimum_magnitude(model_vtxbuf, model_mesh.info);
|
||||||
|
|
||||||
@@ -179,15 +180,17 @@ acVerifyMesh(const AcMesh model, const AcMesh candidate)
|
|||||||
|
|
||||||
/** Verification function for scalar reductions*/
|
/** Verification function for scalar reductions*/
|
||||||
AcResult
|
AcResult
|
||||||
acVerifyScalReductions(const AcMesh model, const AcScalReductionTestCase* testCases, const size_t numCases)
|
acVerifyScalReductions(const AcMesh model, const AcScalReductionTestCase* testCases,
|
||||||
|
const size_t numCases)
|
||||||
{
|
{
|
||||||
printf("\nTesting scalar reductions:\n");
|
printf("\nTesting scalar reductions:\n");
|
||||||
|
|
||||||
bool errors_found = false;
|
bool errors_found = false;
|
||||||
for (size_t i = 0; i < numCases; i++){
|
for (size_t i = 0; i < numCases; i++) {
|
||||||
AcReal model_reduction = acModelReduceScal(model, testCases[i].rtype, testCases[i].vtxbuf);
|
AcReal model_reduction = acModelReduceScal(model, testCases[i].rtype, testCases[i].vtxbuf);
|
||||||
Error error = acGetError(model_reduction, testCases[i].candidate);
|
Error error = acGetError(model_reduction, testCases[i].candidate);
|
||||||
strcpy(error.label, testCases[i].label);
|
strncpy(error.label, testCases[i].label, ERROR_LABEL_LENGTH - 1);
|
||||||
|
error.label[ERROR_LABEL_LENGTH - 1] = '\0';
|
||||||
errors_found |= printErrorToScreen(error);
|
errors_found |= printErrorToScreen(error);
|
||||||
}
|
}
|
||||||
printf("%s\n", errors_found ? "Failure. Found errors in one or more scalar reductions"
|
printf("%s\n", errors_found ? "Failure. Found errors in one or more scalar reductions"
|
||||||
@@ -198,15 +201,18 @@ acVerifyScalReductions(const AcMesh model, const AcScalReductionTestCase* testCa
|
|||||||
|
|
||||||
/** Verification function for vector reductions*/
|
/** Verification function for vector reductions*/
|
||||||
AcResult
|
AcResult
|
||||||
acVerifyVecReductions(const AcMesh model, const AcVecReductionTestCase* testCases, const size_t numCases)
|
acVerifyVecReductions(const AcMesh model, const AcVecReductionTestCase* testCases,
|
||||||
|
const size_t numCases)
|
||||||
{
|
{
|
||||||
printf("\nTesting vector reductions:\n");
|
printf("\nTesting vector reductions:\n");
|
||||||
|
|
||||||
bool errors_found = false;
|
bool errors_found = false;
|
||||||
for (size_t i = 0; i < numCases; i++){
|
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);
|
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);
|
Error error = acGetError(model_reduction, testCases[i].candidate);
|
||||||
strcpy(error.label, testCases[i].label);
|
strncpy(error.label, testCases[i].label, ERROR_LABEL_LENGTH - 1);
|
||||||
|
error.label[ERROR_LABEL_LENGTH - 1] = '\0';
|
||||||
errors_found |= printErrorToScreen(error);
|
errors_found |= printErrorToScreen(error);
|
||||||
}
|
}
|
||||||
printf("%s\n", errors_found ? "Failure. Found errors in one or more vector reductions"
|
printf("%s\n", errors_found ? "Failure. Found errors in one or more vector reductions"
|
||||||
@@ -214,3 +220,36 @@ acVerifyVecReductions(const AcMesh model, const AcVecReductionTestCase* testCase
|
|||||||
|
|
||||||
return errors_found ? AC_FAILURE : AC_SUCCESS;
|
return errors_found ? AC_FAILURE : AC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Constructor for scalar reduction test case */
|
||||||
|
AcScalReductionTestCase
|
||||||
|
acCreateScalReductionTestCase(const char* label, const VertexBufferHandle vtxbuf, const ReductionType rtype)
|
||||||
|
{
|
||||||
|
AcScalReductionTestCase testCase;
|
||||||
|
|
||||||
|
strncpy(testCase.label,label,ERROR_LABEL_LENGTH - 1);
|
||||||
|
testCase.label[ERROR_LABEL_LENGTH - 1] = '\0';
|
||||||
|
testCase.vtxbuf = vtxbuf;
|
||||||
|
testCase.rtype = rtype;
|
||||||
|
testCase.candidate = 0;
|
||||||
|
|
||||||
|
return testCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Constructor for vector reduction test case */
|
||||||
|
AcVecReductionTestCase
|
||||||
|
acCreateVecReductionTestCase(const char* label, const VertexBufferHandle a,
|
||||||
|
const VertexBufferHandle b, const VertexBufferHandle c, const ReductionType rtype)
|
||||||
|
{
|
||||||
|
AcVecReductionTestCase testCase;
|
||||||
|
|
||||||
|
strncpy(testCase.label,label,ERROR_LABEL_LENGTH - 1);
|
||||||
|
testCase.label[ERROR_LABEL_LENGTH - 1] = '\0';
|
||||||
|
testCase.a = a;
|
||||||
|
testCase.b = b;
|
||||||
|
testCase.c = c;
|
||||||
|
testCase.rtype = rtype;
|
||||||
|
testCase.candidate = 0;
|
||||||
|
|
||||||
|
return testCase;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user