Actual source code: ptype.c
1: #define PETSC_DLL
2: /*
3: Provides utility routines for manipulating any type of PETSc object.
4: */
5: #include petsc.h
9: /*@C
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
23: @*/
24: PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType ptype,MPI_Datatype* mtype)
25: {
27: if (ptype == PETSC_INT) {
28: *mtype = MPIU_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_ENUM) {
40: *mtype = MPI_INT;
41: } else if (ptype == PETSC_TRUTH) {
42: *mtype = MPI_INT;
43: } else if (ptype == PETSC_FLOAT) {
44: *mtype = MPI_FLOAT;
45: } else if (ptype == PETSC_CHAR) {
46: *mtype = MPI_CHAR;
47: } else if (ptype == PETSC_LOGICAL) {
48: *mtype = MPI_BYTE;
49: } else if (ptype == PETSC_LONG_DOUBLE) {
50: *mtype = MPI_LONG_DOUBLE;
51: } else {
52: SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
53: }
54: return(0);
55: }
57: typedef enum {PETSC_INT_SIZE = sizeof(PetscInt),PETSC_DOUBLE_SIZE = sizeof(double),
58: PETSC_COMPLEX_SIZE = sizeof(PetscScalar),PETSC_LONG_SIZE=sizeof(long),
59: PETSC_SHORT_SIZE = sizeof(short),PETSC_FLOAT_SIZE = sizeof(float),
60: PETSC_CHAR_SIZE = sizeof(char),PETSC_LOGICAL_SIZE = sizeof(char),
61: PETSC_ENUM_SIZE = sizeof(PetscTruth), PETSC_TRUTH_SIZE = sizeof(PetscTruth),
62: PETSC_LONG_DOUBLE_SIZE = sizeof(long double)} PetscDataTypeSize;
63: #if defined(PETSC_USE_COMPLEX)
64: #define PETSC_SCALAR_SIZE PETSC_COMPLEX_SIZE
65: #else
66: #define PETSC_SCALAR_SIZE PETSC_DOUBLE_SIZE
67: #endif
68: #if defined(PETSC_USE_SINGLE)
69: #define PETSC_REAL_SIZE PETSC_FLOAT_SIZE
70: #elif defined(PETSC_USE_LONG_DOUBLE)
71: #define PETSC_REAL_SIZE PETSC_LONG_DOUBLE_SIZE
72: #elif defined(PETSC_USE_INT)
73: #define PETSC_REAL_SIZE PETSC_INT_SIZE
74: #else
75: #define PETSC_REAL_SIZE PETSC_DOUBLE_SIZE
76: #endif
77: #define PETSC_FORTRANADDR_SIZE PETSC_LONG_SIZE
82: /*@
83: PetscDataTypeGetSize - Gets the size (in bytes) of a PETSc datatype
85: Not collective
87: Input Parameter:
88: . ptype - the PETSc datatype name (for example PETSC_DOUBLE)
90: Output Parameter:
91: . size - the size in bytes (for example the size of PETSC_DOUBLE is 8)
93: Level: advanced
94:
95: .seealso: PetscDataType, PetscDataTypeToMPIDataType()
96: @*/
97: PetscErrorCode PetscDataTypeGetSize(PetscDataType ptype,PetscInt *size)
98: {
100: if ((PetscInt) ptype < 0) {
101: *size = -(PetscInt) ptype;
102: return(0);
103: }
105: if (ptype == PETSC_INT) {
106: *size = PETSC_INT_SIZE;
107: } else if (ptype == PETSC_DOUBLE) {
108: *size = PETSC_DOUBLE_SIZE;
109: #if defined(PETSC_USE_COMPLEX)
110: } else if (ptype == PETSC_COMPLEX) {
111: *size = PETSC_COMPLEX_SIZE;
112: #endif
113: } else if (ptype == PETSC_LONG) {
114: *size = PETSC_LONG_SIZE;
115: } else if (ptype == PETSC_SHORT) {
116: *size = PETSC_SHORT_SIZE;
117: } else if (ptype == PETSC_FLOAT) {
118: *size = PETSC_FLOAT_SIZE;
119: } else if (ptype == PETSC_CHAR) {
120: *size = PETSC_CHAR_SIZE;
121: } else if (ptype == PETSC_ENUM) {
122: *size = PETSC_ENUM_SIZE;
123: } else if (ptype == PETSC_LOGICAL) {
124: *size = PETSC_LOGICAL_SIZE;
125: } else if (ptype == PETSC_TRUTH) {
126: *size = PETSC_TRUTH_SIZE;
127: } else if (ptype == PETSC_LONG_DOUBLE) {
128: *size = PETSC_LONG_DOUBLE_SIZE;
129: } else {
130: SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
131: }
132: return(0);
133: }