1 #define PETSC_DLL 2 3 /* Feature test macros to make sure atoll is available (SVr4, POSIX.1-2001, 4.3BSD, C99), not in (C89 and POSIX.1-1996) */ 4 #define _XOPEN_SOURCE 600 5 #define _BSD_SOURCE 6 /* 7 These routines simplify the use of command line, file options, etc., and are used to manipulate the options database. 8 This provides the low-level interface, the high level interface is in aoptions.c 9 10 Some routines use regular malloc and free because it cannot know what malloc is requested with the 11 options database until it has already processed the input. 12 */ 13 14 #include "petscsys.h" /*I "petscsys.h" I*/ 15 #if defined(PETSC_HAVE_STDLIB_H) 16 #include <stdlib.h> 17 #endif 18 #if defined(PETSC_HAVE_MALLOC_H) 19 #include <malloc.h> 20 #endif 21 #if defined(PETSC_HAVE_SYS_PARAM_H) 22 #include "sys/param.h" 23 #endif 24 25 /* 26 This table holds all the options set by the user. For simplicity, we use a static size database 27 */ 28 #define MAXOPTIONS 512 29 #define MAXALIASES 25 30 #define MAXOPTIONSMONITORS 5 31 #define MAXPREFIXES 25 32 33 typedef struct { 34 int N,argc,Naliases; 35 char **args,*names[MAXOPTIONS],*values[MAXOPTIONS]; 36 char *aliases1[MAXALIASES],*aliases2[MAXALIASES]; 37 PetscBool used[MAXOPTIONS]; 38 PetscBool namegiven; 39 char programname[PETSC_MAX_PATH_LEN]; /* HP includes entire path in name */ 40 41 /* --------User (or default) routines (most return -1 on error) --------*/ 42 PetscErrorCode (*monitor[MAXOPTIONSMONITORS])(const char[], const char[], void*); /* returns control to user after */ 43 PetscErrorCode (*monitordestroy[MAXOPTIONSMONITORS])(void*); /* */ 44 void *monitorcontext[MAXOPTIONSMONITORS]; /* to pass arbitrary user data into monitor */ 45 PetscInt numbermonitors; /* to, for instance, detect options being set */ 46 47 /* Prefixes */ 48 PetscInt prefixind,prefixstack[MAXPREFIXES]; 49 char prefix[2048]; 50 } PetscOptionsTable; 51 52 53 static PetscOptionsTable *options = 0; 54 extern PetscOptionsObjectType PetscOptionsObject; 55 56 /* 57 Options events monitor 58 */ 59 #define PetscOptionsMonitor(name,value) \ 60 { PetscErrorCode _ierr; PetscInt _i,_im = options->numbermonitors; \ 61 for (_i=0; _i<_im; _i++) {\ 62 _ierr = (*options->monitor[_i])(name, value, options->monitorcontext[_i]);CHKERRQ(_ierr); \ 63 } \ 64 } 65 66 #undef __FUNCT__ 67 #define __FUNCT__ "PetscOptionsStringToInt" 68 /* 69 PetscOptionsStringToInt - Converts a string to an integer value. Handles special cases such as "default" and "decide" 70 */ 71 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsStringToInt(const char name[],PetscInt *a) 72 { 73 PetscErrorCode ierr; 74 size_t i,len; 75 PetscBool decide,tdefault,mouse; 76 77 PetscFunctionBegin; 78 ierr = PetscStrlen(name,&len);CHKERRQ(ierr); 79 if (!len) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"character string of length zero has no numerical value"); 80 81 ierr = PetscStrcasecmp(name,"PETSC_DEFAULT",&tdefault);CHKERRQ(ierr); 82 if (!tdefault) { 83 ierr = PetscStrcasecmp(name,"DEFAULT",&tdefault);CHKERRQ(ierr); 84 } 85 ierr = PetscStrcasecmp(name,"PETSC_DECIDE",&decide);CHKERRQ(ierr); 86 if (!decide) { 87 ierr = PetscStrcasecmp(name,"DECIDE",&decide);CHKERRQ(ierr); 88 } 89 ierr = PetscStrcasecmp(name,"mouse",&mouse);CHKERRQ(ierr); 90 91 if (tdefault) { 92 *a = PETSC_DEFAULT; 93 } else if (decide) { 94 *a = PETSC_DECIDE; 95 } else if (mouse) { 96 *a = -1; 97 } else { 98 if (name[0] != '+' && name[0] != '-' && name[0] < '0' && name[0] > '9') { 99 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no integer value (do not include . in it)",name); 100 } 101 for (i=1; i<len; i++) { 102 if (name[i] < '0' || name[i] > '9') { 103 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no integer value (do not include . in it)",name); 104 } 105 } 106 #if defined(PETSC_USE_64BIT_INDICES) 107 *a = atoll(name); 108 #else 109 *a = atoi(name); 110 #endif 111 } 112 PetscFunctionReturn(0); 113 } 114 115 #undef __FUNCT__ 116 #define __FUNCT__ "PetscOptionsStringToReal" 117 /* 118 Converts a string to PetscReal value. Handles special cases like "default" and "decide" 119 */ 120 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsStringToReal(const char name[],PetscReal *a) 121 { 122 PetscErrorCode ierr; 123 size_t len; 124 PetscBool decide,tdefault; 125 126 PetscFunctionBegin; 127 ierr = PetscStrlen(name,&len);CHKERRQ(ierr); 128 if (!len) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"character string of length zero has no numerical value"); 129 130 ierr = PetscStrcasecmp(name,"PETSC_DEFAULT",&tdefault);CHKERRQ(ierr); 131 if (!tdefault) { 132 ierr = PetscStrcasecmp(name,"DEFAULT",&tdefault);CHKERRQ(ierr); 133 } 134 ierr = PetscStrcasecmp(name,"PETSC_DECIDE",&decide);CHKERRQ(ierr); 135 if (!decide) { 136 ierr = PetscStrcasecmp(name,"DECIDE",&decide);CHKERRQ(ierr); 137 } 138 139 if (tdefault) { 140 *a = PETSC_DEFAULT; 141 } else if (decide) { 142 *a = PETSC_DECIDE; 143 } else { 144 if (name[0] != '+' && name[0] != '-' && name[0] != '.' && name[0] < '0' && name[0] > '9') { 145 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no numeric value ",name); 146 } 147 *a = atof(name); 148 } 149 PetscFunctionReturn(0); 150 } 151 152 #undef __FUNCT__ 153 #define __FUNCT__ "PetscOptionsStringToBool" 154 /* 155 PetscOptionsStringToBool - Converts string to PetscBool , handles cases like "yes", "no", "true", "false", "0", "1" 156 */ 157 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsStringToBool(const char value[], PetscBool *a) 158 { 159 PetscBool istrue, isfalse; 160 size_t len; 161 PetscErrorCode ierr; 162 163 PetscFunctionBegin; 164 ierr = PetscStrlen(value, &len);CHKERRQ(ierr); 165 if (!len) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "Character string of length zero has no logical value"); 166 ierr = PetscStrcasecmp(value,"TRUE",&istrue);CHKERRQ(ierr); 167 if (istrue) {*a = PETSC_TRUE; PetscFunctionReturn(0);} 168 ierr = PetscStrcasecmp(value,"YES",&istrue);CHKERRQ(ierr); 169 if (istrue) {*a = PETSC_TRUE; PetscFunctionReturn(0);} 170 ierr = PetscStrcasecmp(value,"1",&istrue);CHKERRQ(ierr); 171 if (istrue) {*a = PETSC_TRUE; PetscFunctionReturn(0);} 172 ierr = PetscStrcasecmp(value,"on",&istrue);CHKERRQ(ierr); 173 if (istrue) {*a = PETSC_TRUE; PetscFunctionReturn(0);} 174 ierr = PetscStrcasecmp(value,"FALSE",&isfalse);CHKERRQ(ierr); 175 if (isfalse) {*a = PETSC_FALSE; PetscFunctionReturn(0);} 176 ierr = PetscStrcasecmp(value,"NO",&isfalse);CHKERRQ(ierr); 177 if (isfalse) {*a = PETSC_FALSE; PetscFunctionReturn(0);} 178 ierr = PetscStrcasecmp(value,"0",&isfalse);CHKERRQ(ierr); 179 if (isfalse) {*a = PETSC_FALSE; PetscFunctionReturn(0);} 180 ierr = PetscStrcasecmp(value,"off",&isfalse);CHKERRQ(ierr); 181 if (isfalse) {*a = PETSC_FALSE; PetscFunctionReturn(0);} 182 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "Unknown logical value: %s", value); 183 PetscFunctionReturn(0); 184 } 185 186 #undef __FUNCT__ 187 #define __FUNCT__ "PetscGetProgramName" 188 /*@C 189 PetscGetProgramName - Gets the name of the running program. 190 191 Not Collective 192 193 Input Parameter: 194 . len - length of the string name 195 196 Output Parameter: 197 . name - the name of the running program 198 199 Level: advanced 200 201 Notes: 202 The name of the program is copied into the user-provided character 203 array of length len. On some machines the program name includes 204 its entire path, so one should generally set len >= PETSC_MAX_PATH_LEN. 205 @*/ 206 PetscErrorCode PETSCSYS_DLLEXPORT PetscGetProgramName(char name[],size_t len) 207 { 208 PetscErrorCode ierr; 209 210 PetscFunctionBegin; 211 if (!options) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call PetscInitialize() first"); 212 if (!options->namegiven) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Unable to determine program name"); 213 ierr = PetscStrncpy(name,options->programname,len);CHKERRQ(ierr); 214 PetscFunctionReturn(0); 215 } 216 217 #undef __FUNCT__ 218 #define __FUNCT__ "PetscSetProgramName" 219 PetscErrorCode PETSCSYS_DLLEXPORT PetscSetProgramName(const char name[]) 220 { 221 PetscErrorCode ierr; 222 223 PetscFunctionBegin; 224 options->namegiven = PETSC_TRUE; 225 ierr = PetscStrncpy(options->programname,name,PETSC_MAX_PATH_LEN);CHKERRQ(ierr); 226 PetscFunctionReturn(0); 227 } 228 229 #undef __FUNCT__ 230 #define __FUNCT__ "PetscOptionsValidKey" 231 /*@ 232 PetscOptionsValidKey - PETSc Options database keys must begin with a - followed by a letter. 233 234 Input Parameter: 235 . in_str - string to check if valid 236 237 Output Parameter: 238 . key - PETSC_TRUE if a valid key 239 240 Level: intermediate 241 242 @*/ 243 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsValidKey(const char in_str[],PetscBool *key) 244 { 245 PetscFunctionBegin; 246 *key = PETSC_FALSE; 247 if (!in_str) PetscFunctionReturn(0); 248 if (in_str[0] != '-') PetscFunctionReturn(0); 249 if ((in_str[1] < 'A') || (in_str[1] > 'z')) PetscFunctionReturn(0); 250 *key = PETSC_TRUE; 251 PetscFunctionReturn(0); 252 } 253 254 #undef __FUNCT__ 255 #define __FUNCT__ "PetscOptionsInsertString" 256 /*@C 257 PetscOptionsInsertString - Inserts options into the database from a string 258 259 Not collective: but only processes that call this routine will set the options 260 included in the string 261 262 Input Parameter: 263 . in_str - string that contains options separated by blanks 264 265 266 Level: intermediate 267 268 Contributed by Boyana Norris 269 270 .seealso: PetscOptionsSetValue(), PetscOptionsPrint(), PetscOptionsHasName(), PetscOptionsGetInt(), 271 PetscOptionsGetReal(), PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsBool(), 272 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 273 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 274 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 275 PetscOptionsList(), PetscOptionsEList(), PetscOptionsInsertFile() 276 277 @*/ 278 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsInsertString(const char in_str[]) 279 { 280 char *first,*second; 281 PetscErrorCode ierr; 282 PetscToken token; 283 PetscBool key,ispush,ispop; 284 285 PetscFunctionBegin; 286 ierr = PetscTokenCreate(in_str,' ',&token);CHKERRQ(ierr); 287 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 288 while (first) { 289 ierr = PetscStrcasecmp(first,"-prefix_push",&ispush);CHKERRQ(ierr); 290 ierr = PetscStrcasecmp(first,"-prefix_pop",&ispop);CHKERRQ(ierr); 291 ierr = PetscOptionsValidKey(first,&key);CHKERRQ(ierr); 292 if (ispush) { 293 ierr = PetscTokenFind(token,&second);CHKERRQ(ierr); 294 ierr = PetscOptionsPrefixPush(second);CHKERRQ(ierr); 295 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 296 } else if (ispop) { 297 ierr = PetscOptionsPrefixPop();CHKERRQ(ierr); 298 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 299 } else if (key) { 300 ierr = PetscTokenFind(token,&second);CHKERRQ(ierr); 301 ierr = PetscOptionsValidKey(second,&key);CHKERRQ(ierr); 302 if (!key) { 303 ierr = PetscOptionsSetValue(first,second);CHKERRQ(ierr); 304 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 305 } else { 306 ierr = PetscOptionsSetValue(first,PETSC_NULL);CHKERRQ(ierr); 307 first = second; 308 } 309 } else { 310 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 311 } 312 } 313 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 314 PetscFunctionReturn(0); 315 } 316 317 /* 318 Returns a line (ended by a \n, \r or null character of any length. Result should be freed with free() 319 */ 320 static char *Petscgetline(FILE * f) 321 { 322 size_t size = 0; 323 size_t len = 0; 324 size_t last = 0; 325 char * buf = PETSC_NULL; 326 327 if (feof(f)) return 0; 328 do { 329 size += 1024; /* BUFSIZ is defined as "the optimal read size for this platform" */ 330 buf = (char*)realloc((void *)buf,size); /* realloc(NULL,n) is the same as malloc(n) */ 331 /* Actually do the read. Note that fgets puts a terminal '\0' on the 332 end of the string, so we make sure we overwrite this */ 333 if (!fgets(buf+len,size,f)) buf[len]=0; 334 PetscStrlen(buf,&len); 335 last = len - 1; 336 } while (!feof(f) && buf[last] != '\n' && buf[last] != '\r'); 337 if (len) return buf; 338 free(buf); 339 return 0; 340 } 341 342 343 #undef __FUNCT__ 344 #define __FUNCT__ "PetscOptionsInsertFile" 345 /*@C 346 PetscOptionsInsertFile - Inserts options into the database from a file. 347 348 Collective on MPI_Comm 349 350 Input Parameter: 351 + comm - the processes that will share the options (usually PETSC_COMM_WORLD) 352 . file - name of file 353 - require - if PETSC_TRUE will generate an error if the file does not exist 354 355 356 Level: intermediate 357 358 .seealso: PetscOptionsSetValue(), PetscOptionsPrint(), PetscOptionsHasName(), PetscOptionsGetInt(), 359 PetscOptionsGetReal(), PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsBool(), 360 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 361 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 362 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 363 PetscOptionsList(), PetscOptionsEList() 364 365 @*/ 366 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsInsertFile(MPI_Comm comm,const char file[],PetscBool require) 367 { 368 char *string,fname[PETSC_MAX_PATH_LEN],*first,*second,*third,*vstring = 0,*astring = 0; 369 PetscErrorCode ierr; 370 size_t i,len; 371 FILE *fd; 372 PetscToken token; 373 int err; 374 char cmt[3]={'#','!','%'},*cmatch; 375 PetscMPIInt rank,cnt=0,acnt=0; 376 377 PetscFunctionBegin; 378 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 379 if (!rank) { 380 /* Warning: assume a maximum size for all options in a string */ 381 ierr = PetscMalloc(128000*sizeof(char),&vstring);CHKERRQ(ierr); 382 vstring[0] = 0; 383 ierr = PetscMalloc(64000*sizeof(char),&astring);CHKERRQ(ierr); 384 astring[0] = 0; 385 cnt = 0; 386 acnt = 0; 387 388 ierr = PetscFixFilename(file,fname);CHKERRQ(ierr); 389 fd = fopen(fname,"r"); 390 if (fd) { 391 /* the following line will not work when opening initial files (like .petscrc) since info is not yet set */ 392 ierr = PetscInfo1(0,"Opened options file %s\n",file);CHKERRQ(ierr); 393 while ((string = Petscgetline(fd))) { 394 /* eliminate comments from each line */ 395 for (i=0; i<3; i++){ 396 ierr = PetscStrchr(string,cmt[i],&cmatch); 397 if (cmatch) *cmatch = 0; 398 } 399 ierr = PetscStrlen(string,&len);CHKERRQ(ierr); 400 /* replace tabs, ^M, \n with " " */ 401 for (i=0; i<len; i++) { 402 if (string[i] == '\t' || string[i] == '\r' || string[i] == '\n') { 403 string[i] = ' '; 404 } 405 } 406 ierr = PetscTokenCreate(string,' ',&token);CHKERRQ(ierr); 407 free(string); 408 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 409 if (!first) { 410 goto destroy; 411 } else if (!first[0]) { /* if first token is empty spaces, redo first token */ 412 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 413 } 414 ierr = PetscTokenFind(token,&second);CHKERRQ(ierr); 415 if (!first) { 416 goto destroy; 417 } else if (first[0] == '-') { 418 /* warning: should be making sure we do not overfill vstring */ 419 ierr = PetscStrcat(vstring,first);CHKERRQ(ierr); 420 ierr = PetscStrcat(vstring," ");CHKERRQ(ierr); 421 if (second) { 422 /* protect second with quotes in case it contains strings */ 423 ierr = PetscStrcat(vstring,"\"");CHKERRQ(ierr); 424 ierr = PetscStrcat(vstring,second);CHKERRQ(ierr); 425 ierr = PetscStrcat(vstring,"\"");CHKERRQ(ierr); 426 } 427 ierr = PetscStrcat(vstring," ");CHKERRQ(ierr); 428 } else { 429 PetscBool match; 430 431 ierr = PetscStrcasecmp(first,"alias",&match);CHKERRQ(ierr); 432 if (match) { 433 ierr = PetscTokenFind(token,&third);CHKERRQ(ierr); 434 if (!third) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Error in options file:alias missing (%s)",second); 435 ierr = PetscStrcat(astring,second);CHKERRQ(ierr); 436 ierr = PetscStrcat(astring," ");CHKERRQ(ierr); 437 ierr = PetscStrcat(astring,third);CHKERRQ(ierr); 438 ierr = PetscStrcat(astring," ");CHKERRQ(ierr); 439 } else { 440 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Unknown statement in options file: (%s)",string); 441 } 442 } 443 destroy: 444 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 445 } 446 err = fclose(fd); 447 if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file"); 448 ierr = PetscStrlen(astring,&len);CHKERRQ(ierr); 449 acnt = PetscMPIIntCast(len);CHKERRQ(ierr); 450 ierr = PetscStrlen(vstring,&len);CHKERRQ(ierr); 451 cnt = PetscMPIIntCast(len);CHKERRQ(ierr); 452 } else if (require) { 453 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"Unable to open Options File %s",fname); 454 } 455 } 456 457 ierr = MPI_Bcast(&acnt,1,MPI_INT,0,comm);CHKERRQ(ierr); 458 if (acnt) { 459 PetscToken token; 460 char *first,*second; 461 462 if (rank) { 463 ierr = PetscMalloc((acnt+1)*sizeof(char),&astring);CHKERRQ(ierr); 464 } 465 ierr = MPI_Bcast(astring,acnt,MPI_CHAR,0,comm);CHKERRQ(ierr); 466 astring[acnt] = 0; 467 ierr = PetscTokenCreate(astring,' ',&token);CHKERRQ(ierr); 468 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 469 while (first) { 470 ierr = PetscTokenFind(token,&second);CHKERRQ(ierr); 471 ierr = PetscOptionsSetAlias(first,second);CHKERRQ(ierr); 472 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 473 } 474 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 475 } 476 477 ierr = MPI_Bcast(&cnt,1,MPI_INT,0,comm);CHKERRQ(ierr); 478 if (cnt) { 479 if (rank) { 480 ierr = PetscMalloc((cnt+1)*sizeof(char),&vstring);CHKERRQ(ierr); 481 } 482 ierr = MPI_Bcast(vstring,cnt,MPI_CHAR,0,comm);CHKERRQ(ierr); 483 vstring[cnt] = 0; 484 ierr = PetscOptionsInsertString(vstring);CHKERRQ(ierr); 485 } 486 ierr = PetscFree(astring);CHKERRQ(ierr); 487 ierr = PetscFree(vstring);CHKERRQ(ierr); 488 PetscFunctionReturn(0); 489 } 490 491 #undef __FUNCT__ 492 #define __FUNCT__ "PetscOptionsInsertArgs_Private" 493 static PetscErrorCode PetscOptionsInsertArgs_Private(int argc,char *args[]) 494 { 495 PetscErrorCode ierr; 496 int left = argc - 1; 497 char **eargs = args + 1; 498 499 PetscFunctionBegin; 500 while (left) { 501 PetscBool isoptions_file,isprefixpush,isprefixpop,isp4,tisp4,isp4yourname,isp4rmrank; 502 ierr = PetscStrcasecmp(eargs[0],"-options_file",&isoptions_file);CHKERRQ(ierr); 503 ierr = PetscStrcasecmp(eargs[0],"-prefix_push",&isprefixpush);CHKERRQ(ierr); 504 ierr = PetscStrcasecmp(eargs[0],"-prefix_pop",&isprefixpop);CHKERRQ(ierr); 505 ierr = PetscStrcasecmp(eargs[0],"-p4pg",&isp4);CHKERRQ(ierr); 506 ierr = PetscStrcasecmp(eargs[0],"-p4yourname",&isp4yourname);CHKERRQ(ierr); 507 ierr = PetscStrcasecmp(eargs[0],"-p4rmrank",&isp4rmrank);CHKERRQ(ierr); 508 ierr = PetscStrcasecmp(eargs[0],"-p4wd",&tisp4);CHKERRQ(ierr); 509 isp4 = (PetscBool) (isp4 || tisp4); 510 ierr = PetscStrcasecmp(eargs[0],"-np",&tisp4);CHKERRQ(ierr); 511 isp4 = (PetscBool) (isp4 || tisp4); 512 ierr = PetscStrcasecmp(eargs[0],"-p4amslave",&tisp4);CHKERRQ(ierr); 513 514 if (eargs[0][0] != '-') { 515 eargs++; left--; 516 } else if (isoptions_file) { 517 if (left <= 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Missing filename for -options_file filename option"); 518 if (eargs[1][0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Missing filename for -options_file filename option"); 519 ierr = PetscOptionsInsertFile(PETSC_COMM_WORLD,eargs[1],PETSC_TRUE);CHKERRQ(ierr); 520 eargs += 2; left -= 2; 521 } else if (isprefixpush) { 522 if (left <= 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Missing prefix for -prefix_push option"); 523 if (eargs[1][0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Missing prefix for -prefix_push option (prefixes cannot start with '-')"); 524 ierr = PetscOptionsPrefixPush(eargs[1]);CHKERRQ(ierr); 525 eargs += 2; left -= 2; 526 } else if (isprefixpop) { 527 ierr = PetscOptionsPrefixPop();CHKERRQ(ierr); 528 eargs++; left--; 529 530 /* 531 These are "bad" options that MPICH, etc put on the command line 532 we strip them out here. 533 */ 534 } else if (tisp4 || isp4rmrank) { 535 eargs += 1; left -= 1; 536 } else if (isp4 || isp4yourname) { 537 eargs += 2; left -= 2; 538 } else if ((left < 2) || ((eargs[1][0] == '-') && 539 ((eargs[1][1] > '9') || (eargs[1][1] < '0')))) { 540 ierr = PetscOptionsSetValue(eargs[0],PETSC_NULL);CHKERRQ(ierr); 541 eargs++; left--; 542 } else { 543 ierr = PetscOptionsSetValue(eargs[0],eargs[1]);CHKERRQ(ierr); 544 eargs += 2; left -= 2; 545 } 546 } 547 PetscFunctionReturn(0); 548 } 549 550 551 #undef __FUNCT__ 552 #define __FUNCT__ "PetscOptionsInsert" 553 /*@C 554 PetscOptionsInsert - Inserts into the options database from the command line, 555 the environmental variable and a file. 556 557 Input Parameters: 558 + argc - count of number of command line arguments 559 . args - the command line arguments 560 - file - optional filename, defaults to ~username/.petscrc 561 562 Note: 563 Since PetscOptionsInsert() is automatically called by PetscInitialize(), 564 the user does not typically need to call this routine. PetscOptionsInsert() 565 can be called several times, adding additional entries into the database. 566 567 Options Database Keys: 568 + -options_monitor <optional filename> - print options names and values as they are set 569 . -options_file <filename> - read options from a file 570 571 Level: advanced 572 573 Concepts: options database^adding 574 575 .seealso: PetscOptionsDestroy_Private(), PetscOptionsPrint(), PetscOptionsInsertString(), PetscOptionsInsertFile(), 576 PetscInitialize() 577 @*/ 578 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsInsert(int *argc,char ***args,const char file[]) 579 { 580 PetscErrorCode ierr; 581 PetscMPIInt rank; 582 char pfile[PETSC_MAX_PATH_LEN]; 583 PetscBool flag = PETSC_FALSE; 584 585 PetscFunctionBegin; 586 if (!options) { 587 fprintf(stderr, "Options have not been enabled.\nYou might have forgotten to call PetscInitialize().\n"); 588 MPI_Abort(MPI_COMM_WORLD, PETSC_ERR_SUP); 589 } 590 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); 591 592 options->argc = (argc) ? *argc : 0; 593 options->args = (args) ? *args : PETSC_NULL; 594 595 if (file && file[0]) { 596 ierr = PetscOptionsInsertFile(PETSC_COMM_WORLD,file,PETSC_TRUE);CHKERRQ(ierr); 597 } 598 /* 599 We want to be able to give -skip_petscrc on the command line, but need to parse it first. Since the command line 600 should take precedence, we insert it twice. It would be sufficient to just scan for -skip_petscrc. 601 */ 602 if (argc && args && *argc) {ierr = PetscOptionsInsertArgs_Private(*argc,*args);CHKERRQ(ierr);} 603 ierr = PetscOptionsGetBool(PETSC_NULL,"-skip_petscrc",&flag,PETSC_NULL);CHKERRQ(ierr); 604 if (!flag) { 605 ierr = PetscGetHomeDirectory(pfile,PETSC_MAX_PATH_LEN-16);CHKERRQ(ierr); 606 /* warning: assumes all processes have a home directory or none, but nothing in between */ 607 if (pfile[0]) { 608 ierr = PetscStrcat(pfile,"/.petscrc");CHKERRQ(ierr); 609 ierr = PetscOptionsInsertFile(PETSC_COMM_WORLD,pfile,PETSC_FALSE);CHKERRQ(ierr); 610 } 611 ierr = PetscOptionsInsertFile(PETSC_COMM_WORLD,".petscrc",PETSC_FALSE);CHKERRQ(ierr); 612 ierr = PetscOptionsInsertFile(PETSC_COMM_WORLD,"petscrc",PETSC_FALSE);CHKERRQ(ierr); 613 } 614 615 /* insert environmental options */ 616 { 617 char *eoptions = 0; 618 size_t len = 0; 619 if (!rank) { 620 eoptions = (char*)getenv("PETSC_OPTIONS"); 621 ierr = PetscStrlen(eoptions,&len);CHKERRQ(ierr); 622 ierr = MPI_Bcast(&len,1,MPIU_SIZE_T,0,PETSC_COMM_WORLD);CHKERRQ(ierr); 623 } else { 624 ierr = MPI_Bcast(&len,1,MPIU_SIZE_T,0,PETSC_COMM_WORLD);CHKERRQ(ierr); 625 if (len) { 626 ierr = PetscMalloc((len+1)*sizeof(char*),&eoptions);CHKERRQ(ierr); 627 } 628 } 629 if (len) { 630 ierr = MPI_Bcast(eoptions,len,MPI_CHAR,0,PETSC_COMM_WORLD);CHKERRQ(ierr); 631 if (rank) eoptions[len] = 0; 632 ierr = PetscOptionsInsertString(eoptions);CHKERRQ(ierr); 633 if (rank) {ierr = PetscFree(eoptions);CHKERRQ(ierr);} 634 } 635 } 636 637 /* insert command line options again because they take precedence over arguments in petscrc/environment */ 638 if (argc && args && *argc) {ierr = PetscOptionsInsertArgs_Private(*argc,*args);CHKERRQ(ierr);} 639 PetscFunctionReturn(0); 640 } 641 642 #undef __FUNCT__ 643 #define __FUNCT__ "PetscOptionsPrint" 644 /*@C 645 PetscOptionsPrint - Prints the options that have been loaded. This is 646 useful for debugging purposes. 647 648 Logically Collective on PETSC_COMM_WORLD 649 650 Input Parameter: 651 . FILE fd - location to print options (usually stdout or stderr) 652 653 Options Database Key: 654 . -optionstable - Activates PetscOptionsPrint() within PetscFinalize() 655 656 Level: advanced 657 658 Concepts: options database^printing 659 660 .seealso: PetscOptionsAllUsed() 661 @*/ 662 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsPrint(FILE *fd) 663 { 664 PetscErrorCode ierr; 665 PetscInt i; 666 667 PetscFunctionBegin; 668 if (!fd) fd = PETSC_STDOUT; 669 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 670 if (options->N) { 671 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"#PETSc Option Table entries:\n");CHKERRQ(ierr); 672 } else { 673 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"#No PETSc Option Table entries\n");CHKERRQ(ierr); 674 } 675 for (i=0; i<options->N; i++) { 676 if (options->values[i]) { 677 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"-%s %s\n",options->names[i],options->values[i]);CHKERRQ(ierr); 678 } else { 679 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"-%s\n",options->names[i]);CHKERRQ(ierr); 680 } 681 } 682 if (options->N) { 683 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"#End of PETSc Option Table entries\n");CHKERRQ(ierr); 684 } 685 PetscFunctionReturn(0); 686 } 687 688 #undef __FUNCT__ 689 #define __FUNCT__ "PetscOptionsGetAll" 690 /*@C 691 PetscOptionsGetAll - Lists all the options the program was run with in a single string. 692 693 Not Collective 694 695 Output Parameter: 696 . copts - pointer where string pointer is stored 697 698 Notes: the array and each entry in the array should be freed with PetscFree() 699 700 Level: advanced 701 702 Concepts: options database^listing 703 704 .seealso: PetscOptionsAllUsed(), PetscOptionsPrint() 705 @*/ 706 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetAll(char *copts[]) 707 { 708 PetscErrorCode ierr; 709 PetscInt i; 710 size_t len = 1,lent; 711 char *coptions; 712 713 PetscFunctionBegin; 714 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 715 716 /* count the length of the required string */ 717 for (i=0; i<options->N; i++) { 718 ierr = PetscStrlen(options->names[i],&lent);CHKERRQ(ierr); 719 len += 2 + lent; 720 if (options->values[i]) { 721 ierr = PetscStrlen(options->values[i],&lent);CHKERRQ(ierr); 722 len += 1 + lent; 723 } 724 } 725 ierr = PetscMalloc(len*sizeof(char),&coptions);CHKERRQ(ierr); 726 coptions[0] = 0; 727 for (i=0; i<options->N; i++) { 728 ierr = PetscStrcat(coptions,"-");CHKERRQ(ierr); 729 ierr = PetscStrcat(coptions,options->names[i]);CHKERRQ(ierr); 730 ierr = PetscStrcat(coptions," ");CHKERRQ(ierr); 731 if (options->values[i]) { 732 ierr = PetscStrcat(coptions,options->values[i]);CHKERRQ(ierr); 733 ierr = PetscStrcat(coptions," ");CHKERRQ(ierr); 734 } 735 } 736 *copts = coptions; 737 PetscFunctionReturn(0); 738 } 739 740 #undef __FUNCT__ 741 #define __FUNCT__ "PetscOptionsPrefixPush" 742 /*@ 743 PetscOptionsPrefixPush - Designate a prefix to be used by all options insertions to follow. 744 745 Not Collective, but prefix will only be applied on calling ranks 746 747 Input Parameter: 748 . prefix - The string to append to the existing prefix 749 750 Options Database Keys: 751 + -prefix_push <some_prefix_> - push the given prefix 752 - -prefix_pop - pop the last prefix 753 754 Notes: 755 It is common to use this in conjunction with -options_file as in 756 757 $ -prefix_push system1_ -options_file system1rc -prefix_pop -prefix_push system2_ -options_file system2rc -prefix_pop 758 759 where the files no longer require all options to be prefixed with -system2_. 760 761 Level: advanced 762 763 .seealso: PetscOptionsPrefixPop() 764 @*/ 765 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsPrefixPush(const char prefix[]) 766 { 767 PetscErrorCode ierr; 768 size_t n; 769 PetscInt start; 770 char buf[2048]; 771 PetscBool key; 772 773 PetscFunctionBegin; 774 PetscValidCharPointer(prefix,1); 775 /* Want to check validity of the key using PetscOptionsValidKey(), which requires that the first character is a '-' */ 776 buf[0] = '-'; 777 ierr = PetscStrncpy(buf+1,prefix,sizeof buf - 1); 778 buf[sizeof buf - 1] = 0; 779 ierr = PetscOptionsValidKey(buf,&key);CHKERRQ(ierr); 780 if (!key) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"Given prefix \"%s\" not valid (the first character must be a letter, do not include leading '-')",prefix); 781 782 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 783 if (options->prefixind >= MAXPREFIXES) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Maximum depth of prefix stack %d exceeded, recompile \n src/sys/objects/options.c with larger value for MAXPREFIXES",MAXPREFIXES); 784 start = options->prefixind ? options->prefixstack[options->prefixind-1] : 0; 785 ierr = PetscStrlen(prefix,&n);CHKERRQ(ierr); 786 if (n+1 > sizeof(options->prefix)-start) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Maximum prefix length %d exceeded",sizeof(options->prefix)); 787 ierr = PetscMemcpy(options->prefix+start,prefix,n+1);CHKERRQ(ierr); 788 options->prefixstack[options->prefixind++] = start+n; 789 PetscFunctionReturn(0); 790 } 791 792 #undef __FUNCT__ 793 #define __FUNCT__ "PetscOptionsPrefixPop" 794 /*@ 795 PetscOptionsPrefixPop - Remove the latest options prefix, see PetscOptionsPrefixPush() for details 796 797 Not Collective, but prefix will only be popped on calling ranks 798 799 Level: advanced 800 801 .seealso: PetscOptionsPrefixPush() 802 @*/ 803 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsPrefixPop(void) 804 { 805 PetscInt offset; 806 807 PetscFunctionBegin; 808 if (options->prefixind < 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"More prefixes popped than pushed"); 809 options->prefixind--; 810 offset = options->prefixind ? options->prefixstack[options->prefixind-1] : 0; 811 options->prefix[offset] = 0; 812 PetscFunctionReturn(0); 813 } 814 815 #undef __FUNCT__ 816 #define __FUNCT__ "PetscOptionsClear" 817 /*@C 818 PetscOptionsClear - Removes all options form the database leaving it empty. 819 820 Level: developer 821 822 .seealso: PetscOptionsInsert() 823 @*/ 824 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsClear(void) 825 { 826 PetscInt i; 827 828 PetscFunctionBegin; 829 if (!options) PetscFunctionReturn(0); 830 for (i=0; i<options->N; i++) { 831 if (options->names[i]) free(options->names[i]); 832 if (options->values[i]) free(options->values[i]); 833 } 834 for (i=0; i<options->Naliases; i++) { 835 free(options->aliases1[i]); 836 free(options->aliases2[i]); 837 } 838 options->prefix[0] = 0; 839 options->prefixind = 0; 840 options->N = 0; 841 options->Naliases = 0; 842 PetscFunctionReturn(0); 843 } 844 845 #undef __FUNCT__ 846 #define __FUNCT__ "PetscOptionsDestroy" 847 /*@C 848 PetscOptionsDestroy - Destroys the option database. 849 850 Note: 851 Since PetscOptionsDestroy() is called by PetscFinalize(), the user 852 typically does not need to call this routine. 853 854 Level: developer 855 856 .seealso: PetscOptionsInsert() 857 @*/ 858 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsDestroy(void) 859 { 860 PetscErrorCode ierr; 861 862 PetscFunctionBegin; 863 if (!options) PetscFunctionReturn(0); 864 ierr = PetscOptionsClear();CHKERRQ(ierr); 865 free(options); 866 options = 0; 867 PetscFunctionReturn(0); 868 } 869 870 #undef __FUNCT__ 871 #define __FUNCT__ "PetscOptionsSetValue" 872 /*@C 873 PetscOptionsSetValue - Sets an option name-value pair in the options 874 database, overriding whatever is already present. 875 876 Not collective, but setting values on certain processors could cause problems 877 for parallel objects looking for options. 878 879 Input Parameters: 880 + name - name of option, this SHOULD have the - prepended 881 - value - the option value (not used for all options) 882 883 Level: intermediate 884 885 Note: 886 Only some options have values associated with them, such as 887 -ksp_rtol tol. Other options stand alone, such as -ksp_monitor. 888 889 Concepts: options database^adding option 890 891 .seealso: PetscOptionsInsert() 892 @*/ 893 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsSetValue(const char iname[],const char value[]) 894 { 895 size_t len; 896 PetscErrorCode ierr; 897 PetscInt N,n,i; 898 char **names; 899 char fullname[2048]; 900 const char *name = iname; 901 PetscBool gt,match; 902 903 PetscFunctionBegin; 904 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 905 906 /* this is so that -h and -hel\p are equivalent (p4 does not like -help)*/ 907 ierr = PetscStrcasecmp(name,"-h",&match);CHKERRQ(ierr); 908 if (match) name = "-help"; 909 910 name++; /* skip starting hyphen */ 911 if (options->prefixind > 0) { 912 ierr = PetscStrncpy(fullname,options->prefix,sizeof fullname);CHKERRQ(ierr); 913 ierr = PetscStrncat(fullname,name,sizeof fullname);CHKERRQ(ierr); 914 name = fullname; 915 } 916 917 /* check against aliases */ 918 N = options->Naliases; 919 for (i=0; i<N; i++) { 920 ierr = PetscStrcasecmp(options->aliases1[i],name,&match);CHKERRQ(ierr); 921 if (match) { 922 name = options->aliases2[i]; 923 break; 924 } 925 } 926 927 N = options->N; 928 n = N; 929 names = options->names; 930 931 for (i=0; i<N; i++) { 932 ierr = PetscStrcasecmp(names[i],name,&match);CHKERRQ(ierr); 933 ierr = PetscStrgrt(names[i],name,>);CHKERRQ(ierr); 934 if (match) { 935 if (options->values[i]) free(options->values[i]); 936 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 937 if (len) { 938 options->values[i] = (char*)malloc((len+1)*sizeof(char)); 939 ierr = PetscStrcpy(options->values[i],value);CHKERRQ(ierr); 940 } else { options->values[i] = 0;} 941 PetscOptionsMonitor(name,value); 942 PetscFunctionReturn(0); 943 } else if (gt) { 944 n = i; 945 break; 946 } 947 } 948 if (N >= MAXOPTIONS) { 949 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"No more room in option table, limit %d recompile \n src/sys/objects/options.c with larger value for MAXOPTIONS\n",MAXOPTIONS); 950 } 951 /* shift remaining values down 1 */ 952 for (i=N; i>n; i--) { 953 options->names[i] = options->names[i-1]; 954 options->values[i] = options->values[i-1]; 955 options->used[i] = options->used[i-1]; 956 } 957 /* insert new name and value */ 958 ierr = PetscStrlen(name,&len);CHKERRQ(ierr); 959 options->names[n] = (char*)malloc((len+1)*sizeof(char)); 960 ierr = PetscStrcpy(options->names[n],name);CHKERRQ(ierr); 961 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 962 if (len) { 963 options->values[n] = (char*)malloc((len+1)*sizeof(char)); 964 ierr = PetscStrcpy(options->values[n],value);CHKERRQ(ierr); 965 } else {options->values[n] = 0;} 966 options->used[n] = PETSC_FALSE; 967 options->N++; 968 PetscOptionsMonitor(name,value); 969 PetscFunctionReturn(0); 970 } 971 972 #undef __FUNCT__ 973 #define __FUNCT__ "PetscOptionsClearValue" 974 /*@C 975 PetscOptionsClearValue - Clears an option name-value pair in the options 976 database, overriding whatever is already present. 977 978 Not Collective, but setting values on certain processors could cause problems 979 for parallel objects looking for options. 980 981 Input Parameter: 982 . name - name of option, this SHOULD have the - prepended 983 984 Level: intermediate 985 986 Concepts: options database^removing option 987 .seealso: PetscOptionsInsert() 988 @*/ 989 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsClearValue(const char iname[]) 990 { 991 PetscErrorCode ierr; 992 PetscInt N,n,i; 993 char **names,*name=(char*)iname; 994 PetscBool gt,match; 995 996 PetscFunctionBegin; 997 if (name[0] != '-') SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Name must begin with -: Instead %s",name); 998 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 999 1000 name++; 1001 1002 N = options->N; n = 0; 1003 names = options->names; 1004 1005 for (i=0; i<N; i++) { 1006 ierr = PetscStrcasecmp(names[i],name,&match);CHKERRQ(ierr); 1007 ierr = PetscStrgrt(names[i],name,>);CHKERRQ(ierr); 1008 if (match) { 1009 if (options->names[i]) free(options->names[i]); 1010 if (options->values[i]) free(options->values[i]); 1011 PetscOptionsMonitor(name,""); 1012 break; 1013 } else if (gt) { 1014 PetscFunctionReturn(0); /* it was not listed */ 1015 } 1016 n++; 1017 } 1018 if (n == N) PetscFunctionReturn(0); /* it was not listed */ 1019 1020 /* shift remaining values down 1 */ 1021 for (i=n; i<N-1; i++) { 1022 options->names[i] = options->names[i+1]; 1023 options->values[i] = options->values[i+1]; 1024 options->used[i] = options->used[i+1]; 1025 } 1026 options->N--; 1027 PetscFunctionReturn(0); 1028 } 1029 1030 #undef __FUNCT__ 1031 #define __FUNCT__ "PetscOptionsSetAlias" 1032 /*@C 1033 PetscOptionsSetAlias - Makes a key and alias for another key 1034 1035 Not Collective, but setting values on certain processors could cause problems 1036 for parallel objects looking for options. 1037 1038 Input Parameters: 1039 + inewname - the alias 1040 - ioldname - the name that alias will refer to 1041 1042 Level: advanced 1043 1044 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),OptionsHasName(), 1045 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(),PetscOptionsBool(), 1046 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1047 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1048 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1049 PetscOptionsList(), PetscOptionsEList() 1050 @*/ 1051 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsSetAlias(const char inewname[],const char ioldname[]) 1052 { 1053 PetscErrorCode ierr; 1054 PetscInt n = options->Naliases; 1055 size_t len; 1056 char *newname = (char *)inewname,*oldname = (char*)ioldname; 1057 1058 PetscFunctionBegin; 1059 if (newname[0] != '-') SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"aliased must have -: Instead %s",newname); 1060 if (oldname[0] != '-') SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"aliasee must have -: Instead %s",oldname); 1061 if (n >= MAXALIASES) { 1062 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_MEM,"You have defined to many PETSc options aliases, limit %d recompile \n src/sys/objects/options.c with larger value for MAXALIASES",MAXALIASES); 1063 } 1064 1065 newname++; oldname++; 1066 ierr = PetscStrlen(newname,&len);CHKERRQ(ierr); 1067 options->aliases1[n] = (char*)malloc((len+1)*sizeof(char)); 1068 ierr = PetscStrcpy(options->aliases1[n],newname);CHKERRQ(ierr); 1069 ierr = PetscStrlen(oldname,&len);CHKERRQ(ierr); 1070 options->aliases2[n] = (char*)malloc((len+1)*sizeof(char)); 1071 ierr = PetscStrcpy(options->aliases2[n],oldname);CHKERRQ(ierr); 1072 options->Naliases++; 1073 PetscFunctionReturn(0); 1074 } 1075 1076 #undef __FUNCT__ 1077 #define __FUNCT__ "PetscOptionsFindPair_Private" 1078 static PetscErrorCode PetscOptionsFindPair_Private(const char pre[],const char name[],char *value[],PetscBool *flg) 1079 { 1080 PetscErrorCode ierr; 1081 PetscInt i,N; 1082 size_t len; 1083 char **names,tmp[256]; 1084 PetscBool match; 1085 1086 PetscFunctionBegin; 1087 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 1088 N = options->N; 1089 names = options->names; 1090 1091 if (name[0] != '-') SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Name must begin with -: Instead %s",name); 1092 1093 /* append prefix to name */ 1094 if (pre) { 1095 if (pre[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Prefix should not begin with a -"); 1096 ierr = PetscStrncpy(tmp,pre,256);CHKERRQ(ierr); 1097 ierr = PetscStrlen(tmp,&len);CHKERRQ(ierr); 1098 ierr = PetscStrncat(tmp,name+1,256-len-1);CHKERRQ(ierr); 1099 } else { 1100 ierr = PetscStrncpy(tmp,name+1,256);CHKERRQ(ierr); 1101 } 1102 1103 /* slow search */ 1104 *flg = PETSC_FALSE; 1105 for (i=0; i<N; i++) { 1106 ierr = PetscStrcasecmp(names[i],tmp,&match);CHKERRQ(ierr); 1107 if (match) { 1108 *value = options->values[i]; 1109 options->used[i] = PETSC_TRUE; 1110 *flg = PETSC_TRUE; 1111 break; 1112 } 1113 } 1114 if (!*flg) { 1115 PetscInt j,cnt = 0,locs[16],loce[16]; 1116 size_t n; 1117 ierr = PetscStrlen(tmp,&n);CHKERRQ(ierr); 1118 /* determine the location and number of all _%d_ in the key */ 1119 for (i=0; i< (PetscInt)n; i++) { 1120 if (tmp[i] == '_') { 1121 for (j=i+1; j< (PetscInt)n; j++) { 1122 if (tmp[j] >= '0' && tmp[j] <= '9') continue; 1123 if (tmp[j] == '_' && j > i+1) { /* found a number */ 1124 locs[cnt] = i+1; 1125 loce[cnt++] = j+1; 1126 } 1127 break; 1128 } 1129 } 1130 } 1131 if (cnt) { 1132 char tmp2[256]; 1133 for (i=0; i<cnt; i++) { 1134 ierr = PetscStrcpy(tmp2,"-");CHKERRQ(ierr); 1135 ierr = PetscStrncat(tmp2,tmp,locs[i]);CHKERRQ(ierr); 1136 ierr = PetscStrcat(tmp2,tmp+loce[i]);CHKERRQ(ierr); 1137 ierr = PetscOptionsFindPair_Private(PETSC_NULL,tmp2,value,flg);CHKERRQ(ierr); 1138 if (*flg) break; 1139 } 1140 } 1141 } 1142 PetscFunctionReturn(0); 1143 } 1144 1145 #undef __FUNCT__ 1146 #define __FUNCT__ "PetscOptionsReject" 1147 /*@C 1148 PetscOptionsReject - Generates an error if a certain option is given. 1149 1150 Not Collective, but setting values on certain processors could cause problems 1151 for parallel objects looking for options. 1152 1153 Input Parameters: 1154 + name - the option one is seeking 1155 - mess - error message (may be PETSC_NULL) 1156 1157 Level: advanced 1158 1159 Concepts: options database^rejecting option 1160 1161 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),OptionsHasName(), 1162 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1163 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1164 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1165 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1166 PetscOptionsList(), PetscOptionsEList() 1167 @*/ 1168 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsReject(const char name[],const char mess[]) 1169 { 1170 PetscErrorCode ierr; 1171 PetscBool flag = PETSC_FALSE; 1172 1173 PetscFunctionBegin; 1174 ierr = PetscOptionsHasName(PETSC_NULL,name,&flag);CHKERRQ(ierr); 1175 if (flag) { 1176 if (mess) { 1177 SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Program has disabled option: %s with %s",name,mess); 1178 } else { 1179 SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Program has disabled option: %s",name); 1180 } 1181 } 1182 PetscFunctionReturn(0); 1183 } 1184 1185 #undef __FUNCT__ 1186 #define __FUNCT__ "PetscOptionsHasName" 1187 /*@C 1188 PetscOptionsHasName - Determines whether a certain option is given in the database. This returns true whether the option is a number, string or boolean, even 1189 its value is set to false. 1190 1191 Not Collective 1192 1193 Input Parameters: 1194 + name - the option one is seeking 1195 - pre - string to prepend to the name or PETSC_NULL 1196 1197 Output Parameters: 1198 . set - PETSC_TRUE if found else PETSC_FALSE. 1199 1200 Level: beginner 1201 1202 Concepts: options database^has option name 1203 1204 Notes: Name cannot be simply -h 1205 1206 In many cases you probably want to use PetscOptionsGetBool() instead of calling this, to allowing toggling values. 1207 1208 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1209 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1210 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1211 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1212 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1213 PetscOptionsList(), PetscOptionsEList() 1214 @*/ 1215 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsHasName(const char pre[],const char name[],PetscBool *set) 1216 { 1217 char *value; 1218 PetscErrorCode ierr; 1219 PetscBool flag; 1220 1221 PetscFunctionBegin; 1222 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1223 if (set) *set = flag; 1224 PetscFunctionReturn(0); 1225 } 1226 1227 #undef __FUNCT__ 1228 #define __FUNCT__ "PetscOptionsGetInt" 1229 /*@C 1230 PetscOptionsGetInt - Gets the integer value for a particular option in the database. 1231 1232 Not Collective 1233 1234 Input Parameters: 1235 + pre - the string to prepend to the name or PETSC_NULL 1236 - name - the option one is seeking 1237 1238 Output Parameter: 1239 + ivalue - the integer value to return 1240 - set - PETSC_TRUE if found, else PETSC_FALSE 1241 1242 Level: beginner 1243 1244 Concepts: options database^has int 1245 1246 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), 1247 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1248 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1249 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1250 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1251 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1252 PetscOptionsList(), PetscOptionsEList() 1253 @*/ 1254 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetInt(const char pre[],const char name[],PetscInt *ivalue,PetscBool *set) 1255 { 1256 char *value; 1257 PetscErrorCode ierr; 1258 PetscBool flag; 1259 1260 PetscFunctionBegin; 1261 PetscValidCharPointer(name,2); 1262 PetscValidIntPointer(ivalue,3); 1263 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1264 if (flag) { 1265 if (!value) {if (set) *set = PETSC_FALSE;} 1266 else { 1267 if (set) *set = PETSC_TRUE; 1268 ierr = PetscOptionsStringToInt(value,ivalue);CHKERRQ(ierr); 1269 } 1270 } else { 1271 if (set) *set = PETSC_FALSE; 1272 } 1273 PetscFunctionReturn(0); 1274 } 1275 1276 #undef __FUNCT__ 1277 #define __FUNCT__ "PetscOptionsGetEList" 1278 /*@C 1279 PetscOptionsGetEList - Puts a list of option values that a single one may be selected from 1280 1281 Not Collective 1282 1283 Input Parameters: 1284 + pre - the string to prepend to the name or PETSC_NULL 1285 . opt - option name 1286 . list - the possible choices 1287 . ntext - number of choices 1288 1289 Output Parameter: 1290 + value - the index of the value to return 1291 - set - PETSC_TRUE if found, else PETSC_FALSE 1292 1293 Level: intermediate 1294 1295 See PetscOptionsList() for when the choices are given in a PetscFList() 1296 1297 Concepts: options database^list 1298 1299 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1300 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1301 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1302 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1303 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1304 PetscOptionsList(), PetscOptionsEList() 1305 @*/ 1306 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetEList(const char pre[],const char opt[],const char *const*list,PetscInt ntext,PetscInt *value,PetscBool *set) 1307 { 1308 PetscErrorCode ierr; 1309 size_t alen,len = 0; 1310 char *svalue; 1311 PetscBool aset,flg = PETSC_FALSE; 1312 PetscInt i; 1313 1314 PetscFunctionBegin; 1315 for ( i=0; i<ntext; i++) { 1316 ierr = PetscStrlen(list[i],&alen);CHKERRQ(ierr); 1317 if (alen > len) len = alen; 1318 } 1319 len += 5; /* a little extra space for user mistypes */ 1320 ierr = PetscMalloc(len*sizeof(char),&svalue);CHKERRQ(ierr); 1321 ierr = PetscOptionsGetString(pre,opt,svalue,len,&aset);CHKERRQ(ierr); 1322 if (aset) { 1323 if (set) *set = PETSC_TRUE; 1324 for (i=0; i<ntext; i++) { 1325 ierr = PetscStrcasecmp(svalue,list[i],&flg);CHKERRQ(ierr); 1326 if (flg) { 1327 *value = i; 1328 break; 1329 } 1330 } 1331 if (!flg) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_USER,"Unknown option %s for -%s%s",svalue,pre?pre:"",opt+1); 1332 } else if (set) { 1333 *set = PETSC_FALSE; 1334 } 1335 ierr = PetscFree(svalue);CHKERRQ(ierr); 1336 PetscFunctionReturn(0); 1337 } 1338 1339 #undef __FUNCT__ 1340 #define __FUNCT__ "PetscOptionsGetEnum" 1341 /*@C 1342 PetscOptionsGetEnum - Gets the enum value for a particular option in the database. 1343 1344 Not Collective 1345 1346 Input Parameters: 1347 + pre - option prefix or PETSC_NULL 1348 . opt - option name 1349 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 1350 - defaultv - the default (current) value 1351 1352 Output Parameter: 1353 + value - the value to return 1354 - set - PETSC_TRUE if found, else PETSC_FALSE 1355 1356 Level: beginner 1357 1358 Concepts: options database 1359 1360 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1361 1362 list is usually something like PCASMTypes or some other predefined list of enum names 1363 1364 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1365 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1366 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1367 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1368 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1369 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1370 PetscOptionsList(), PetscOptionsEList(), PetscOptionsGetEList(), PetscOptionsEnum() 1371 @*/ 1372 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetEnum(const char pre[],const char opt[],const char *const*list,PetscEnum *value,PetscBool *set) 1373 { 1374 PetscErrorCode ierr; 1375 PetscInt ntext = 0,tval; 1376 PetscBool fset; 1377 1378 PetscFunctionBegin; 1379 while (list[ntext++]) { 1380 if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 1381 } 1382 if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 1383 ntext -= 3; 1384 ierr = PetscOptionsGetEList(pre,opt,list,ntext,&tval,&fset);CHKERRQ(ierr); 1385 /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */ 1386 if (fset) *value = (PetscEnum)tval; 1387 if (set) *set = fset; 1388 PetscFunctionReturn(0); 1389 } 1390 1391 #undef __FUNCT__ 1392 #define __FUNCT__ "PetscOptionsGetBool" 1393 /*@C 1394 PetscOptionsGetBool - Gets the Logical (true or false) value for a particular 1395 option in the database. 1396 1397 Not Collective 1398 1399 Input Parameters: 1400 + pre - the string to prepend to the name or PETSC_NULL 1401 - name - the option one is seeking 1402 1403 Output Parameter: 1404 + ivalue - the logical value to return 1405 - set - PETSC_TRUE if found, else PETSC_FALSE 1406 1407 Level: beginner 1408 1409 Notes: 1410 TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE 1411 FALSE, false, NO, no, and 0 all translate to PETSC_FALSE 1412 1413 If the user does not supply the option (as either true or false) ivalue is NOT changed. Thus 1414 you NEED TO ALWAYS initialize the ivalue. 1415 1416 Concepts: options database^has logical 1417 1418 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), 1419 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetInt(), PetscOptionsBool(), 1420 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1421 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1422 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1423 PetscOptionsList(), PetscOptionsEList() 1424 @*/ 1425 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetBool(const char pre[],const char name[],PetscBool *ivalue,PetscBool *set) 1426 { 1427 char *value; 1428 PetscBool flag; 1429 PetscErrorCode ierr; 1430 1431 PetscFunctionBegin; 1432 PetscValidCharPointer(name,2); 1433 PetscValidIntPointer(ivalue,3); 1434 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1435 if (flag) { 1436 if (set) *set = PETSC_TRUE; 1437 if (!value) { 1438 *ivalue = PETSC_TRUE; 1439 } else { 1440 ierr = PetscOptionsStringToBool(value, ivalue);CHKERRQ(ierr); 1441 } 1442 } else { 1443 if (set) *set = PETSC_FALSE; 1444 } 1445 PetscFunctionReturn(0); 1446 } 1447 1448 #undef __FUNCT__ 1449 #define __FUNCT__ "PetscOptionsGetBoolArray" 1450 /*@C 1451 PetscOptionsGetBoolArray - Gets an array of Logical (true or false) values for a particular 1452 option in the database. The values must be separated with commas with 1453 no intervening spaces. 1454 1455 Not Collective 1456 1457 Input Parameters: 1458 + pre - string to prepend to each name or PETSC_NULL 1459 . name - the option one is seeking 1460 - nmax - maximum number of values to retrieve 1461 1462 Output Parameter: 1463 + dvalue - the integer values to return 1464 . nmax - actual number of values retreived 1465 - set - PETSC_TRUE if found, else PETSC_FALSE 1466 1467 Level: beginner 1468 1469 Concepts: options database^array of ints 1470 1471 Notes: 1472 TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE 1473 FALSE, false, NO, no, and 0 all translate to PETSC_FALSE 1474 1475 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1476 PetscOptionsGetString(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1477 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1478 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1479 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1480 PetscOptionsList(), PetscOptionsEList() 1481 @*/ 1482 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetBoolArray(const char pre[],const char name[],PetscBool dvalue[],PetscInt *nmax,PetscBool *set) 1483 { 1484 char *value; 1485 PetscErrorCode ierr; 1486 PetscInt n = 0; 1487 PetscBool flag; 1488 PetscToken token; 1489 1490 PetscFunctionBegin; 1491 PetscValidCharPointer(name,2); 1492 PetscValidIntPointer(dvalue,3); 1493 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1494 if (!flag) {if (set) *set = PETSC_FALSE; *nmax = 0; PetscFunctionReturn(0);} 1495 if (!value) {if (set) *set = PETSC_TRUE; *nmax = 0; PetscFunctionReturn(0);} 1496 1497 if (set) *set = PETSC_TRUE; 1498 1499 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1500 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1501 while (n < *nmax) { 1502 if (!value) break; 1503 ierr = PetscOptionsStringToBool(value,dvalue);CHKERRQ(ierr); 1504 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1505 dvalue++; 1506 n++; 1507 } 1508 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1509 *nmax = n; 1510 PetscFunctionReturn(0); 1511 } 1512 1513 #undef __FUNCT__ 1514 #define __FUNCT__ "PetscOptionsGetReal" 1515 /*@C 1516 PetscOptionsGetReal - Gets the double precision value for a particular 1517 option in the database. 1518 1519 Not Collective 1520 1521 Input Parameters: 1522 + pre - string to prepend to each name or PETSC_NULL 1523 - name - the option one is seeking 1524 1525 Output Parameter: 1526 + dvalue - the double value to return 1527 - set - PETSC_TRUE if found, PETSC_FALSE if not found 1528 1529 Level: beginner 1530 1531 Concepts: options database^has double 1532 1533 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1534 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(),PetscOptionsBool(), 1535 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1536 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1537 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1538 PetscOptionsList(), PetscOptionsEList() 1539 @*/ 1540 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetReal(const char pre[],const char name[],PetscReal *dvalue,PetscBool *set) 1541 { 1542 char *value; 1543 PetscErrorCode ierr; 1544 PetscBool flag; 1545 1546 PetscFunctionBegin; 1547 PetscValidCharPointer(name,2); 1548 PetscValidDoublePointer(dvalue,3); 1549 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1550 if (flag) { 1551 if (!value) {if (set) *set = PETSC_FALSE;} 1552 else {if (set) *set = PETSC_TRUE; ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);} 1553 } else { 1554 if (set) *set = PETSC_FALSE; 1555 } 1556 PetscFunctionReturn(0); 1557 } 1558 1559 #undef __FUNCT__ 1560 #define __FUNCT__ "PetscOptionsGetScalar" 1561 /*@C 1562 PetscOptionsGetScalar - Gets the scalar value for a particular 1563 option in the database. 1564 1565 Not Collective 1566 1567 Input Parameters: 1568 + pre - string to prepend to each name or PETSC_NULL 1569 - name - the option one is seeking 1570 1571 Output Parameter: 1572 + dvalue - the double value to return 1573 - set - PETSC_TRUE if found, else PETSC_FALSE 1574 1575 Level: beginner 1576 1577 Usage: 1578 A complex number 2+3i can be specified as 2,3 at the command line. 1579 or a number 2.0e-10 - 3.3e-20 i can be specified as 2.0e-10,3.3e-20 1580 1581 Concepts: options database^has scalar 1582 1583 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1584 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1585 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1586 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1587 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1588 PetscOptionsList(), PetscOptionsEList() 1589 @*/ 1590 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetScalar(const char pre[],const char name[],PetscScalar *dvalue,PetscBool *set) 1591 { 1592 char *value; 1593 PetscBool flag; 1594 PetscErrorCode ierr; 1595 1596 PetscFunctionBegin; 1597 PetscValidCharPointer(name,2); 1598 PetscValidScalarPointer(dvalue,3); 1599 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1600 if (flag) { 1601 if (!value) { 1602 if (set) *set = PETSC_FALSE; 1603 } else { 1604 #if !defined(PETSC_USE_COMPLEX) 1605 ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr); 1606 #else 1607 PetscReal re=0.0,im=0.0; 1608 PetscToken token; 1609 char *tvalue = 0; 1610 1611 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1612 ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr); 1613 if (!tvalue) { SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"unknown string specified\n"); } 1614 ierr = PetscOptionsStringToReal(tvalue,&re);CHKERRQ(ierr); 1615 ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr); 1616 if (!tvalue) { /* Unknown separator used. using only real value */ 1617 *dvalue = re; 1618 } else { 1619 ierr = PetscOptionsStringToReal(tvalue,&im);CHKERRQ(ierr); 1620 *dvalue = re + PETSC_i*im; 1621 } 1622 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1623 #endif 1624 if (set) *set = PETSC_TRUE; 1625 } 1626 } else { /* flag */ 1627 if (set) *set = PETSC_FALSE; 1628 } 1629 PetscFunctionReturn(0); 1630 } 1631 1632 #undef __FUNCT__ 1633 #define __FUNCT__ "PetscOptionsGetRealArray" 1634 /*@C 1635 PetscOptionsGetRealArray - Gets an array of double precision values for a 1636 particular option in the database. The values must be separated with 1637 commas with no intervening spaces. 1638 1639 Not Collective 1640 1641 Input Parameters: 1642 + pre - string to prepend to each name or PETSC_NULL 1643 . name - the option one is seeking 1644 - nmax - maximum number of values to retrieve 1645 1646 Output Parameters: 1647 + dvalue - the double value to return 1648 . nmax - actual number of values retreived 1649 - set - PETSC_TRUE if found, else PETSC_FALSE 1650 1651 Level: beginner 1652 1653 Concepts: options database^array of doubles 1654 1655 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1656 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsBool(), 1657 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1658 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1659 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1660 PetscOptionsList(), PetscOptionsEList() 1661 @*/ 1662 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetRealArray(const char pre[],const char name[],PetscReal dvalue[],PetscInt *nmax,PetscBool *set) 1663 { 1664 char *value; 1665 PetscErrorCode ierr; 1666 PetscInt n = 0; 1667 PetscBool flag; 1668 PetscToken token; 1669 1670 PetscFunctionBegin; 1671 PetscValidCharPointer(name,2); 1672 PetscValidDoublePointer(dvalue,3); 1673 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1674 if (!flag) {if (set) *set = PETSC_FALSE; *nmax = 0; PetscFunctionReturn(0);} 1675 if (!value) {if (set) *set = PETSC_TRUE; *nmax = 0; PetscFunctionReturn(0);} 1676 1677 if (set) *set = PETSC_TRUE; 1678 1679 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1680 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1681 while (n < *nmax) { 1682 if (!value) break; 1683 ierr = PetscOptionsStringToReal(value,dvalue++);CHKERRQ(ierr); 1684 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1685 n++; 1686 } 1687 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1688 *nmax = n; 1689 PetscFunctionReturn(0); 1690 } 1691 1692 #undef __FUNCT__ 1693 #define __FUNCT__ "PetscOptionsGetIntArray" 1694 /*@C 1695 PetscOptionsGetIntArray - Gets an array of integer values for a particular 1696 option in the database. The values must be separated with commas with 1697 no intervening spaces. 1698 1699 Not Collective 1700 1701 Input Parameters: 1702 + pre - string to prepend to each name or PETSC_NULL 1703 . name - the option one is seeking 1704 - nmax - maximum number of values to retrieve, can include d-D to indicate d,d+1,..,D-1 1705 1706 Output Parameter: 1707 + dvalue - the integer values to return 1708 . nmax - actual number of values retreived 1709 - set - PETSC_TRUE if found, else PETSC_FALSE 1710 1711 Level: beginner 1712 1713 Concepts: options database^array of ints 1714 1715 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1716 PetscOptionsGetString(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1717 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1718 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1719 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1720 PetscOptionsList(), PetscOptionsEList() 1721 @*/ 1722 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetIntArray(const char pre[],const char name[],PetscInt dvalue[],PetscInt *nmax,PetscBool *set) 1723 { 1724 char *value; 1725 PetscErrorCode ierr; 1726 PetscInt n = 0,i,start,end; 1727 size_t len; 1728 PetscBool flag,foundrange; 1729 PetscToken token; 1730 1731 PetscFunctionBegin; 1732 PetscValidCharPointer(name,2); 1733 PetscValidIntPointer(dvalue,3); 1734 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1735 if (!flag) {if (set) *set = PETSC_FALSE; *nmax = 0; PetscFunctionReturn(0);} 1736 if (!value) {if (set) *set = PETSC_TRUE; *nmax = 0; PetscFunctionReturn(0);} 1737 1738 if (set) *set = PETSC_TRUE; 1739 1740 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1741 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1742 while (n < *nmax) { 1743 if (!value) break; 1744 1745 /* look for form d-D where d and D are integers */ 1746 foundrange = PETSC_FALSE; 1747 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 1748 if (value[0] == '-') i=2; 1749 else i=1; 1750 for (;i<(int)len; i++) { 1751 if (value[i] == '-') { 1752 if (i == (int)len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value); 1753 value[i] = 0; 1754 ierr = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr); 1755 ierr = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr); 1756 if (end <= start) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry, %s-%s cannot have decreasing list",n,value,value+i+1); 1757 if (n + end - start - 1 >= *nmax) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry, not enough space in left in array (%D) to contain entire range from %D to %D",n,*nmax-n,start,end); 1758 for (;start<end; start++) { 1759 *dvalue = start; dvalue++;n++; 1760 } 1761 foundrange = PETSC_TRUE; 1762 break; 1763 } 1764 } 1765 if (!foundrange) { 1766 ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr); 1767 dvalue++; 1768 n++; 1769 } 1770 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1771 } 1772 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1773 *nmax = n; 1774 PetscFunctionReturn(0); 1775 } 1776 1777 #undef __FUNCT__ 1778 #define __FUNCT__ "PetscOptionsGetString" 1779 /*@C 1780 PetscOptionsGetString - Gets the string value for a particular option in 1781 the database. 1782 1783 Not Collective 1784 1785 Input Parameters: 1786 + pre - string to prepend to name or PETSC_NULL 1787 . name - the option one is seeking 1788 - len - maximum length of the string including null termination 1789 1790 Output Parameters: 1791 + string - location to copy string 1792 - set - PETSC_TRUE if found, else PETSC_FALSE 1793 1794 Level: beginner 1795 1796 Fortran Note: 1797 The Fortran interface is slightly different from the C/C++ 1798 interface (len is not used). Sample usage in Fortran follows 1799 .vb 1800 character *20 string 1801 integer flg, ierr 1802 call PetscOptionsGetString(PETSC_NULL_CHARACTER,'-s',string,flg,ierr) 1803 .ve 1804 1805 Concepts: options database^string 1806 1807 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1808 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1809 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1810 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1811 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1812 PetscOptionsList(), PetscOptionsEList() 1813 @*/ 1814 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetString(const char pre[],const char name[],char string[],size_t len,PetscBool *set) 1815 { 1816 char *value; 1817 PetscErrorCode ierr; 1818 PetscBool flag; 1819 1820 PetscFunctionBegin; 1821 PetscValidCharPointer(name,2); 1822 PetscValidCharPointer(string,3); 1823 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1824 if (!flag) { 1825 if (set) *set = PETSC_FALSE; 1826 } else { 1827 if (set) *set = PETSC_TRUE; 1828 if (value) { 1829 ierr = PetscStrncpy(string,value,len);CHKERRQ(ierr); 1830 string[len-1] = 0; /* Ensure that the string is NULL terminated */ 1831 } else { 1832 ierr = PetscMemzero(string,len);CHKERRQ(ierr); 1833 } 1834 } 1835 PetscFunctionReturn(0); 1836 } 1837 1838 #undef __FUNCT__ 1839 #define __FUNCT__ "PetscOptionsGetStringArray" 1840 /*@C 1841 PetscOptionsGetStringArray - Gets an array of string values for a particular 1842 option in the database. The values must be separated with commas with 1843 no intervening spaces. 1844 1845 Not Collective 1846 1847 Input Parameters: 1848 + pre - string to prepend to name or PETSC_NULL 1849 . name - the option one is seeking 1850 - nmax - maximum number of strings 1851 1852 Output Parameter: 1853 + strings - location to copy strings 1854 - set - PETSC_TRUE if found, else PETSC_FALSE 1855 1856 Level: beginner 1857 1858 Notes: 1859 The user should pass in an array of pointers to char, to hold all the 1860 strings returned by this function. 1861 1862 The user is responsible for deallocating the strings that are 1863 returned. The Fortran interface for this routine is not supported. 1864 1865 Contributed by Matthew Knepley. 1866 1867 Concepts: options database^array of strings 1868 1869 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1870 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), 1871 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1872 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1873 PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 1874 PetscOptionsList(), PetscOptionsEList() 1875 @*/ 1876 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsGetStringArray(const char pre[],const char name[],char *strings[],PetscInt *nmax,PetscBool *set) 1877 { 1878 char *value; 1879 PetscErrorCode ierr; 1880 PetscInt n; 1881 PetscBool flag; 1882 PetscToken token; 1883 1884 PetscFunctionBegin; 1885 PetscValidCharPointer(name,2); 1886 PetscValidPointer(strings,3); 1887 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1888 if (!flag) {*nmax = 0; if (set) *set = PETSC_FALSE; PetscFunctionReturn(0);} 1889 if (!value) {*nmax = 0; if (set) *set = PETSC_FALSE;PetscFunctionReturn(0);} 1890 if (!*nmax) {if (set) *set = PETSC_FALSE;PetscFunctionReturn(0);} 1891 if (set) *set = PETSC_TRUE; 1892 1893 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1894 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1895 n = 0; 1896 while (n < *nmax) { 1897 if (!value) break; 1898 ierr = PetscStrallocpy(value,&strings[n]);CHKERRQ(ierr); 1899 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1900 n++; 1901 } 1902 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1903 *nmax = n; 1904 PetscFunctionReturn(0); 1905 } 1906 1907 #undef __FUNCT__ 1908 #define __FUNCT__ "PetscOptionsAllUsed" 1909 /*@C 1910 PetscOptionsAllUsed - Returns a count of the number of options in the 1911 database that have never been selected. 1912 1913 Not Collective 1914 1915 Output Parameter: 1916 . N - count of options not used 1917 1918 Level: advanced 1919 1920 .seealso: PetscOptionsPrint() 1921 @*/ 1922 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsAllUsed(int *N) 1923 { 1924 PetscInt i,n = 0; 1925 1926 PetscFunctionBegin; 1927 for (i=0; i<options->N; i++) { 1928 if (!options->used[i]) { n++; } 1929 } 1930 *N = n; 1931 PetscFunctionReturn(0); 1932 } 1933 1934 #undef __FUNCT__ 1935 #define __FUNCT__ "PetscOptionsLeft" 1936 /*@ 1937 PetscOptionsLeft - Prints to screen any options that were set and never used. 1938 1939 Not collective 1940 1941 Options Database Key: 1942 . -options_left - Activates OptionsAllUsed() within PetscFinalize() 1943 1944 Level: advanced 1945 1946 .seealso: PetscOptionsAllUsed() 1947 @*/ 1948 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsLeft(void) 1949 { 1950 PetscErrorCode ierr; 1951 PetscInt i; 1952 1953 PetscFunctionBegin; 1954 for (i=0; i<options->N; i++) { 1955 if (!options->used[i]) { 1956 if (options->values[i]) { 1957 ierr = PetscPrintf(PETSC_COMM_WORLD,"Option left: name:-%s value: %s\n",options->names[i],options->values[i]);CHKERRQ(ierr); 1958 } else { 1959 ierr = PetscPrintf(PETSC_COMM_WORLD,"Option left: name:-%s no value \n",options->names[i]);CHKERRQ(ierr); 1960 } 1961 } 1962 } 1963 PetscFunctionReturn(0); 1964 } 1965 1966 1967 #undef __FUNCT__ 1968 #define __FUNCT__ "PetscOptionsCreate" 1969 /* 1970 PetscOptionsCreate - Creates the empty options database. 1971 1972 */ 1973 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsCreate(void) 1974 { 1975 PetscErrorCode ierr; 1976 1977 PetscFunctionBegin; 1978 options = (PetscOptionsTable*)malloc(sizeof(PetscOptionsTable)); 1979 ierr = PetscMemzero(options,sizeof(PetscOptionsTable));CHKERRQ(ierr); 1980 options->namegiven = PETSC_FALSE; 1981 options->N = 0; 1982 options->Naliases = 0; 1983 options->numbermonitors = 0; 1984 1985 PetscOptionsObject.prefix = PETSC_NULL; 1986 PetscOptionsObject.title = PETSC_NULL; 1987 1988 PetscFunctionReturn(0); 1989 } 1990 1991 #undef __FUNCT__ 1992 #define __FUNCT__ "PetscOptionsSetFromOptions" 1993 /*@ 1994 PetscOptionsSetFromOptions - Sets various SNES and KSP parameters from user options. 1995 1996 Collective on PETSC_COMM_WORLD 1997 1998 Options Database Keys: 1999 + -options_monitor <optional filename> - prints the names and values of all runtime options as they are set. The monitor functionality is not 2000 available for options set through a file, environment variable, or on 2001 the command line. Only options set after PetscInitialize completes will 2002 be monitored. 2003 . -options_monitor_cancel - cancel all options database monitors 2004 2005 Notes: 2006 To see all options, run your program with the -help option or consult 2007 the <A href="../../docs/manual.pdf">users manual</A>.. 2008 2009 Level: intermediate 2010 2011 .keywords: set, options, database 2012 @*/ 2013 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsSetFromOptions(void) 2014 { 2015 PetscBool flgc,flgm; 2016 PetscErrorCode ierr; 2017 char monfilename[PETSC_MAX_PATH_LEN]; 2018 PetscViewer monviewer; 2019 2020 PetscFunctionBegin; 2021 ierr = PetscOptionsBegin(PETSC_COMM_WORLD,"","Options database options","PetscOptions");CHKERRQ(ierr); 2022 ierr = PetscOptionsString("-options_monitor","Monitor options database","PetscOptionsMonitorSet","stdout",monfilename,PETSC_MAX_PATH_LEN,&flgm);CHKERRQ(ierr); 2023 ierr = PetscOptionsBool("-options_monitor_cancel","Cancel all options database monitors","PetscOptionsMonitorCancel",PETSC_FALSE,&flgc,PETSC_NULL);CHKERRQ(ierr); 2024 ierr = PetscOptionsEnd();CHKERRQ(ierr); 2025 if (flgm) { 2026 ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,monfilename,&monviewer);CHKERRQ(ierr); 2027 ierr = PetscOptionsMonitorSet(PetscOptionsMonitorDefault,monviewer,(PetscErrorCode (*)(void*))PetscViewerDestroy);CHKERRQ(ierr); 2028 } 2029 if (flgc) { ierr = PetscOptionsMonitorCancel();CHKERRQ(ierr); } 2030 PetscFunctionReturn(0); 2031 } 2032 2033 2034 #undef __FUNCT__ 2035 #define __FUNCT__ "PetscOptionsMonitorDefault" 2036 /*@C 2037 PetscOptionsMonitorDefault - Print all options set value events. 2038 2039 Logically Collective on PETSC_COMM_WORLD 2040 2041 Input Parameters: 2042 + name - option name string 2043 . value - option value string 2044 - dummy - unused monitor context 2045 2046 Level: intermediate 2047 2048 .keywords: PetscOptions, default, monitor 2049 2050 .seealso: PetscOptionsMonitorSet() 2051 @*/ 2052 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsMonitorDefault(const char name[], const char value[], void *dummy) 2053 { 2054 PetscErrorCode ierr; 2055 PetscViewer viewer = (PetscViewer) dummy; 2056 2057 PetscFunctionBegin; 2058 if (!viewer) { 2059 ierr = PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&viewer);CHKERRQ(ierr); 2060 } 2061 ierr = PetscViewerASCIIPrintf(viewer,"Setting option: %s = %s\n",name,value);CHKERRQ(ierr); 2062 PetscFunctionReturn(0); 2063 } 2064 2065 #undef __FUNCT__ 2066 #define __FUNCT__ "PetscOptionsMonitorSet" 2067 /*@C 2068 PetscOptionsMonitorSet - Sets an ADDITIONAL function to be called at every method that 2069 modified the PETSc options database. 2070 2071 Not collective 2072 2073 Input Parameters: 2074 + monitor - pointer to function (if this is PETSC_NULL, it turns off monitoring 2075 . mctx - [optional] context for private data for the 2076 monitor routine (use PETSC_NULL if no context is desired) 2077 - monitordestroy - [optional] routine that frees monitor context 2078 (may be PETSC_NULL) 2079 2080 Calling Sequence of monitor: 2081 $ monitor (const char name[], const char value[], void *mctx) 2082 2083 + name - option name string 2084 . value - option value string 2085 - mctx - optional monitoring context, as set by PetscOptionsMonitorSet() 2086 2087 Options Database Keys: 2088 + -options_monitor - sets PetscOptionsMonitorDefault() 2089 - -options_monitor_cancel - cancels all monitors that have 2090 been hardwired into a code by 2091 calls to PetscOptionsMonitorSet(), but 2092 does not cancel those set via 2093 the options database. 2094 2095 Notes: 2096 The default is to do nothing. To print the name and value of options 2097 being inserted into the database, use PetscOptionsMonitorDefault() as the monitoring routine, 2098 with a null monitoring context. 2099 2100 Several different monitoring routines may be set by calling 2101 PetscOptionsMonitorSet() multiple times; all will be called in the 2102 order in which they were set. 2103 2104 Level: beginner 2105 2106 .keywords: PetscOptions, set, monitor 2107 2108 .seealso: PetscOptionsMonitorDefault(), PetscOptionsMonitorCancel() 2109 @*/ 2110 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsMonitorSet(PetscErrorCode (*monitor)(const char name[], const char value[], void*),void *mctx,PetscErrorCode (*monitordestroy)(void*)) 2111 { 2112 PetscFunctionBegin; 2113 if (options->numbermonitors >= MAXOPTIONSMONITORS) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many PetscOptions monitors set"); 2114 options->monitor[options->numbermonitors] = monitor; 2115 options->monitordestroy[options->numbermonitors] = monitordestroy; 2116 options->monitorcontext[options->numbermonitors++] = (void*)mctx; 2117 PetscFunctionReturn(0); 2118 } 2119 2120 #undef __FUNCT__ 2121 #define __FUNCT__ "PetscOptionsMonitorCancel" 2122 /*@ 2123 PetscOptionsMonitorCancel - Clears all monitors for a PetscOptions object. 2124 2125 Not collective 2126 2127 Options Database Key: 2128 . -options_monitor_cancel - Cancels all monitors that have 2129 been hardwired into a code by calls to PetscOptionsMonitorSet(), 2130 but does not cancel those set via the options database. 2131 2132 Level: intermediate 2133 2134 .keywords: PetscOptions, set, monitor 2135 2136 .seealso: PetscOptionsMonitorDefault(), PetscOptionsMonitorSet() 2137 @*/ 2138 PetscErrorCode PETSCSYS_DLLEXPORT PetscOptionsMonitorCancel(void) 2139 { 2140 PetscErrorCode ierr; 2141 PetscInt i; 2142 2143 PetscFunctionBegin; 2144 for (i=0; i<options->numbermonitors; i++) { 2145 if (options->monitordestroy[i]) { 2146 ierr = (*options->monitordestroy[i])(options->monitorcontext[i]);CHKERRQ(ierr); 2147 } 2148 } 2149 options->numbermonitors = 0; 2150 PetscFunctionReturn(0); 2151 } 2152