Actual source code: ex22.c
petsc-3.7.7 2017-09-25
1: static char help[] = "Tests the PetscByteSwap()\n";
3: #include <petscsys.h>
7: int main(int argc,char **argv)
8: {
10: PetscInt oint[2],sint[2];
11: PetscPrecision oenum[2],senum[2];
12: PetscBool obool[2],sbool[2];
13: PetscScalar oscalar[2],sscalar[2];
14: double odouble[2],sdouble[2];
15: float ofloat[2],sfloat[2];
16: short oshort[2],sshort[2];
18: PetscInitialize(&argc,&argv,(char*)0,help);
20: sint[0] = oint[0] = 5;
21: sint[1] = oint[1] = 19;
22: senum[0] = oenum[0] = PETSC_PRECISION_SINGLE;
23: senum[1] = oenum[1] = PETSC_PRECISION_DOUBLE;
24: sbool[0] = obool[0] = PETSC_FALSE;
25: sbool[1] = obool[1] = PETSC_TRUE;
26: sscalar[0] = oscalar[0] = 3.14159265;
27: sscalar[1] = oscalar[1] = 1.3806504e-23;
28: sdouble[0] = odouble[0] = 3.14159265;
29: sdouble[1] = odouble[1] = 1.3806504e-23;
30: sfloat[0] = ofloat[0] = 3.14159265;
31: sfloat[1] = ofloat[1] = 1.3806504e-23;
32: sshort[0] = oshort[0] = 5;
33: sshort[1] = oshort[1] = 19;
35: PetscByteSwap(sint,PETSC_INT,2);
36: PetscByteSwap(senum,PETSC_ENUM,2);
37: PetscByteSwap(sbool,PETSC_BOOL,2);
38: PetscByteSwap(sscalar,PETSC_SCALAR,2);
39: PetscByteSwap(sdouble,PETSC_DOUBLE,2);
40: PetscByteSwap(sfloat,PETSC_FLOAT,2);
41: PetscByteSwap(sshort,PETSC_SHORT,2);
43: PetscByteSwap(sint,PETSC_INT,2);
44: PetscByteSwap(senum,PETSC_ENUM,2);
45: PetscByteSwap(sbool,PETSC_BOOL,2);
46: PetscByteSwap(sscalar,PETSC_SCALAR,2);
47: PetscByteSwap(sdouble,PETSC_DOUBLE,2);
48: PetscByteSwap(sfloat,PETSC_FLOAT,2);
49: PetscByteSwap(sshort,PETSC_SHORT,2);
51: if ((sint[0] !=oint[0])|| (sint[1] != oint[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_INT\n");
52: if ((senum[0] !=oenum[0])|| (senum[1] != oenum[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_ENUM\n");
53: if ((sbool[0] !=obool[0])|| (sbool[1] != obool[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_BOOL\n");
54: if ((sscalar[0] !=oscalar[0])|| (sscalar[1] != oscalar[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_SCALAR\n");
55: if ((sdouble[0] !=odouble[0])|| (sdouble[1] != odouble[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_DOUBLE\n");
56: if ((sfloat[0] !=ofloat[0])|| (sfloat[1] != ofloat[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_FLOAT\n");
57: if ((sshort[0] !=oshort[0])|| (sshort[1] != oshort[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_SHORT\n");
59: PetscFinalize();
60: return 0;
61: }