xref: /petsc/src/sys/objects/ptype.c (revision a83599f43e878c398a63bdbdbc1ebde0ef34fa4d)
1 #define PETSC_DLL
2 /*
3      Provides utility routines for manipulating any type of PETSc object.
4 */
5 #include "petsc.h"  /*I   "petsc.h"    I*/
6 
7 #undef __FUNCT__
8 #define __FUNCT__ "PetscDataTypeToMPIDataType"
9 /*@C
10      PetscDataTypeToMPIDataType - Converts the PETSc name of a datatype to its MPI name.
11 
12    Not collective
13 
14     Input Parameter:
15 .     ptype - the PETSc datatype name (for example PETSC_DOUBLE)
16 
17     Output Parameter:
18 .     mtype - the MPI datatype (for example MPI_DOUBLE, ...)
19 
20     Level: advanced
21 
22 .seealso: PetscDataType
23 @*/
24 PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType ptype,MPI_Datatype* mtype)
25 {
26   PetscFunctionBegin;
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   PetscFunctionReturn(0);
55 }
56 
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 #else
73 #define PETSC_REAL_SIZE PETSC_DOUBLE_SIZE
74 #endif
75 #define PETSC_FORTRANADDR_SIZE PETSC_LONG_SIZE
76 
77 
78 #undef __FUNCT__
79 #define __FUNCT__ "PetscDataTypeGetSize"
80 /*@
81      PetscDataTypeGetSize - Gets the size (in bytes) of a PETSc datatype
82 
83    Not collective
84 
85     Input Parameter:
86 .     ptype - the PETSc datatype name (for example PETSC_DOUBLE)
87 
88     Output Parameter:
89 .     size - the size in bytes (for example the size of PETSC_DOUBLE is 8)
90 
91     Level: advanced
92 
93 .seealso: PetscDataType, PetscDataTypeToMPIDataType()
94 @*/
95 PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType ptype,PetscInt *size)
96 {
97   PetscFunctionBegin;
98   if (ptype == PETSC_INT) {
99     *size = PETSC_INT_SIZE;
100   } else if (ptype == PETSC_DOUBLE) {
101     *size = PETSC_DOUBLE_SIZE;
102 #if defined(PETSC_USE_COMPLEX)
103   } else if (ptype == PETSC_COMPLEX) {
104     *size = PETSC_COMPLEX_SIZE;
105 #endif
106   } else if (ptype == PETSC_LONG) {
107     *size = PETSC_LONG_SIZE;
108   } else if (ptype == PETSC_SHORT) {
109     *size = PETSC_SHORT_SIZE;
110   } else if (ptype == PETSC_FLOAT) {
111     *size = PETSC_FLOAT_SIZE;
112   } else if (ptype == PETSC_CHAR) {
113     *size = PETSC_CHAR_SIZE;
114   } else if (ptype == PETSC_ENUM) {
115     *size = PETSC_ENUM_SIZE;
116   } else if (ptype == PETSC_LOGICAL) {
117     *size = PETSC_LOGICAL_SIZE;
118   } else if (ptype == PETSC_TRUTH) {
119     *size = PETSC_TRUTH_SIZE;
120   } else if (ptype == PETSC_LONG_DOUBLE) {
121     *size = PETSC_LONG_DOUBLE_SIZE;
122   } else {
123     SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Unknown PETSc datatype");
124   }
125   PetscFunctionReturn(0);
126 }
127