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 PetscGetArchType(char[],size_t); 10 EXTERN PetscErrorCode PetscGetHostName(char[],size_t); 11 EXTERN PetscErrorCode PetscGetUserName(char[],size_t); 12 EXTERN PetscErrorCode PetscGetProgramName(char[],size_t); 13 EXTERN PetscErrorCode PetscSetProgramName(const char[]); 14 EXTERN PetscErrorCode PetscGetDate(char[],size_t); 15 EXTERN PetscErrorCode PetscSetInitialDate(void); 16 EXTERN PetscErrorCode PetscGetInitialDate(char[],size_t); 17 18 EXTERN PetscErrorCode PetscSortInt(PetscInt,PetscInt[]); 19 EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]); 20 EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]); 21 EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]); 22 EXTERN PetscErrorCode PetscSortReal(PetscInt,PetscReal[]); 23 EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]); 24 25 EXTERN PetscErrorCode PetscSetDisplay(void); 26 EXTERN PetscErrorCode PetscGetDisplay(char[],size_t); 27 28 extern PetscCookie 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 PetscErrorCode PetscRandomCreate(MPI_Comm,PetscRandomType,PetscRandom*); 45 EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom,PetscScalar*); 46 EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar); 47 EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom); 48 49 EXTERN PetscErrorCode PetscGetFullPath(const char[],char[],size_t); 50 EXTERN PetscErrorCode PetscGetRelativePath(const char[],char[],size_t); 51 EXTERN PetscErrorCode PetscGetWorkingDirectory(char[],size_t); 52 EXTERN PetscErrorCode PetscGetRealPath(char[],char[]); 53 EXTERN PetscErrorCode PetscGetHomeDirectory(char[],size_t); 54 EXTERN PetscErrorCode PetscTestFile(const char[],char,PetscTruth*); 55 EXTERN PetscErrorCode PetscTestDirectory(const char[],char,PetscTruth*); 56 EXTERN PetscErrorCode PetscBinaryRead(int,void*,int,PetscDataType); 57 EXTERN PetscErrorCode PetscSynchronizedBinaryRead(MPI_Comm,int,void*,int,PetscDataType); 58 EXTERN PetscErrorCode PetscBinaryWrite(int,void*,int,PetscDataType,int); 59 EXTERN PetscErrorCode PetscBinaryOpen(const char[],int,int *); 60 EXTERN PetscErrorCode PetscBinaryClose(int); 61 EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm,PetscTruth *); 62 EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm,PetscTruth *); 63 EXTERN PetscErrorCode PetscGetTmp(MPI_Comm,char *,int); 64 EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm,const char *,char *,int,PetscTruth*); 65 EXTERN PetscErrorCode PetscLs(MPI_Comm,const char[],char*,int,PetscTruth*); 66 EXTERN PetscErrorCode 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 PetscErrorCode PetscBinarySeek(int,int,PetscBinarySeekType,int*); 90 EXTERN PetscErrorCode PetscSynchronizedBinarySeek(MPI_Comm,int,int,PetscBinarySeekType,int*); 91 92 EXTERN PetscErrorCode PetscSetDebugger(const char[],PetscTruth); 93 EXTERN PetscErrorCode PetscSetDefaultDebugger(void); 94 EXTERN PetscErrorCode PetscSetDebuggerFromString(char*); 95 EXTERN PetscErrorCode PetscAttachDebugger(void); 96 EXTERN PetscErrorCode PetscStopForDebugger(void); 97 98 EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm,int*,int*,int*); 99 EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm,int,int,int*,int**,int**); 100 EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm,int,int,int*,int*,int***,MPI_Request**); 101 EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm,int,int,int*,int*,PetscScalar***,MPI_Request**); 102 103 EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm,PetscTruth *,PetscTruth *); 104 105 /* ParameterDict objects encapsulate arguments to generic functions, like mechanisms over interfaces */ 106 EXTERN PetscErrorCode ParameterDictCreate(MPI_Comm, ParameterDict *); 107 EXTERN PetscErrorCode ParameterDictDestroy(ParameterDict); 108 EXTERN PetscErrorCode ParameterDictRemove(ParameterDict, const char []); 109 EXTERN PetscErrorCode ParameterDictSetInteger(ParameterDict, const char [], int); 110 EXTERN PetscErrorCode ParameterDictSetDouble(ParameterDict, const char [], double); 111 EXTERN PetscErrorCode ParameterDictSetObject(ParameterDict, const char [], void *); 112 EXTERN PetscErrorCode ParameterDictGetInteger(ParameterDict, const char [], int *); 113 EXTERN PetscErrorCode ParameterDictGetDouble(ParameterDict, const char [], double *); 114 EXTERN PetscErrorCode 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 PetscErrorCode PetscGhostExchange(MPI_Comm, int, int *, int *, PetscDataType, int *, InsertMode, ScatterMode, void *, void *); 214 215 /* 216 Create and initialize a linked list 217 Input Parameters: 218 idx_start - starting index of the list 219 lnk_max - max value of lnk indicating the end of the list 220 nlnk - max length of the list 221 Output Parameters: 222 lnk - list initialized 223 bt - PetscBT (bitarray) with all bits set to false 224 */ 225 #define PetscLLCreate(idx_start,lnk_max,nlnk,lnk,bt) 0;\ 226 {\ 227 PetscMalloc(nlnk*sizeof(int),&lnk);\ 228 PetscBTCreate(nlnk,bt);\ 229 ierr = PetscBTMemzero(nlnk,bt);\ 230 lnk[idx_start] = lnk_max;\ 231 } 232 233 /* 234 Add a index set into a sorted linked list 235 Input Parameters: 236 nidx - number of input indices 237 indices - interger array 238 idx_start - starting index of the list 239 lnk - linked list(an integer array) that is created 240 bt - PetscBT (bitarray), bt[idx]=true marks idx is in lnk 241 output Parameters: 242 nlnk - number of newly added indices 243 lnk - the sorted(increasing order) linked list containing new and non-redundate entries from indices 244 bt - updated PetscBT (bitarray) 245 */ 246 #define PetscLLAdd(nidx,indices,idx_start,nlnk,lnk,bt) 0;\ 247 {\ 248 int _k,_entry,_location,_lnkdata;\ 249 nlnk = 0;\ 250 _k=nidx;\ 251 while (_k){/* assume indices are almost in increasing order, starting from its end saves computation */\ 252 _entry = indices[--_k];\ 253 if (!PetscBTLookupSet(bt,_entry)){ /* new entry */\ 254 /* search for insertion location */\ 255 _lnkdata = idx_start;\ 256 do {\ 257 _location = _lnkdata;\ 258 _lnkdata = lnk[_location];\ 259 } while (_entry > _lnkdata);\ 260 /* insertion location is found, add entry into lnk if it is new */\ 261 if (_entry < _lnkdata){/* new entry */\ 262 lnk[_location] = _entry;\ 263 lnk[_entry] = _lnkdata;\ 264 nlnk++;\ 265 }\ 266 }\ 267 }\ 268 } 269 /* 270 Copy data on the list into an array, then initialize the list 271 Input Parameters: 272 idx_start - starting index of the list 273 lnk_max - max value of lnk indicating the end of the list 274 nlnk - number of data on the list to be copied 275 lnk - linked list 276 bt - PetscBT (bitarray), bt[idx]=true marks idx is in lnk 277 output Parameters: 278 indices - array that contains the copied data 279 lnk -llinked list that is cleaned and initialize 280 bt - PetscBT (bitarray) with all bits set to false 281 */ 282 #define PetscLLClean(idx_start,lnk_max,nlnk,lnk,indices,bt) 0;\ 283 {\ 284 int _j,_idx=idx_start;\ 285 for (_j=0; _j<nlnk; _j++){\ 286 _idx = lnk[_idx];\ 287 *(indices+_j) = _idx;\ 288 PetscBTClear(bt,_idx);\ 289 }\ 290 lnk[idx_start] = lnk_max;\ 291 } 292 /* 293 Free memories used by the list 294 */ 295 #define PetscLLDestroy(lnk,bt) 0;\ 296 {\ 297 PetscFree(lnk);\ 298 PetscBTDestroy(bt);\ 299 } 300 301 PETSC_EXTERN_CXX_END 302 #endif /* __PETSCSYS_H */ 303