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