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 PetscSetDebugger(const char[],PetscTruth); 180 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDefaultDebugger(void); 181 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDebuggerFromString(char*); 182 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscAttachDebugger(void); 183 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStopForDebugger(void); 184 185 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*); 186 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**); 187 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**); 188 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**); 189 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**); 190 191 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSSEIsEnabled(MPI_Comm,PetscTruth *,PetscTruth *); 192 193 /*E 194 InsertMode - Whether entries are inserted or added into vectors or matrices 195 196 Level: beginner 197 198 .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 199 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), 200 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 201 E*/ 202 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode; 203 204 /*MC 205 INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value 206 207 Level: beginner 208 209 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 210 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES, 211 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 212 213 M*/ 214 215 /*MC 216 ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the 217 value into that location 218 219 Level: beginner 220 221 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 222 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES, 223 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 224 225 M*/ 226 227 /*MC 228 MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location 229 230 Level: beginner 231 232 .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES 233 234 M*/ 235 236 /*E 237 ScatterMode - Determines the direction of a scatter 238 239 Level: beginner 240 241 .seealso: VecScatter, VecScatterBegin(), VecScatterEnd() 242 E*/ 243 typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode; 244 245 /*MC 246 SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call 247 248 Level: beginner 249 250 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL, 251 SCATTER_REVERSE_LOCAL 252 253 M*/ 254 255 /*MC 256 SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in 257 in the VecScatterCreate() 258 259 Level: beginner 260 261 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 262 SCATTER_REVERSE_LOCAL 263 264 M*/ 265 266 /*MC 267 SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication 268 is done. Any variables that have be moved between processes are ignored 269 270 Level: developer 271 272 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD, 273 SCATTER_REVERSE_LOCAL 274 275 M*/ 276 277 /*MC 278 SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in 279 in the VecScatterCreate() except NO parallel communication 280 is done. Any variables that have be moved between processes are ignored 281 282 Level: developer 283 284 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 285 SCATTER_REVERSE 286 287 M*/ 288 289 /*S 290 PetscSubcomm - Context of MPI subcommunicators, used by PCREDUNDANT 291 292 Level: advanced 293 294 Concepts: communicator, create 295 S*/ 296 typedef struct _n_PetscSubcomm* PetscSubcomm; 297 298 struct _n_PetscSubcomm { 299 MPI_Comm parent; /* parent communicator */ 300 MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 301 MPI_Comm comm; /* this communicator */ 302 PetscInt n; /* num of subcommunicators under the parent communicator */ 303 PetscInt color; /* color of processors belong to this communicator */ 304 }; 305 306 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommCreate(MPI_Comm,PetscInt,PetscSubcomm*); 307 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommDestroy(PetscSubcomm); 308 309 PETSC_EXTERN_CXX_END 310 #endif /* __PETSCSYS_H */ 311