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 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]); 25 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]); 26 27 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDisplay(void); 28 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetDisplay(char[],size_t); 29 30 /*E 31 PetscRandomType - String with the name of a PETSc randomizer 32 with an optional dynamic library name, for example 33 http://www.mcs.anl.gov/petsc/lib.a:myrandcreate() 34 35 Level: beginner 36 37 Notes: to use the SPRNG you must have config/configure.py PETSc 38 with the option --download-sprng 39 40 .seealso: PetscRandomSetType(), PetscRandom 41 E*/ 42 #define PetscRandomType char* 43 #define PETSCRAND "rand" 44 #define PETSCRAND48 "rand48" 45 #define PETSCSPRNG "sprng" 46 47 /* Logging support */ 48 extern PETSC_DLLEXPORT PetscCookie PETSC_RANDOM_COOKIE; 49 50 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomInitializePackage(const char[]); 51 52 /*S 53 PetscRandom - Abstract PETSc object that manages generating random numbers 54 55 Level: intermediate 56 57 Concepts: random numbers 58 59 .seealso: PetscRandomCreate(), PetscRandomGetValue(), PetscRandomType 60 S*/ 61 typedef struct _p_PetscRandom* PetscRandom; 62 63 /* Dynamic creation and loading functions */ 64 extern PetscFList PetscRandomList; 65 extern PetscTruth PetscRandomRegisterAllCalled; 66 67 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomRegisterAll(const char []); 68 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscRandom)); 69 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomRegisterDestroy(void); 70 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetType(PetscRandom, const PetscRandomType); 71 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetFromOptions(PetscRandom); 72 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetType(PetscRandom, const PetscRandomType*); 73 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomViewFromOptions(PetscRandom,char*); 74 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomView(PetscRandom,PetscViewer); 75 76 /*MC 77 PetscRandomRegisterDynamic - Adds a new PetscRandom component implementation 78 79 Synopsis: 80 PetscErrorCode PetscRandomRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(PetscRandom)) 81 82 Not Collective 83 84 Input Parameters: 85 + name - The name of a new user-defined creation routine 86 . path - The path (either absolute or relative) of the library containing this routine 87 . func_name - The name of routine to create method context 88 - create_func - The creation routine itself 89 90 Notes: 91 PetscRandomRegisterDynamic() may be called multiple times to add several user-defined randome number generators 92 93 If dynamic libraries are used, then the fourth input argument (routine_create) is ignored. 94 95 Sample usage: 96 .vb 97 PetscRandomRegisterDynamic("my_rand","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscRandomtorCreate", MyPetscRandomtorCreate); 98 .ve 99 100 Then, your random type can be chosen with the procedural interface via 101 .vb 102 PetscRandomCreate(MPI_Comm, PetscRandom *); 103 PetscRandomSetType(PetscRandom,"my_random_name"); 104 .ve 105 or at runtime via the option 106 .vb 107 -random_type my_random_name 108 .ve 109 110 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 111 112 For an example of the code needed to interface your own random number generator see 113 src/sys/random/impls/rand/rand.c 114 115 Level: advanced 116 117 .keywords: PetscRandom, register 118 .seealso: PetscRandomRegisterAll(), PetscRandomRegisterDestroy(), PetscRandomRegister() 119 M*/ 120 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 121 #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,0) 122 #else 123 #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,d) 124 #endif 125 126 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomCreate(MPI_Comm,PetscRandom*); 127 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetValue(PetscRandom,PetscScalar*); 128 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetValueReal(PetscRandom,PetscReal*); 129 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetValueImaginary(PetscRandom,PetscScalar*); 130 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*); 131 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar); 132 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSetSeed(PetscRandom,unsigned long); 133 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomGetSeed(PetscRandom,unsigned long *); 134 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomSeed(PetscRandom); 135 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRandomDestroy(PetscRandom); 136 137 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetFullPath(const char[],char[],size_t); 138 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetRelativePath(const char[],char[],size_t); 139 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetWorkingDirectory(char[],size_t); 140 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetRealPath(const char[],char[]); 141 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetHomeDirectory(char[],size_t); 142 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTestFile(const char[],char,PetscTruth*); 143 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTestDirectory(const char[],char,PetscTruth*); 144 145 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryRead(int,void*,PetscInt,PetscDataType); 146 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscDataType); 147 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySynchronizedWrite(MPI_Comm,int,void*,PetscInt,PetscDataType,PetscTruth); 148 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryWrite(int,void*,PetscInt,PetscDataType,PetscTruth); 149 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryOpen(const char[],PetscFileMode,int *); 150 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinaryClose(int); 151 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSharedTmp(MPI_Comm,PetscTruth *); 152 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSharedWorkingDirectory(MPI_Comm,PetscTruth *); 153 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTmp(MPI_Comm,char[],size_t); 154 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscTruth*); 155 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLs(MPI_Comm,const char[],char[],size_t,PetscTruth*); 156 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenSocket(char*,int,int*); 157 158 /* 159 In binary files variables are stored using the following lengths, 160 regardless of how they are stored in memory on any one particular 161 machine. Use these rather then sizeof() in computing sizes for 162 PetscBinarySeek(). 163 */ 164 #define PETSC_BINARY_INT_SIZE (32/8) 165 #define PETSC_BINARY_FLOAT_SIZE (32/8) 166 #define PETSC_BINARY_CHAR_SIZE (8/8) 167 #define PETSC_BINARY_SHORT_SIZE (16/8) 168 #define PETSC_BINARY_DOUBLE_SIZE (64/8) 169 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar) 170 171 /*E 172 PetscBinarySeekType - argument to PetscBinarySeek() 173 174 Level: advanced 175 176 .seealso: PetscBinarySeek(), PetscBinarySynchronizedSeek() 177 E*/ 178 typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType; 179 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*); 180 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*); 181 182 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDebugTerminal(const char[]); 183 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDebugger(const char[],PetscTruth); 184 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDefaultDebugger(void); 185 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetDebuggerFromString(char*); 186 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscAttachDebugger(void); 187 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStopForDebugger(void); 188 189 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*); 190 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**); 191 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**); 192 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**); 193 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**); 194 195 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSSEIsEnabled(MPI_Comm,PetscTruth *,PetscTruth *); 196 197 /*E 198 InsertMode - Whether entries are inserted or added into vectors or matrices 199 200 Level: beginner 201 202 .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 203 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), 204 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 205 E*/ 206 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode; 207 208 /*MC 209 INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value 210 211 Level: beginner 212 213 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 214 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES, 215 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 216 217 M*/ 218 219 /*MC 220 ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the 221 value into that location 222 223 Level: beginner 224 225 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 226 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES, 227 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 228 229 M*/ 230 231 /*MC 232 MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location 233 234 Level: beginner 235 236 .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES 237 238 M*/ 239 240 /*E 241 ScatterMode - Determines the direction of a scatter 242 243 Level: beginner 244 245 .seealso: VecScatter, VecScatterBegin(), VecScatterEnd() 246 E*/ 247 typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode; 248 249 /*MC 250 SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call 251 252 Level: beginner 253 254 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL, 255 SCATTER_REVERSE_LOCAL 256 257 M*/ 258 259 /*MC 260 SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in 261 in the VecScatterCreate() 262 263 Level: beginner 264 265 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 266 SCATTER_REVERSE_LOCAL 267 268 M*/ 269 270 /*MC 271 SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication 272 is done. Any variables that have be moved between processes are ignored 273 274 Level: developer 275 276 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD, 277 SCATTER_REVERSE_LOCAL 278 279 M*/ 280 281 /*MC 282 SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in 283 in the VecScatterCreate() except NO parallel communication 284 is done. Any variables that have be moved between processes are ignored 285 286 Level: developer 287 288 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 289 SCATTER_REVERSE 290 291 M*/ 292 293 /*S 294 PetscSubcomm - Context of MPI subcommunicators, used by PCREDUNDANT 295 296 Level: advanced 297 298 Concepts: communicator, create 299 S*/ 300 typedef struct _n_PetscSubcomm* PetscSubcomm; 301 302 struct _n_PetscSubcomm { 303 MPI_Comm parent; /* parent communicator */ 304 MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 305 MPI_Comm comm; /* this communicator */ 306 PetscInt n; /* num of subcommunicators under the parent communicator */ 307 PetscInt color; /* color of processors belong to this communicator */ 308 }; 309 310 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommCreate(MPI_Comm,PetscInt,PetscSubcomm*); 311 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommDestroy(PetscSubcomm); 312 313 PETSC_EXTERN_CXX_END 314 #endif /* __PETSCSYS_H */ 315