Actual source code: ex15.cxx
1: static char help[] = "Tests inclusion of petscsystypes.h.\n\n";
3: // Simulate a third-party configuration macro sharing a suffix with a PETSc macro.
4: #define PETSC_DEFINED_TEST 1
5: #define DEFINED_TEST 1
7: #include <petscsys.h>
9: static_assert(PetscDefined(DEFINED_TEST), "PetscDefined() expanded its argument before prepending PETSC_");
10: static_assert(PetscIfPetscDefined(DEFINED_TEST, 1, 0), "PetscIfPetscDefined() expanded its argument before prepending PETSC_");
12: #if defined(PETSC_HAVE_COMPLEX)
13: template <class Type>
14: PetscErrorCode TestComplexOperators(Type x, PetscBool check, double &ans)
15: {
16: double res;
17: PetscComplex z = x;
19: PetscFunctionBeginUser;
20: (void)z;
21: z = x;
22: z += x;
23: z = z + x;
24: z = x + z;
25: z = x;
26: z -= x;
27: z = z - x;
28: z = x - z;
29: z = x;
30: z *= x;
31: z = z * x;
32: z = x * z;
33: z = x;
34: z /= x;
35: z = z / x;
36: z = x / z;
37: (void)(z == x);
38: (void)(x == z);
39: (void)(z != x);
40: (void)(x != z);
41: res = PetscRealPartComplex(z);
42: if (check) PetscCheck(PetscAbs(ans - res) < 1e-5, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Expected %g, but get incorrect result %g", ans, res);
43: else ans = res;
44: PetscFunctionReturn(PETSC_SUCCESS);
45: }
46: #endif
48: int main(int argc, char **argv)
49: {
50: /* numeric types */
51: PetscScalar svalue;
52: PetscReal rvalue;
53: #if defined(PETSC_HAVE_COMPLEX)
54: PetscComplex cvalue;
55: #endif
57: /* integer types */
58: PetscInt64 i64;
59: PetscInt i;
60: PetscBLASInt bi;
61: PetscMPIInt rank;
63: /* PETSc types */
64: PetscBool b;
65: PetscErrorCode ierr;
66: PetscClassId cid;
67: PetscEnum e;
68: PetscShort s;
69: char c;
70: PetscFloat f;
71: PetscLogDouble ld;
72: PetscObjectId oid;
73: PetscObjectState ost;
75: /* Enums */
76: PetscCopyMode cp;
77: PetscDataType dt;
78: PetscFileMode fm;
79: PetscDLMode dlm;
80: PetscBinarySeekType bsk;
81: PetscBuildTwoSidedType b2s;
82: InsertMode im;
83: PetscSubcommType subct;
85: /* Sys objects */
86: PetscObject obj;
87: PetscRandom rand;
88: PetscToken token;
89: PetscFunctionList flist;
90: PetscDLHandle dlh;
91: PetscObjectList olist;
92: PetscDLLibrary dlist;
93: PetscContainer cont;
94: PetscSubcomm subc;
95: PetscHeap pheap;
96: PetscShmComm scomm;
97: PetscOmpCtrl octrl;
98: PetscSegBuffer sbuff;
99: PetscOptionsHelpPrinted oh;
101: PetscFunctionBeginUser;
102: PetscCall(PetscInitialize(&argc, &argv, nullptr, help));
103: svalue = 0.0;
104: rvalue = 0.0;
105: #if defined(PETSC_HAVE_COMPLEX)
106: cvalue = 0.0;
107: #endif
109: #if defined(PETSC_HAVE_COMPLEX)
110: double ans = 0.0;
112: // PetscComplex .op. integer
113: PetscCall(TestComplexOperators((PetscReal)1.0, PETSC_FALSE, ans)); // assuming with PetscReal, we get a correct answer
114: PetscCall(TestComplexOperators((char)1, PETSC_TRUE, ans)); // check against the answer
115: PetscCall(TestComplexOperators((signed char)1, PETSC_TRUE, ans));
116: PetscCall(TestComplexOperators((signed short)1, PETSC_TRUE, ans));
117: PetscCall(TestComplexOperators((signed int)1, PETSC_TRUE, ans));
118: PetscCall(TestComplexOperators((signed long)1, PETSC_TRUE, ans));
119: PetscCall(TestComplexOperators((signed long long)1, PETSC_TRUE, ans));
121: PetscCall(TestComplexOperators((unsigned char)1, PETSC_TRUE, ans));
122: PetscCall(TestComplexOperators((unsigned short)1, PETSC_TRUE, ans));
123: PetscCall(TestComplexOperators((unsigned int)1, PETSC_TRUE, ans));
124: PetscCall(TestComplexOperators((unsigned long)1, PETSC_TRUE, ans));
125: PetscCall(TestComplexOperators((unsigned long long)1, PETSC_TRUE, ans));
127: // PetscComplex .op. floating point
128: PetscCall(TestComplexOperators((PetscReal)0.5, PETSC_FALSE, ans)); // get an answer again
129: #if defined(PETSC_HAVE_REAL___FP16)
130: PetscCall(TestComplexOperators((__fp16)0.5, PETSC_TRUE, ans));
131: #endif
132: PetscCall(TestComplexOperators((float)0.5, PETSC_TRUE, ans));
133: PetscCall(TestComplexOperators((double)0.5, PETSC_TRUE, ans));
134: PetscCall(TestComplexOperators((long double)0.5, PETSC_TRUE, ans));
135: #if defined(PETSC_HAVE_REAL___FLOAT128)
136: PetscCall(TestComplexOperators((__float128)0.5, PETSC_TRUE, ans));
137: #endif
139: #endif
141: i64 = 0;
142: i = 0;
143: bi = 0;
144: rank = 0;
146: b = PETSC_FALSE;
147: cid = 0;
148: e = ENUM_DUMMY;
149: s = 0;
150: c = '\0';
151: f = 0;
152: ld = 0.0;
153: oid = 0;
154: ost = 0;
156: cp = PETSC_COPY_VALUES;
157: dt = PETSC_DATATYPE_UNKNOWN;
158: fm = FILE_MODE_READ;
159: dlm = PETSC_DL_DECIDE;
160: bsk = PETSC_BINARY_SEEK_SET;
161: b2s = PETSC_BUILDTWOSIDED_NOTSET;
162: im = INSERT_VALUES;
163: subct = PETSC_SUBCOMM_GENERAL;
165: obj = nullptr;
166: rand = nullptr;
167: token = nullptr;
168: flist = nullptr;
169: dlh = nullptr;
170: olist = nullptr;
171: dlist = nullptr;
172: cont = nullptr;
173: subc = nullptr;
174: pheap = nullptr;
175: scomm = nullptr;
176: octrl = nullptr;
177: sbuff = nullptr;
178: oh = nullptr;
180: /* prevent to issue warning about unused-but-set variables */
181: (void)help;
183: (void)svalue;
184: (void)rvalue;
185: #if defined(PETSC_HAVE_COMPLEX)
186: (void)cvalue;
187: #endif
188: (void)i64;
189: (void)i;
190: (void)bi;
191: (void)rank;
193: (void)b;
194: (void)ierr;
195: (void)cid;
196: (void)e;
197: (void)s;
198: (void)c;
199: (void)f;
200: (void)ld;
201: (void)oid;
202: (void)ost;
204: (void)cp;
205: (void)dt;
206: (void)fm;
207: (void)dlm;
208: (void)bsk;
209: (void)b2s;
210: (void)im;
211: (void)subct;
213: (void)obj;
214: (void)rand;
215: (void)token;
216: (void)flist;
217: (void)dlh;
218: (void)olist;
219: (void)dlist;
220: (void)cont;
221: (void)subc;
222: (void)pheap;
223: (void)scomm;
224: (void)octrl;
225: (void)sbuff;
226: (void)oh;
227: PetscCall(PetscFinalize());
228: return 0;
229: }
231: /*TEST
233: test:
234: output_file: output/empty.out
236: TEST*/