Actual source code: ex22.c

petsc-3.3-p7 2013-05-11
  1: /*
  2:       Tests the PetscByteSwap()
  3: */
  4: #include <petscsys.h>

  8: int main(int argc,char **argv)
  9: {
 11:   PetscInt oint[2],sint[2];
 12:   PetscPrecision oenum[2],senum[2];
 13:   PetscBool obool[2],sbool[2];
 14:   PetscScalar oscalar[2],sscalar[2];
 15:   double odouble[2],sdouble[2];
 16:   float ofloat[2],sfloat[2];
 17:   short oshort[2],sshort[2];

 19:   PetscInitialize(&argc,&argv,(char *)0,0);

 21:   sint[0]    = oint[0]    = 5;
 22:   sint[1]    = oint[1]    = 19;
 23:   senum[0]   = oenum[0]   = PETSC_PRECISION_SINGLE;
 24:   senum[1]   = oenum[1]   = PETSC_PRECISION_DOUBLE;
 25:   sbool[0]   = obool[0]   = PETSC_FALSE;
 26:   sbool[1]   = obool[1]   = PETSC_TRUE;
 27:   sscalar[0] = oscalar[0] = 3.14159265;
 28:   sscalar[1] = oscalar[1] = 1.3806504e-23;
 29:   sdouble[0] = odouble[0] = 3.14159265;
 30:   sdouble[1] = odouble[1] = 1.3806504e-23;
 31:   sfloat[0]  = ofloat[0]  = 3.14159265;
 32:   sfloat[1]  = ofloat[1]  = 1.3806504e-23;
 33:   sshort[0]  = oshort[0]  = 5;
 34:   sshort[1]  = oshort[1]  = 19;

 36:   PetscByteSwap(sint,PETSC_INT,2);
 37:   PetscByteSwap(senum,PETSC_ENUM,2);
 38:   PetscByteSwap(sbool,PETSC_BOOL,2);
 39:   PetscByteSwap(sscalar,PETSC_SCALAR,2);
 40:   PetscByteSwap(sdouble,PETSC_DOUBLE,2);
 41:   PetscByteSwap(sfloat,PETSC_FLOAT,2);
 42:   PetscByteSwap(sshort,PETSC_SHORT,2);

 44:   PetscByteSwap(sint,PETSC_INT,2);
 45:   PetscByteSwap(senum,PETSC_ENUM,2);
 46:   PetscByteSwap(sbool,PETSC_BOOL,2);
 47:   PetscByteSwap(sscalar,PETSC_SCALAR,2);
 48:   PetscByteSwap(sdouble,PETSC_DOUBLE,2);
 49:   PetscByteSwap(sfloat,PETSC_FLOAT,2);
 50:   PetscByteSwap(sshort,PETSC_SHORT,2);

 52:   if ((sint[0] !=oint[0] )|| (sint[1] != oint[1])) {
 53:     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_INT\n");
 54:   }
 55:   if ((senum[0] !=oenum[0] )|| (senum[1] != oenum[1])) {
 56:     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_ENUM\n");
 57:   }
 58:   if ((sbool[0] !=obool[0] )|| (sbool[1] != obool[1])) {
 59:     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_BOOL\n");
 60:   }
 61:   if ((sscalar[0] !=oscalar[0] )|| (sscalar[1] != oscalar[1])) {
 62:     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_SCALAR\n");
 63:   }
 64:   if ((sdouble[0] !=odouble[0] )|| (sdouble[1] != odouble[1])) {
 65:     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_DOUBLE\n");
 66:   }
 67:   if ((sfloat[0] !=ofloat[0] )|| (sfloat[1] != ofloat[1])) {
 68:     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_FLOAT\n");
 69:   }
 70:   if ((sshort[0] !=oshort[0] )|| (sshort[1] != oshort[1])) {
 71:     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_SHORT\n");
 72:   }

 74:   PetscFinalize();
 75:   return 0;
 76: }