Actual source code: ex22.c

petsc-3.13.6 2020-09-29
Report Typos and Errors
  1: static char help[] = "Tests the PetscByteSwap()\n";

  3:  #include <petscsys.h>

  5: int main(int argc,char **argv)
  6: {
  8:   PetscInt       oint[2],sint[2];
  9:   PetscBool      obool[2],sbool[2];
 10:   PetscScalar    oscalar[2],sscalar[2];
 11:   double         odouble[2],sdouble[2];
 12:   float          ofloat[2],sfloat[2];
 13:   short          oshort[2],sshort[2];

 15:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

 17:   sint[0]    = oint[0]    = 5;
 18:   sint[1]    = oint[1]    = 19;
 19:   sbool[0]   = obool[0]   = PETSC_FALSE;
 20:   sbool[1]   = obool[1]   = PETSC_TRUE;
 21:   sscalar[0] = oscalar[0] = 3.14159265;
 22:   sscalar[1] = oscalar[1] = 1.3806504e-23;
 23:   sdouble[0] = odouble[0] = 3.14159265;
 24:   sdouble[1] = odouble[1] = 1.3806504e-23;
 25:   sfloat[0]  = ofloat[0]  = 3.14159265;
 26:   sfloat[1]  = ofloat[1]  = 1.3806504e-23;
 27:   sshort[0]  = oshort[0]  = 5;
 28:   sshort[1]  = oshort[1]  = 19;

 30:   PetscByteSwap(sint,PETSC_INT,2);
 31:   PetscByteSwap(sbool,PETSC_BOOL,2);
 32:   PetscByteSwap(sscalar,PETSC_SCALAR,2);
 33:   PetscByteSwap(sdouble,PETSC_DOUBLE,2);
 34:   PetscByteSwap(sfloat,PETSC_FLOAT,2);
 35:   PetscByteSwap(sshort,PETSC_SHORT,2);

 37:   PetscByteSwap(sint,PETSC_INT,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:   if ((sint[0] !=oint[0])|| (sint[1] != oint[1]))             PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_INT\n");
 45:   if ((sbool[0] !=obool[0])|| (sbool[1] != obool[1]))         PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_BOOL\n");
 46:   if ((sscalar[0] !=oscalar[0])|| (sscalar[1] != oscalar[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_SCALAR\n");
 47:   if ((sdouble[0] !=odouble[0])|| (sdouble[1] != odouble[1])) PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_DOUBLE\n");
 48:   if ((sfloat[0] !=ofloat[0])|| (sfloat[1] != ofloat[1]))     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_FLOAT\n");
 49:   if ((sshort[0] !=oshort[0])|| (sshort[1] != oshort[1]))     PetscPrintf(PETSC_COMM_SELF,"Byteswap mismatch for PETSC_SHORT\n");

 51:   PetscFinalize();
 52:   return ierr;
 53: }


 56: /*TEST
 57:    
 58:    test:

 60: TEST*/