Actual source code: ptype.c

  1: /*$Id: ptype.c,v 1.7 2001/08/06 21:14:10 bsmith Exp $*/
  2: /*
  3:      Provides utility routines for manipulating any type of PETSc object.
  4: */
 5:  #include petsc.h

  7: #undef __FUNCT__  
  9: /*@
 10:      PetscDataTypeToMPIDataType - Converts the PETSc name of a datatype to its MPI name.

 12:    Not collective

 14:     Input Parameter:
 15: .     ptype - the PETSc datatype name (for example PETSC_DOUBLE)

 17:     Output Parameter:
 18: .     mtype - the MPI datatype (for example MPI_DOUBLE, ...)

 20:     Level: advanced
 21:    
 22: .seealso: PetscDataType, PetscDataTypeGetName()
 23: @*/
 24: int PetscDataTypeToMPIDataType(PetscDataType ptype,MPI_Datatype* mtype)
 25: {
 27:   if (ptype == PETSC_INT) {
 28:     *mtype = MPI_INT;
 29:   } else if (ptype == PETSC_DOUBLE) {
 30:     *mtype = MPI_DOUBLE;
 31: #if defined(PETSC_USE_COMPLEX)
 32:   } else if (ptype == PETSC_COMPLEX) {
 33:     *mtype = MPIU_COMPLEX;
 34: #endif
 35:   } else if (ptype == PETSC_LONG) {
 36:     *mtype = MPI_LONG;
 37:   } else if (ptype == PETSC_SHORT) {
 38:     *mtype = MPI_SHORT;
 39:   } else if (ptype == PETSC_FLOAT) {
 40:     *mtype = MPI_FLOAT;
 41:   } else if (ptype == PETSC_CHAR) {
 42:     *mtype = MPI_CHAR;
 43:   } else if (ptype == PETSC_LOGICAL) {
 44:     *mtype = MPI_BYTE;
 45:   } else {
 46:     SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
 47:   }
 48:   return(0);
 49: }

 51: typedef enum {PETSC_INT_SIZE = sizeof(int),PETSC_DOUBLE_SIZE = sizeof(double),
 52:               PETSC_COMPLEX_SIZE = sizeof(PetscScalar),PETSC_LONG_SIZE=sizeof(long),
 53:               PETSC_SHORT_SIZE = sizeof(short),PETSC_FLOAT_SIZE = sizeof(float),
 54:               PETSC_CHAR_SIZE = sizeof(char),PETSC_LOGICAL_SIZE = 1} PetscDataTypeSize;
 55: #if defined(PETSC_USE_COMPLEX)
 56: #define PETSC_SCALAR_SIZE PETSC_COMPLEX_SIZE
 57: #else
 58: #define PETSC_SCALAR_SIZE PETSC_DOUBLE_SIZE
 59: #endif
 60: #if defined(PETSC_USE_SINGLE)
 61: #define PETSC_REAL_SIZE PETSC_FLOAT_SIZE
 62: #else
 63: #define PETSC_REAL_SIZE PETSC_DOUBLE_SIZE
 64: #endif
 65: #define PETSC_FORTRANADDR_SIZE PETSC_LONG_SIZE


 68: #undef __FUNCT__  
 70: /*@
 71:      PetscDataTypeGetSize - Gets the size (in bytes) of a PETSc datatype

 73:    Not collective

 75:     Input Parameter:
 76: .     ptype - the PETSc datatype name (for example PETSC_DOUBLE)

 78:     Output Parameter:
 79: .     size - the size in bytes (for example the size of PETSC_DOUBLE is 8)

 81:     Level: advanced
 82:    
 83: .seealso: PetscDataType, PetscDataTypeGetName(), PetscDataTypeToMPIDataType()
 84: @*/
 85: int PetscDataTypeGetSize(PetscDataType ptype,int *size)
 86: {
 88:   if (ptype == PETSC_INT) {
 89:     *size = PETSC_INT_SIZE;
 90:   } else if (ptype == PETSC_DOUBLE) {
 91:     *size = PETSC_DOUBLE_SIZE;
 92: #if defined(PETSC_USE_COMPLEX)
 93:   } else if (ptype == PETSC_COMPLEX) {
 94:     *size = PETSC_COMPLEX_SIZE;
 95: #endif
 96:   } else if (ptype == PETSC_LONG) {
 97:     *size = PETSC_LONG_SIZE;
 98:   } else if (ptype == PETSC_SHORT) {
 99:     *size = PETSC_SHORT_SIZE;
100:   } else if (ptype == PETSC_FLOAT) {
101:     *size = PETSC_FLOAT_SIZE;
102:   } else if (ptype == PETSC_CHAR) {
103:     *size = PETSC_CHAR_SIZE;
104:   } else if (ptype == PETSC_LOGICAL) {
105:     *size = PETSC_LOGICAL_SIZE;
106:   } else {
107:     SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
108:   }
109:   return(0);
110: }

112: #undef __FUNCT__  
114: /*@
115:      PetscDataTypeGetName - Gets the string representation of a PETSc datatype

117:    Not collective

119:     Input Parameter:
120: .     ptype - the PETSc datatype name (for example PETSC_DOUBLE)

122:     Output Parameter:
123: .     name - the name as a string (for example "double")

125:     Level: advanced
126:    
127: .seealso: PetscDataType, PetscDataTypeGetSize(), PetscDataTypeToMPIDataType()
128: @*/
129: int PetscDataTypeGetName(PetscDataType ptype,char *name[])
130: {
132:   if (ptype == PETSC_INT) {
133:     *name = "int";
134:   } else if (ptype == PETSC_DOUBLE) {
135:     *name = "double";
136: #if defined(PETSC_USE_COMPLEX)
137:   } else if (ptype == PETSC_COMPLEX) {
138:     *name = "complex";
139: #endif
140:   } else if (ptype == PETSC_LONG) {
141:     *name = "long";
142:   } else if (ptype == PETSC_SHORT) {
143:     *name = "short";
144:   } else if (ptype == PETSC_FLOAT) {
145:     *name = "float";
146:   } else if (ptype == PETSC_CHAR) {
147:     *name = "char";
148:   } else if (ptype == PETSC_LOGICAL) {
149:     *name = "logical";
150:   } else {
151:     SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
152:   }
153:   return(0);
154: }