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