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: /*@
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 PETSC_DLLEXPORT 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 {
50: SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
51: }
52: return(0);
53: }
55: typedef enum {PETSC_INT_SIZE = sizeof(PetscInt),PETSC_DOUBLE_SIZE = sizeof(double),
56: PETSC_COMPLEX_SIZE = sizeof(PetscScalar),PETSC_LONG_SIZE=sizeof(long),
57: PETSC_SHORT_SIZE = sizeof(short),PETSC_FLOAT_SIZE = sizeof(float),
58: PETSC_CHAR_SIZE = sizeof(char),PETSC_LOGICAL_SIZE = sizeof(char),
59: PETSC_ENUM_SIZE = sizeof(PetscTruth), PETSC_TRUTH_SIZE = sizeof(PetscTruth)} PetscDataTypeSize;
60: #if defined(PETSC_USE_COMPLEX)
61: #define PETSC_SCALAR_SIZE PETSC_COMPLEX_SIZE
62: #else
63: #define PETSC_SCALAR_SIZE PETSC_DOUBLE_SIZE
64: #endif
65: #if defined(PETSC_USE_SINGLE)
66: #define PETSC_REAL_SIZE PETSC_FLOAT_SIZE
67: #else
68: #define PETSC_REAL_SIZE PETSC_DOUBLE_SIZE
69: #endif
70: #define PETSC_FORTRANADDR_SIZE PETSC_LONG_SIZE
75: /*@
76: PetscDataTypeGetSize - Gets the size (in bytes) of a PETSc datatype
78: Not collective
80: Input Parameter:
81: . ptype - the PETSc datatype name (for example PETSC_DOUBLE)
83: Output Parameter:
84: . size - the size in bytes (for example the size of PETSC_DOUBLE is 8)
86: Level: advanced
87:
88: .seealso: PetscDataType, PetscDataTypeToMPIDataType()
89: @*/
90: PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType ptype,PetscInt *size)
91: {
93: if (ptype == PETSC_INT) {
94: *size = PETSC_INT_SIZE;
95: } else if (ptype == PETSC_DOUBLE) {
96: *size = PETSC_DOUBLE_SIZE;
97: #if defined(PETSC_USE_COMPLEX)
98: } else if (ptype == PETSC_COMPLEX) {
99: *size = PETSC_COMPLEX_SIZE;
100: #endif
101: } else if (ptype == PETSC_LONG) {
102: *size = PETSC_LONG_SIZE;
103: } else if (ptype == PETSC_SHORT) {
104: *size = PETSC_SHORT_SIZE;
105: } else if (ptype == PETSC_FLOAT) {
106: *size = PETSC_FLOAT_SIZE;
107: } else if (ptype == PETSC_CHAR) {
108: *size = PETSC_CHAR_SIZE;
109: } else if (ptype == PETSC_ENUM) {
110: *size = PETSC_ENUM_SIZE;
111: } else if (ptype == PETSC_LOGICAL) {
112: *size = PETSC_LOGICAL_SIZE;
113: } else if (ptype == PETSC_TRUTH) {
114: *size = PETSC_TRUTH_SIZE;
115: } else {
116: SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
117: }
118: return(0);
119: }