xref: /petsc/include/petscsys.h (revision e3caeda681d93b7b1d053090fe6dee7657faa56d)
1 /*
2     Provides access to system related and general utility routines.
3 */
4 #if !defined(__PETSCSYS_H)
5 #define __PETSCSYS_H
6 #include "petsc.h"
7 PETSC_EXTERN_CXX_BEGIN
8 
9 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArchType(char[],size_t);
10 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetHostName(char[],size_t);
11 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetUserName(char[],size_t);
12 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetProgramName(char[],size_t);
13 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetProgramName(const char[]);
14 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetDate(char[],size_t);
15 
16 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortInt(PetscInt,PetscInt[]);
17 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]);
18 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]);
19 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]);
20 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]);
21 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]);
22 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortReal(PetscInt,PetscReal[]);
23 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]);
24 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]);
25 
26 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDisplay(void);
27 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetDisplay(char[],size_t);
28 
29 /*E
30     PetscRandomType - String with the name of a PETSc randomizer
31        with an optional dynamic library name, for example
32        http://www.mcs.anl.gov/petsc/lib.a:myrandcreate()
33 
34    Level: beginner
35 
36    Notes: to use the SPRNG you must have config/configure.py PETSc
37    with the option --download-sprng
38 
39 .seealso: PetscRandomSetType(), PetscRandom
40 E*/
41 #define PetscRandomType char*
42 #define PETSCRAND       "rand"
43 #define PETSCRAND48     "rand48"
44 #define PETSCSPRNG      "sprng"
45 
46 /* Logging support */
47 extern PETSC_DLLEXPORT PetscCookie PETSC_RANDOM_COOKIE;
48 
49 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomInitializePackage(const char[]);
50 
51 /*S
52      PetscRandom - Abstract PETSc object that manages generating random numbers
53 
54    Level: intermediate
55 
56   Concepts: random numbers
57 
58 .seealso:  PetscRandomCreate(), PetscRandomGetValue(), PetscRandomType
59 S*/
60 typedef struct _p_PetscRandom*   PetscRandom;
61 
62 /* Dynamic creation and loading functions */
63 extern PetscFList PetscRandomList;
64 extern PetscTruth PetscRandomRegisterAllCalled;
65 
66 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomRegisterAll(const char []);
67 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscRandom));
68 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomRegisterDestroy(void);
69 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetType(PetscRandom, const PetscRandomType);
70 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetFromOptions(PetscRandom);
71 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetType(PetscRandom, const PetscRandomType*);
72 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomViewFromOptions(PetscRandom,char*);
73 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomView(PetscRandom,PetscViewer);
74 
75 /*MC
76   PetscRandomRegisterDynamic - Adds a new PetscRandom component implementation
77 
78   Synopsis:
79   PetscErrorCode PetscRandomRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(PetscRandom))
80 
81   Not Collective
82 
83   Input Parameters:
84 + name        - The name of a new user-defined creation routine
85 . path        - The path (either absolute or relative) of the library containing this routine
86 . func_name   - The name of routine to create method context
87 - create_func - The creation routine itself
88 
89   Notes:
90   PetscRandomRegisterDynamic() may be called multiple times to add several user-defined randome number generators
91 
92   If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
93 
94   Sample usage:
95 .vb
96     PetscRandomRegisterDynamic("my_rand","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscRandomtorCreate", MyPetscRandomtorCreate);
97 .ve
98 
99   Then, your random type can be chosen with the procedural interface via
100 .vb
101     PetscRandomCreate(MPI_Comm, PetscRandom *);
102     PetscRandomSetType(PetscRandom,"my_random_name");
103 .ve
104    or at runtime via the option
105 .vb
106     -random_type my_random_name
107 .ve
108 
109   Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
110 
111          For an example of the code needed to interface your own random number generator see
112          src/sys/random/impls/rand/rand.c
113 
114   Level: advanced
115 
116 .keywords: PetscRandom, register
117 .seealso: PetscRandomRegisterAll(), PetscRandomRegisterDestroy(), PetscRandomRegister()
118 M*/
119 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
120 #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,0)
121 #else
122 #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,d)
123 #endif
124 
125 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomCreate(MPI_Comm,PetscRandom*);
126 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetValue(PetscRandom,PetscScalar*);
127 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetValueReal(PetscRandom,PetscReal*);
128 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetValueImaginary(PetscRandom,PetscScalar*);
129 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*);
130 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar);
131 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetSeed(PetscRandom,unsigned long);
132 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetSeed(PetscRandom,unsigned long *);
133 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSeed(PetscRandom);
134 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomDestroy(PetscRandom);
135 
136 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetFullPath(const char[],char[],size_t);
137 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetRelativePath(const char[],char[],size_t);
138 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetWorkingDirectory(char[],size_t);
139 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetRealPath(const char[],char[]);
140 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetHomeDirectory(char[],size_t);
141 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTestFile(const char[],char,PetscTruth*);
142 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTestDirectory(const char[],char,PetscTruth*);
143 
144 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryRead(int,void*,PetscInt,PetscDataType);
145 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscDataType);
146 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySynchronizedWrite(MPI_Comm,int,void*,PetscInt,PetscDataType,PetscTruth);
147 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryWrite(int,void*,PetscInt,PetscDataType,PetscTruth);
148 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryOpen(const char[],PetscFileMode,int *);
149 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryClose(int);
150 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSharedTmp(MPI_Comm,PetscTruth *);
151 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSharedWorkingDirectory(MPI_Comm,PetscTruth *);
152 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTmp(MPI_Comm,char[],size_t);
153 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscTruth*);
154 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLs(MPI_Comm,const char[],char[],size_t,PetscTruth*);
155 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenSocket(char*,int,int*);
156 
157 /*
158    In binary files variables are stored using the following lengths,
159   regardless of how they are stored in memory on any one particular
160   machine. Use these rather then sizeof() in computing sizes for
161   PetscBinarySeek().
162 */
163 #define PETSC_BINARY_INT_SIZE    (32/8)
164 #define PETSC_BINARY_FLOAT_SIZE  (32/8)
165 #define PETSC_BINARY_CHAR_SIZE    (8/8)
166 #define PETSC_BINARY_SHORT_SIZE  (16/8)
167 #define PETSC_BINARY_DOUBLE_SIZE (64/8)
168 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
169 
170 /*E
171   PetscBinarySeekType - argument to PetscBinarySeek()
172 
173   Level: advanced
174 
175 .seealso: PetscBinarySeek(), PetscBinarySynchronizedSeek()
176 E*/
177 typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType;
178 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*);
179 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*);
180 
181 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDebugTerminal(const char[]);
182 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDebugger(const char[],PetscTruth);
183 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDefaultDebugger(void);
184 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDebuggerFromString(char*);
185 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscAttachDebugger(void);
186 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStopForDebugger(void);
187 
188 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*);
189 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**);
190 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**);
191 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**);
192 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**);
193 
194 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSSEIsEnabled(MPI_Comm,PetscTruth *,PetscTruth *);
195 
196 /*E
197   InsertMode - Whether entries are inserted or added into vectors or matrices
198 
199   Level: beginner
200 
201 .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
202           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(),
203           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
204 E*/
205 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode;
206 
207 /*MC
208     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
209 
210     Level: beginner
211 
212 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
213           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES,
214           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
215 
216 M*/
217 
218 /*MC
219     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
220                 value into that location
221 
222     Level: beginner
223 
224 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
225           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES,
226           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
227 
228 M*/
229 
230 /*MC
231     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
232 
233     Level: beginner
234 
235 .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES
236 
237 M*/
238 
239 /*E
240   ScatterMode - Determines the direction of a scatter
241 
242   Level: beginner
243 
244 .seealso: VecScatter, VecScatterBegin(), VecScatterEnd()
245 E*/
246 typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode;
247 
248 /*MC
249     SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call
250 
251     Level: beginner
252 
253 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL,
254           SCATTER_REVERSE_LOCAL
255 
256 M*/
257 
258 /*MC
259     SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in
260          in the VecScatterCreate()
261 
262     Level: beginner
263 
264 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
265           SCATTER_REVERSE_LOCAL
266 
267 M*/
268 
269 /*MC
270     SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication
271        is done. Any variables that have be moved between processes are ignored
272 
273     Level: developer
274 
275 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD,
276           SCATTER_REVERSE_LOCAL
277 
278 M*/
279 
280 /*MC
281     SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in
282          in the VecScatterCreate()  except NO parallel communication
283        is done. Any variables that have be moved between processes are ignored
284 
285     Level: developer
286 
287 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
288           SCATTER_REVERSE
289 
290 M*/
291 
292 /*S
293    PetscSubcomm - Context of MPI subcommunicators, used by PCREDUNDANT
294 
295    Level: advanced
296 
297    Concepts: communicator, create
298 S*/
299 typedef struct _n_PetscSubcomm* PetscSubcomm;
300 
301 struct _n_PetscSubcomm {
302   MPI_Comm   parent;      /* parent communicator */
303   MPI_Comm   dupparent;   /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
304   MPI_Comm   comm;        /* this communicator */
305   PetscInt   n;           /* num of subcommunicators under the parent communicator */
306   PetscInt   color;       /* color of processors belong to this communicator */
307 };
308 
309 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommCreate(MPI_Comm,PetscInt,PetscSubcomm*);
310 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommDestroy(PetscSubcomm);
311 
312 PETSC_EXTERN_CXX_END
313 #endif /* __PETSCSYS_H */
314