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