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