Skip to content

Commit 78ee22c

Browse files
committed
Change mixed precision tests to use the same source file
1 parent c66094c commit 78ee22c

28 files changed

+333
-2654
lines changed

tests/t502-operator-mixed.c

Lines changed: 0 additions & 125 deletions
This file was deleted.

tests/t502-operator.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
/// @file
22
/// Test creation, action, and destruction for mass matrix operator with multiple components
33
/// \test Test creation, action, and destruction for mass matrix operator with multiple components
4-
#include "t502-operator.h"
4+
5+
//TESTARGS {ceed_resource} fp32
6+
//TESTARGS {ceed_resource} fp64
57

68
#include <ceed.h>
79
#include <math.h>
810
#include <stdio.h>
911
#include <stdlib.h>
12+
#include <string.h>
13+
14+
#include "t502-operator.h"
1015

1116
int main(int argc, char **argv) {
1217
Ceed ceed;
@@ -18,8 +23,21 @@ int main(int argc, char **argv) {
1823
CeedInt num_elem = 15, p = 5, q = 8;
1924
CeedInt num_nodes_x = num_elem + 1, num_nodes_u = num_elem * (p - 1) + 1;
2025
CeedInt ind_x[num_elem * 2], ind_u[num_elem * p];
26+
CeedScalarType precision = CEED_SCALAR_TYPE;
27+
CeedScalar epsilon = CEED_EPSILON;
2128

2229
CeedInit(argv[1], &ceed);
30+
if (argc == 3) {
31+
if (!strcmp(argv[2], "fp32")) {
32+
precision = CEED_SCALAR_FP32;
33+
epsilon = FLT_EPSILON;
34+
} else if (!strcmp(argv[2], "fp64")) {
35+
precision = CEED_SCALAR_FP64;
36+
} else {
37+
printf("Unknown scalar type: %s\n", argv[2]);
38+
exit(1);
39+
}
40+
}
2341

2442
CeedVectorCreate(ceed, num_nodes_x, &x);
2543
{
@@ -69,11 +87,13 @@ int main(int argc, char **argv) {
6987
CeedOperatorSetField(op_setup, "weight", CEED_ELEMRESTRICTION_NONE, basis_x, CEED_VECTOR_NONE);
7088
CeedOperatorSetField(op_setup, "dx", elem_restriction_x, basis_x, CEED_VECTOR_ACTIVE);
7189
CeedOperatorSetField(op_setup, "rho", elem_restriction_q_data, CEED_BASIS_NONE, CEED_VECTOR_ACTIVE);
90+
CeedOperatorSetPrecision(op_setup, precision);
7291

7392
CeedOperatorCreate(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass);
7493
CeedOperatorSetField(op_mass, "rho", elem_restriction_q_data, CEED_BASIS_NONE, q_data);
7594
CeedOperatorSetField(op_mass, "u", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE);
7695
CeedOperatorSetField(op_mass, "v", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE);
96+
CeedOperatorSetPrecision(op_mass, precision);
7797

7898
CeedOperatorApply(op_setup, x, q_data, CEED_REQUEST_IMMEDIATE);
7999

@@ -100,8 +120,8 @@ int main(int argc, char **argv) {
100120
sum_2 += v_array[2 * i + 1];
101121
}
102122
CeedVectorRestoreArrayRead(v, &v_array);
103-
if (fabs(sum_1 - 1.) > 1000. * CEED_EPSILON) printf("Computed Area: %f != True Area: 1.0\n", sum_1);
104-
if (fabs(sum_2 - 2.) > 1000. * CEED_EPSILON) printf("Computed Area: %f != True Area: 2.0\n", sum_2);
123+
if (fabs(sum_1 - 1.) > 1000. * epsilon) printf("Computed Area: %f != True Area: 1.0\n", sum_1);
124+
if (fabs(sum_2 - 2.) > 1000. * epsilon) printf("Computed Area: %f != True Area: 2.0\n", sum_2);
105125
}
106126

107127
CeedVectorDestroy(&x);

tests/t503-operator-mixed.c

Lines changed: 0 additions & 114 deletions
This file was deleted.

tests/t503-operator.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
/// @file
22
/// Test creation, action, and destruction for mass matrix operator with passive inputs and outputs
33
/// \test Test creation, action, and destruction for mass matrix operator with passive inputs and outputs
4+
5+
//TESTARGS {ceed_resource} fp32
6+
//TESTARGS {ceed_resource} fp64
7+
48
#include <ceed.h>
59
#include <math.h>
610
#include <stdio.h>
711
#include <stdlib.h>
12+
#include <string.h>
813

914
#include "t500-operator.h"
1015

@@ -18,8 +23,21 @@ int main(int argc, char **argv) {
1823
CeedInt num_elem = 15, p = 5, q = 8;
1924
CeedInt num_nodes_x = num_elem + 1, num_nodes_u = num_elem * (p - 1) + 1;
2025
CeedInt ind_x[num_elem * 2], ind_u[num_elem * p];
26+
CeedScalarType precision = CEED_SCALAR_TYPE;
27+
CeedScalar epsilon = CEED_EPSILON;
2128

2229
CeedInit(argv[1], &ceed);
30+
if (argc == 3) {
31+
if (!strcmp(argv[2], "fp32")) {
32+
precision = CEED_SCALAR_FP32;
33+
epsilon = FLT_EPSILON;
34+
} else if (!strcmp(argv[2], "fp64")) {
35+
precision = CEED_SCALAR_FP64;
36+
} else {
37+
printf("Unknown scalar type: %s\n", argv[2]);
38+
exit(1);
39+
}
40+
}
2341

2442
// Vectors
2543
CeedVectorCreate(ceed, num_nodes_x, &x);
@@ -70,11 +88,13 @@ int main(int argc, char **argv) {
7088
CeedOperatorSetField(op_setup, "weight", CEED_ELEMRESTRICTION_NONE, basis_x, CEED_VECTOR_NONE);
7189
CeedOperatorSetField(op_setup, "dx", elem_restriction_x, basis_x, x);
7290
CeedOperatorSetField(op_setup, "rho", elem_restriction_q_data, CEED_BASIS_NONE, q_data);
91+
CeedOperatorSetPrecision(op_setup, precision);
7392

7493
CeedOperatorCreate(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass);
7594
CeedOperatorSetField(op_mass, "rho", elem_restriction_q_data, CEED_BASIS_NONE, q_data);
7695
CeedOperatorSetField(op_mass, "u", elem_restriction_u, basis_u, u);
7796
CeedOperatorSetField(op_mass, "v", elem_restriction_u, basis_u, v);
97+
CeedOperatorSetPrecision(op_mass, precision);
7898

7999
// Note - It is atypical to use only passive fields; this test is intended
80100
// as a test for all passive input modes rather than as an example.
@@ -90,7 +110,7 @@ int main(int argc, char **argv) {
90110
CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array);
91111
for (CeedInt i = 0; i < num_nodes_u; i++) sum += v_array[i];
92112
CeedVectorRestoreArrayRead(v, &v_array);
93-
if (fabs(sum - 1.) > 1000. * CEED_EPSILON) printf("Computed Area: %f != True Area: 1.0\n", sum);
113+
if (fabs(sum - 1.) > 1000. * epsilon) printf("Computed Area: %f != True Area: 1.0\n", sum);
94114
}
95115

96116
CeedVectorDestroy(&x);

0 commit comments

Comments
 (0)