xref: /petsc/include/petscsys.h (revision f747e1ae54eac4c971caa6b7e82576b5c3be8258)
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 int  PetscGetArchType(char[],int);
10 EXTERN int  PetscGetHostName(char[],int);
11 EXTERN int  PetscGetUserName(char[],int);
12 EXTERN int  PetscGetProgramName(char[],int);
13 EXTERN int  PetscSetProgramName(const char[]);
14 EXTERN int  PetscGetDate(char[],int);
15 EXTERN int  PetscSetInitialDate(void);
16 EXTERN int  PetscGetInitialDate(char[],int);
17 
18 EXTERN int  PetscSortInt(int,int[]);
19 EXTERN int  PetscSortIntWithPermutation(int,const int[],int[]);
20 EXTERN int  PetscSortStrWithPermutation(int,const char*[],int[]);
21 EXTERN int  PetscSortIntWithArray(int,int[],int[]);
22 EXTERN int  PetscSortReal(int,PetscReal[]);
23 EXTERN int  PetscSortRealWithPermutation(int,const PetscReal[],int[]);
24 
25 EXTERN int  PetscSetDisplay(void);
26 EXTERN int  PetscGetDisplay(char[],int);
27 
28 extern int PETSC_RANDOM_COOKIE;
29 
30 typedef enum { RANDOM_DEFAULT,RANDOM_DEFAULT_REAL,
31                RANDOM_DEFAULT_IMAGINARY } PetscRandomType;
32 
33 /*S
34      PetscRandom - Abstract PETSc object that manages generating random numbers
35 
36    Level: intermediate
37 
38   Concepts: random numbers
39 
40 .seealso:  PetscRandomCreate(), PetscRandomGetValue()
41 S*/
42 typedef struct _p_PetscRandom*   PetscRandom;
43 
44 EXTERN int PetscRandomCreate(MPI_Comm,PetscRandomType,PetscRandom*);
45 EXTERN int PetscRandomGetValue(PetscRandom,PetscScalar*);
46 EXTERN int PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar);
47 EXTERN int PetscRandomDestroy(PetscRandom);
48 
49 EXTERN int PetscGetFullPath(const char[],char[],int);
50 EXTERN int PetscGetRelativePath(const char[],char[],int);
51 EXTERN int PetscGetWorkingDirectory(char[],int);
52 EXTERN int PetscGetRealPath(char[],char[]);
53 EXTERN int PetscGetHomeDirectory(char[],int);
54 EXTERN int PetscTestFile(const char[],char,PetscTruth*);
55 EXTERN int PetscTestDirectory(const char[],char,PetscTruth*);
56 EXTERN int PetscBinaryRead(int,void*,int,PetscDataType);
57 EXTERN int PetscSynchronizedBinaryRead(MPI_Comm,int,void*,int,PetscDataType);
58 EXTERN int PetscBinaryWrite(int,void*,int,PetscDataType,int);
59 EXTERN int PetscBinaryOpen(const char[],int,int *);
60 EXTERN int PetscBinaryClose(int);
61 EXTERN int PetscSharedTmp(MPI_Comm,PetscTruth *);
62 EXTERN int PetscSharedWorkingDirectory(MPI_Comm,PetscTruth *);
63 EXTERN int PetscGetTmp(MPI_Comm,char *,int);
64 EXTERN int PetscFileRetrieve(MPI_Comm,const char *,char *,int,PetscTruth*);
65 EXTERN int PetscLs(MPI_Comm,const char[],char*,int,PetscTruth*);
66 EXTERN int PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibraryList*,const char[]);
67 
68 /*
69    In binary files variables are stored using the following lengths,
70   regardless of how they are stored in memory on any one particular
71   machine. Use these rather then sizeof() in computing sizes for
72   PetscBinarySeek().
73 */
74 #define PETSC_BINARY_INT_SIZE    (32/8)
75 #define PETSC_BINARY_FLOAT_SIZE  (32/8)
76 #define PETSC_BINARY_CHAR_SIZE    (8/8)
77 #define PETSC_BINARY_SHORT_SIZE  (16/8)
78 #define PETSC_BINARY_DOUBLE_SIZE (64/8)
79 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
80 
81 /*E
82   PetscBinarySeekType - argument to PetscBinarySeek()
83 
84   Level: advanced
85 
86 .seealso: PetscBinarySeek(), PetscSynchronizedBinarySeek()
87 E*/
88 typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType;
89 EXTERN int PetscBinarySeek(int,int,PetscBinarySeekType,int*);
90 EXTERN int PetscSynchronizedBinarySeek(MPI_Comm,int,int,PetscBinarySeekType,int*);
91 
92 EXTERN int PetscSetDebugger(const char[],PetscTruth);
93 EXTERN int PetscSetDefaultDebugger(void);
94 EXTERN int PetscSetDebuggerFromString(char*);
95 EXTERN int PetscAttachDebugger(void);
96 EXTERN int PetscStopForDebugger(void);
97 
98 EXTERN int PetscGatherNumberOfMessages(MPI_Comm,int*,int*,int*);
99 EXTERN int PetscGatherMessageLengths(MPI_Comm,int,int,int*,int**,int**);
100 EXTERN int PetscPostIrecvInt(MPI_Comm,int,int,int*,int*,int***,MPI_Request**);
101 EXTERN int PetscPostIrecvScalar(MPI_Comm,int,int,int*,int*,PetscScalar***,MPI_Request**);
102 
103 EXTERN int PetscSSEIsEnabled(MPI_Comm,PetscTruth *,PetscTruth *);
104 
105 /* ParameterDict objects encapsulate arguments to generic functions, like mechanisms over interfaces */
106 EXTERN int ParameterDictCreate(MPI_Comm, ParameterDict *);
107 EXTERN int ParameterDictDestroy(ParameterDict);
108 EXTERN int ParameterDictRemove(ParameterDict, const char []);
109 EXTERN int ParameterDictSetInteger(ParameterDict, const char [], int);
110 EXTERN int ParameterDictSetDouble(ParameterDict, const char [], double);
111 EXTERN int ParameterDictSetObject(ParameterDict, const char [], void *);
112 EXTERN int ParameterDictGetInteger(ParameterDict, const char [], int *);
113 EXTERN int ParameterDictGetDouble(ParameterDict, const char [], double *);
114 EXTERN int ParameterDictGetObject(ParameterDict, const char [], void **);
115 
116 /* Parallel communication routines */
117 /*E
118   InsertMode - Whether entries are inserted or added into vectors or matrices
119 
120   Level: beginner
121 
122 .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
123           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(),
124           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
125 E*/
126 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode;
127 
128 /*M
129     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
130 
131     Level: beginner
132 
133 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
134           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES,
135           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
136 
137 M*/
138 
139 /*M
140     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
141                 value into that location
142 
143     Level: beginner
144 
145 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
146           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES,
147           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
148 
149 M*/
150 
151 /*M
152     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
153 
154     Level: beginner
155 
156 .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES
157 
158 M*/
159 
160 /*E
161   ScatterMode - Determines the direction of a scatter
162 
163   Level: beginner
164 
165 .seealso: VecScatter, VecScatterBegin(), VecScatterEnd()
166 E*/
167 typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode;
168 
169 /*M
170     SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call
171 
172     Level: beginner
173 
174 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL,
175           SCATTER_REVERSE_LOCAL
176 
177 M*/
178 
179 /*M
180     SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in
181          in the VecScatterCreate()
182 
183     Level: beginner
184 
185 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
186           SCATTER_REVERSE_LOCAL
187 
188 M*/
189 
190 /*M
191     SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication
192        is done. Any variables that have be moved between processes are ignored
193 
194     Level: developer
195 
196 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD,
197           SCATTER_REVERSE_LOCAL
198 
199 M*/
200 
201 /*M
202     SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in
203          in the VecScatterCreate()  except NO parallel communication
204        is done. Any variables that have be moved between processes are ignored
205 
206     Level: developer
207 
208 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
209           SCATTER_REVERSE
210 
211 M*/
212 
213 EXTERN int PetscGhostExchange(MPI_Comm, int, int *, int *, PetscDataType, int *, InsertMode, ScatterMode, void *, void *);
214 
215 /*
216   Initialize a linked list
217   Input Parameters:
218     lnk_init  - the initial index value indicating the entry in the list is not set yet
219     nlnk      - max length of the list
220     lnk       - linked list(an integer array) that is allocated
221   output Parameters:
222     lnk       - the linked list with all values set as lnk_int
223 */
224 #define PetscLLInitialize(lnk_init,nlnk,lnk) 0;\
225 {\
226   int _i;\
227   for (_i=0; _i<nlnk; _i++) lnk[_i] = lnk_init;\
228 }
229 
230 /*
231   Add a index set into a sorted linked list
232   Input Parameters:
233     nidx      - number of input indices
234     indices   - interger array
235     lnk_head  - the header of the list
236     lnk_init  - the initial index value indicating the entry in the list is not set yet
237     lnk       - linked list(an integer array) that is created
238   output Parameters:
239     nlnk      - number of newly added indices
240     lnk       - the sorted(increasing order) linked list containing new and non-redundate entries from indices
241 */
242 #define PetscLLAdd(nidx,indices,lnk_head,lnk_init,nlnk,lnk) 0;\
243 {\
244   int _k,_entry,_location,_lnkdata;\
245   nlnk = 0;\
246   _k=nidx;\
247   while (_k){/* assume indices are almost in increasing order, starting from its end saves computation */\
248     _entry = indices[--_k];\
249     /* search for insertion location */\
250     _lnkdata  = lnk_head;\
251     do {\
252       _location = _lnkdata;\
253       _lnkdata  = lnk[_location];\
254     } while (_entry > _lnkdata);\
255     /* insertion location is found, add entry into lnk if it is new */\
256     if (_entry <  _lnkdata){/* new entry */\
257       lnk[_location] = _entry;\
258       lnk[_entry]    = _lnkdata;\
259       nlnk++;\
260     }\
261   }\
262 }
263 /*
264   Copy data on the list into an array, then initialize the list
265   Input Parameters:
266     lnk_head  - the header of the list
267     lnk_init  - the initial index value indicating the entry in the list is not set yet
268     nlnk      - number of data on the list to be copied
269     lnk       - linked list
270   output Parameters:
271     indices   - array that contains the copied data
272 */
273 #define PetscLLClear(lnk_head,lnk_init,nlnk,lnk,indices) 0;\
274 {\
275   int _j,_idx=lnk_head,_idx0;\
276   for (_j=0; _j<nlnk; _j++){\
277     _idx0 = _idx; _idx = lnk[_idx0];\
278     *(indices+_j) = _idx;\
279     lnk[_idx0] = lnk_init;\
280   }\
281   lnk[_idx] = lnk_init;\
282 }
283 
284 PETSC_EXTERN_CXX_END
285 #endif /* __PETSCSYS_H */
286