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