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