1 #define PETSC_DLL 2 /* 3 These routines simplify the use of command line, file options, etc., 4 and are used to manipulate the options database. 5 6 This file uses regular malloc and free because it cannot know 7 what malloc is being used until it has already processed the input. 8 */ 9 10 #include "petsc.h" /*I "petsc.h" I*/ 11 #include "petscsys.h" 12 #if defined(PETSC_HAVE_STDLIB_H) 13 #include <stdlib.h> 14 #endif 15 #if defined(PETSC_HAVE_MALLOC_H) 16 #include <malloc.h> 17 #endif 18 #if defined(PETSC_HAVE_SYS_PARAM_H) 19 #include "sys/param.h" 20 #endif 21 #include "petscfix.h" 22 23 /* 24 For simplicity, we use a static size database 25 */ 26 #define MAXOPTIONS 512 27 #define MAXALIASES 25 28 #define MAXOPTIONSMONITORS 5 29 30 typedef struct { 31 int N,argc,Naliases; 32 char **args,*names[MAXOPTIONS],*values[MAXOPTIONS]; 33 char *aliases1[MAXALIASES],*aliases2[MAXALIASES]; 34 PetscTruth used[MAXOPTIONS]; 35 PetscTruth namegiven; 36 char programname[PETSC_MAX_PATH_LEN]; /* HP includes entire path in name */ 37 38 /* --------User (or default) routines (most return -1 on error) --------*/ 39 PetscErrorCode (*monitor[MAXOPTIONSMONITORS])(const char[], const char[], void*); /* returns control to user after */ 40 PetscErrorCode (*monitordestroy[MAXOPTIONSMONITORS])(void*); /* */ 41 void *monitorcontext[MAXOPTIONSMONITORS]; /* to pass arbitrary user data into monitor */ 42 PetscInt numbermonitors; /* to, for instance, detect options being set */ 43 44 } PetscOptionsTable; 45 46 47 static PetscOptionsTable *options = 0; 48 49 /* 50 Options events monitor 51 */ 52 #define PetscOptionsMonitor(name,value) \ 53 { PetscErrorCode _ierr; PetscInt _i,_im = options->numbermonitors; \ 54 for (_i=0; _i<_im; _i++) {\ 55 _ierr = (*options->monitor[_i])(name, value, options->monitorcontext[_i]);CHKERRQ(_ierr); \ 56 } \ 57 } 58 59 #undef __FUNCT__ 60 #define __FUNCT__ "PetscOptionsAtoi" 61 PetscErrorCode PETSC_DLLEXPORT PetscOptionsAtoi(const char name[],PetscInt *a) 62 { 63 PetscErrorCode ierr; 64 size_t i,len; 65 PetscTruth decide,tdefault,mouse; 66 67 PetscFunctionBegin; 68 ierr = PetscStrlen(name,&len);CHKERRQ(ierr); 69 if (!len) SETERRQ(PETSC_ERR_ARG_WRONG,"character string of length zero has no numerical value"); 70 71 ierr = PetscStrcasecmp(name,"PETSC_DEFAULT",&tdefault);CHKERRQ(ierr); 72 if (!tdefault) { 73 ierr = PetscStrcasecmp(name,"DEFAULT",&tdefault);CHKERRQ(ierr); 74 } 75 ierr = PetscStrcasecmp(name,"PETSC_DECIDE",&decide);CHKERRQ(ierr); 76 if (!decide) { 77 ierr = PetscStrcasecmp(name,"DECIDE",&decide);CHKERRQ(ierr); 78 } 79 ierr = PetscStrcasecmp(name,"mouse",&mouse);CHKERRQ(ierr); 80 81 if (tdefault) { 82 *a = PETSC_DEFAULT; 83 } else if (decide) { 84 *a = PETSC_DECIDE; 85 } else if (mouse) { 86 *a = -1; 87 } else { 88 if (name[0] != '+' && name[0] != '-' && name[0] < '0' && name[0] > '9') { 89 SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no integer value (do not include . in it)",name); 90 } 91 for (i=1; i<len; i++) { 92 if (name[i] < '0' || name[i] > '9') { 93 SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no integer value (do not include . in it)",name); 94 } 95 } 96 *a = atoi(name); 97 } 98 PetscFunctionReturn(0); 99 } 100 101 #undef __FUNCT__ 102 #define __FUNCT__ "PetscOptionsAtod" 103 PetscErrorCode PETSC_DLLEXPORT PetscOptionsAtod(const char name[],PetscReal *a) 104 { 105 PetscErrorCode ierr; 106 size_t len; 107 PetscTruth decide,tdefault; 108 109 PetscFunctionBegin; 110 ierr = PetscStrlen(name,&len);CHKERRQ(ierr); 111 if (!len) SETERRQ(PETSC_ERR_ARG_WRONG,"character string of length zero has no numerical value"); 112 113 ierr = PetscStrcasecmp(name,"PETSC_DEFAULT",&tdefault);CHKERRQ(ierr); 114 if (!tdefault) { 115 ierr = PetscStrcasecmp(name,"DEFAULT",&tdefault);CHKERRQ(ierr); 116 } 117 ierr = PetscStrcasecmp(name,"PETSC_DECIDE",&decide);CHKERRQ(ierr); 118 if (!decide) { 119 ierr = PetscStrcasecmp(name,"DECIDE",&decide);CHKERRQ(ierr); 120 } 121 122 if (tdefault) { 123 *a = PETSC_DEFAULT; 124 } else if (decide) { 125 *a = PETSC_DECIDE; 126 } else { 127 if (name[0] != '+' && name[0] != '-' && name[0] != '.' && name[0] < '0' && name[0] > '9') { 128 SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no numeric value ",name); 129 } 130 *a = atof(name); 131 } 132 PetscFunctionReturn(0); 133 } 134 135 #undef __FUNCT__ 136 #define __FUNCT__ "PetscGetProgramName" 137 /*@C 138 PetscGetProgramName - Gets the name of the running program. 139 140 Not Collective 141 142 Input Parameter: 143 . len - length of the string name 144 145 Output Parameter: 146 . name - the name of the running program 147 148 Level: advanced 149 150 Notes: 151 The name of the program is copied into the user-provided character 152 array of length len. On some machines the program name includes 153 its entire path, so one should generally set len >= PETSC_MAX_PATH_LEN. 154 @*/ 155 PetscErrorCode PETSC_DLLEXPORT PetscGetProgramName(char name[],size_t len) 156 { 157 PetscErrorCode ierr; 158 159 PetscFunctionBegin; 160 if (!options) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call PetscInitialize() first"); 161 if (!options->namegiven) SETERRQ(PETSC_ERR_PLIB,"Unable to determine program name"); 162 ierr = PetscStrncpy(name,options->programname,len);CHKERRQ(ierr); 163 PetscFunctionReturn(0); 164 } 165 166 #undef __FUNCT__ 167 #define __FUNCT__ "PetscSetProgramName" 168 PetscErrorCode PETSC_DLLEXPORT PetscSetProgramName(const char name[]) 169 { 170 PetscErrorCode ierr; 171 172 PetscFunctionBegin; 173 options->namegiven = PETSC_TRUE; 174 ierr = PetscStrncpy(options->programname,name,PETSC_MAX_PATH_LEN);CHKERRQ(ierr); 175 PetscFunctionReturn(0); 176 } 177 178 #undef __FUNCT__ 179 #define __FUNCT__ "PetscOptionsInsertString" 180 /*@C 181 PetscOptionsInsertString - Inserts options into the database from a string 182 183 Not collective: but only processes that call this routine will set the options 184 included in the file 185 186 Input Parameter: 187 . in_str - string that contains options separated by blanks 188 189 190 Level: intermediate 191 192 Contributed by Boyana Norris 193 194 .seealso: PetscOptionsSetValue(), PetscOptionsPrint(), PetscOptionsHasName(), PetscOptionsGetInt(), 195 PetscOptionsGetReal(), PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsTruth(), 196 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 197 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 198 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 199 PetscOptionsList(), PetscOptionsEList(), PetscOptionsInsertFile() 200 201 @*/ 202 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInsertString(const char in_str[]) 203 { 204 char *str,*first,*second,*third,*final; 205 size_t len; 206 PetscErrorCode ierr; 207 PetscToken *token; 208 209 PetscFunctionBegin; 210 ierr = PetscStrallocpy(in_str, &str);CHKERRQ(ierr); 211 ierr = PetscTokenCreate(str,' ',&token);CHKERRQ(ierr); 212 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 213 ierr = PetscTokenFind(token,&second);CHKERRQ(ierr); 214 if (first && first[0] == '-') { 215 if (second) {final = second;} else {final = first;} 216 ierr = PetscStrlen(final,&len);CHKERRQ(ierr); 217 while (len > 0 && (final[len-1] == ' ' || final[len-1] == 'n')) { 218 len--; final[len] = 0; 219 } 220 ierr = PetscOptionsSetValue(first,second);CHKERRQ(ierr); 221 } else if (first) { 222 PetscTruth match; 223 224 ierr = PetscStrcasecmp(first,"alias",&match);CHKERRQ(ierr); 225 if (match) { 226 ierr = PetscTokenFind(token,&third);CHKERRQ(ierr); 227 if (!third) SETERRQ1(PETSC_ERR_ARG_WRONG,"Error in options string:alias missing (%s)",second); 228 ierr = PetscStrlen(third,&len);CHKERRQ(ierr); 229 if (third[len-1] == 'n') third[len-1] = 0; 230 ierr = PetscOptionsSetAlias(second,third);CHKERRQ(ierr); 231 } 232 } 233 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 234 ierr = PetscFree(str);CHKERRQ(ierr); 235 236 PetscFunctionReturn(0); 237 } 238 239 #undef __FUNCT__ 240 #define __FUNCT__ "PetscOptionsInsertFile" 241 /*@C 242 PetscOptionsInsertFile - Inserts options into the database from a file. 243 244 Not collective: but only processes that call this routine will set the options 245 included in the file 246 247 Input Parameter: 248 . file - name of file 249 250 251 Level: intermediate 252 253 .seealso: PetscOptionsSetValue(), PetscOptionsPrint(), PetscOptionsHasName(), PetscOptionsGetInt(), 254 PetscOptionsGetReal(), PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsTruth(), 255 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 256 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 257 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 258 PetscOptionsList(), PetscOptionsEList() 259 260 @*/ 261 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInsertFile(const char file[]) 262 { 263 char string[PETSC_MAX_PATH_LEN],fname[PETSC_MAX_PATH_LEN],*first,*second,*third,*final; 264 PetscErrorCode ierr; 265 size_t i,len,startIndex; 266 FILE *fd; 267 PetscToken *token; 268 269 PetscFunctionBegin; 270 ierr = PetscFixFilename(file,fname);CHKERRQ(ierr); 271 fd = fopen(fname,"r"); 272 if (fd) { 273 while (fgets(string,128,fd)) { 274 /* Comments are indicated by #, ! or % in the first column */ 275 if (string[0] == '#') continue; 276 if (string[0] == '!') continue; 277 if (string[0] == '%') continue; 278 279 ierr = PetscStrlen(string,&len);CHKERRQ(ierr); 280 281 /* replace tabs, ^M with " " */ 282 for (i=0; i<len; i++) { 283 if (string[i] == '\t' || string[i] == '\r') { 284 string[i] = ' '; 285 } 286 } 287 for(startIndex = 0; startIndex < len-1; startIndex++) { 288 if (string[startIndex] != ' ') break; 289 } 290 ierr = PetscTokenCreate(&string[startIndex],' ',&token);CHKERRQ(ierr); 291 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 292 ierr = PetscTokenFind(token,&second);CHKERRQ(ierr); 293 if (first && first[0] == '-') { 294 if (second) {final = second;} else {final = first;} 295 ierr = PetscStrlen(final,&len);CHKERRQ(ierr); 296 while (len > 0 && (final[len-1] == ' ' || final[len-1] == '\n')) { 297 len--; final[len] = 0; 298 } 299 ierr = PetscOptionsSetValue(first,second);CHKERRQ(ierr); 300 } else if (first) { 301 PetscTruth match; 302 303 ierr = PetscStrcasecmp(first,"alias",&match);CHKERRQ(ierr); 304 if (match) { 305 ierr = PetscTokenFind(token,&third);CHKERRQ(ierr); 306 if (!third) SETERRQ1(PETSC_ERR_ARG_WRONG,"Error in options file:alias missing (%s)",second); 307 ierr = PetscStrlen(third,&len);CHKERRQ(ierr); 308 if (third[len-1] == '\n') third[len-1] = 0; 309 ierr = PetscOptionsSetAlias(second,third);CHKERRQ(ierr); 310 } 311 } 312 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 313 } 314 fclose(fd); 315 } else { 316 SETERRQ1(PETSC_ERR_USER,"Unable to open Options File %s",fname); 317 } 318 PetscFunctionReturn(0); 319 } 320 321 #undef __FUNCT__ 322 #define __FUNCT__ "PetscOptionsInsert" 323 /*@C 324 PetscOptionsInsert - Inserts into the options database from the command line, 325 the environmental variable and a file. 326 327 Input Parameters: 328 + argc - count of number of command line arguments 329 . args - the command line arguments 330 - file - optional filename, defaults to ~username/.petscrc 331 332 Note: 333 Since PetscOptionsInsert() is automatically called by PetscInitialize(), 334 the user does not typically need to call this routine. PetscOptionsInsert() 335 can be called several times, adding additional entries into the database. 336 337 Options Database Keys: 338 + -options_monitor <optional filename> - print options names and values as they are set 339 340 Level: advanced 341 342 Concepts: options database^adding 343 344 .seealso: PetscOptionsDestroy_Private(), PetscOptionsPrint() 345 @*/ 346 PetscErrorCode PETSC_DLLEXPORT PetscOptionsInsert(int *argc,char ***args,const char file[]) 347 { 348 PetscErrorCode ierr; 349 PetscMPIInt rank; 350 char pfile[PETSC_MAX_PATH_LEN]; 351 PetscToken *token; 352 char monfilename[PETSC_MAX_PATH_LEN]; 353 PetscViewer monviewer; 354 PetscTruth flg; 355 356 PetscFunctionBegin; 357 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); 358 359 options->argc = (argc) ? *argc : 0; 360 options->args = (args) ? *args : 0; 361 362 if (file) { 363 ierr = PetscOptionsInsertFile(file);CHKERRQ(ierr); 364 } else { 365 ierr = PetscGetHomeDirectory(pfile,PETSC_MAX_PATH_LEN-16);CHKERRQ(ierr); 366 if (pfile[0]) { 367 PetscTruth flag; 368 ierr = PetscStrcat(pfile,"/.petscrc");CHKERRQ(ierr); 369 ierr = PetscTestFile(pfile,'r',&flag);CHKERRQ(ierr); 370 if (flag) { 371 ierr = PetscOptionsInsertFile(pfile);CHKERRQ(ierr); 372 } 373 } else { 374 ierr = PetscInfo(0,"Unable to determine home directory; skipping loading ~/.petscrc\n");CHKERRQ(ierr); 375 } 376 377 ierr = PetscOptionsName("-options_cancelmonitors","Remove any hardwired monitor routines","PetscOptionsClearMonitor",&flg);CHKERRQ(ierr); 378 /* -----------------------------------------------------------------------*/ 379 /* 380 Cancels all monitors hardwired into code before call to PetscOptionsInsert() 381 */ 382 if (flg) { 383 ierr = PetscOptionsClearMonitor();CHKERRQ(ierr); 384 } 385 386 /* 387 Prints the name and value of each option being set 388 */ 389 ierr = PetscOptionsString("-options_monitor","Monitor options database","PetscOptionsSetMonitor","stdout",monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); 390 if (flg && (!options->monitor)) { 391 ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,monfilename,&monviewer);CHKERRQ(ierr); 392 ierr = PetscOptionsSetMonitor(PetscOptionsDefaultMonitor,monviewer,(PetscErrorCode (*)(void*))PetscViewerDestroy);CHKERRQ(ierr); 393 } 394 395 } 396 397 /* insert environmental options */ 398 { 399 char *eoptions = 0,*second,*first; 400 size_t len = 0; 401 if (!rank) { 402 eoptions = (char*)getenv("PETSC_OPTIONS"); 403 ierr = PetscStrlen(eoptions,&len);CHKERRQ(ierr); 404 ierr = MPI_Bcast(&len,1,MPI_INT,0,PETSC_COMM_WORLD);CHKERRQ(ierr); 405 } else { 406 ierr = MPI_Bcast(&len,1,MPI_INT,0,PETSC_COMM_WORLD);CHKERRQ(ierr); 407 if (len) { 408 ierr = PetscMalloc((len+1)*sizeof(char*),&eoptions);CHKERRQ(ierr); 409 } 410 } 411 if (len) { 412 ierr = MPI_Bcast(eoptions,len,MPI_CHAR,0,PETSC_COMM_WORLD);CHKERRQ(ierr); 413 eoptions[len] = 0; 414 ierr = PetscTokenCreate(eoptions,' ',&token);CHKERRQ(ierr); 415 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 416 while (first) { 417 if (first[0] != '-') {ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); continue;} 418 ierr = PetscTokenFind(token,&second);CHKERRQ(ierr); 419 if ((!second) || ((second[0] == '-') && (second[1] > '9'))) { 420 ierr = PetscOptionsSetValue(first,(char *)0);CHKERRQ(ierr); 421 first = second; 422 } else { 423 ierr = PetscOptionsSetValue(first,second);CHKERRQ(ierr); 424 ierr = PetscTokenFind(token,&first);CHKERRQ(ierr); 425 } 426 } 427 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 428 if (rank) {ierr = PetscFree(eoptions);CHKERRQ(ierr);} 429 } 430 } 431 432 /* insert command line options */ 433 if (argc && args && *argc) { 434 int left = *argc - 1; 435 char **eargs = *args + 1; 436 PetscTruth isoptions_file,isp4,tisp4,isp4yourname,isp4rmrank; 437 438 while (left) { 439 ierr = PetscStrcasecmp(eargs[0],"-options_file",&isoptions_file);CHKERRQ(ierr); 440 ierr = PetscStrcasecmp(eargs[0],"-p4pg",&isp4);CHKERRQ(ierr); 441 ierr = PetscStrcasecmp(eargs[0],"-p4yourname",&isp4yourname);CHKERRQ(ierr); 442 ierr = PetscStrcasecmp(eargs[0],"-p4rmrank",&isp4rmrank);CHKERRQ(ierr); 443 ierr = PetscStrcasecmp(eargs[0],"-p4wd",&tisp4);CHKERRQ(ierr); 444 isp4 = (PetscTruth) (isp4 || tisp4); 445 ierr = PetscStrcasecmp(eargs[0],"-np",&tisp4);CHKERRQ(ierr); 446 isp4 = (PetscTruth) (isp4 || tisp4); 447 ierr = PetscStrcasecmp(eargs[0],"-p4amslave",&tisp4);CHKERRQ(ierr); 448 449 if (eargs[0][0] != '-') { 450 eargs++; left--; 451 } else if (isoptions_file) { 452 if (left <= 1) SETERRQ(PETSC_ERR_USER,"Missing filename for -options_file filename option"); 453 if (eargs[1][0] == '-') SETERRQ(PETSC_ERR_USER,"Missing filename for -options_file filename option"); 454 ierr = PetscOptionsInsertFile(eargs[1]);CHKERRQ(ierr); 455 eargs += 2; left -= 2; 456 457 /* 458 These are "bad" options that MPICH, etc put on the command line 459 we strip them out here. 460 */ 461 } else if (tisp4 || isp4rmrank) { 462 eargs += 1; left -= 1; 463 } else if (isp4 || isp4yourname) { 464 eargs += 2; left -= 2; 465 } else if ((left < 2) || ((eargs[1][0] == '-') && 466 ((eargs[1][1] > '9') || (eargs[1][1] < '0')))) { 467 ierr = PetscOptionsSetValue(eargs[0],PETSC_NULL);CHKERRQ(ierr); 468 eargs++; left--; 469 } else { 470 ierr = PetscOptionsSetValue(eargs[0],eargs[1]);CHKERRQ(ierr); 471 eargs += 2; left -= 2; 472 } 473 } 474 } 475 PetscFunctionReturn(0); 476 } 477 478 #undef __FUNCT__ 479 #define __FUNCT__ "PetscOptionsPrint" 480 /*@C 481 PetscOptionsPrint - Prints the options that have been loaded. This is 482 useful for debugging purposes. 483 484 Collective on PETSC_COMM_WORLD 485 486 Input Parameter: 487 . FILE fd - location to print options (usually stdout or stderr) 488 489 Options Database Key: 490 . -optionstable - Activates PetscOptionsPrint() within PetscFinalize() 491 492 Level: advanced 493 494 Concepts: options database^printing 495 496 .seealso: PetscOptionsAllUsed() 497 @*/ 498 PetscErrorCode PETSC_DLLEXPORT PetscOptionsPrint(FILE *fd) 499 { 500 PetscErrorCode ierr; 501 PetscInt i; 502 503 PetscFunctionBegin; 504 if (!fd) fd = stdout; 505 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 506 for (i=0; i<options->N; i++) { 507 if (options->values[i]) { 508 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"OptionTable: -%s %s\n",options->names[i],options->values[i]);CHKERRQ(ierr); 509 } else { 510 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"OptionTable: -%s\n",options->names[i]);CHKERRQ(ierr); 511 } 512 } 513 PetscFunctionReturn(0); 514 } 515 516 #undef __FUNCT__ 517 #define __FUNCT__ "PetscOptionsGetAll" 518 /*@C 519 PetscOptionsGetAll - Lists all the options the program was run with in a single string. 520 521 Not Collective 522 523 Output Parameter: 524 . copts - pointer where string pointer is stored 525 526 Level: advanced 527 528 Concepts: options database^listing 529 530 .seealso: PetscOptionsAllUsed(), PetscOptionsPrint() 531 @*/ 532 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetAll(char *copts[]) 533 { 534 PetscErrorCode ierr; 535 PetscInt i; 536 size_t len = 1,lent; 537 char *coptions; 538 539 PetscFunctionBegin; 540 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 541 542 /* count the length of the required string */ 543 for (i=0; i<options->N; i++) { 544 ierr = PetscStrlen(options->names[i],&lent);CHKERRQ(ierr); 545 len += 2 + lent; 546 if (options->values[i]) { 547 ierr = PetscStrlen(options->values[i],&lent);CHKERRQ(ierr); 548 len += 1 + lent; 549 } 550 } 551 ierr = PetscMalloc(len*sizeof(char),&coptions);CHKERRQ(ierr); 552 coptions[0] = 0; 553 for (i=0; i<options->N; i++) { 554 ierr = PetscStrcat(coptions,"-");CHKERRQ(ierr); 555 ierr = PetscStrcat(coptions,options->names[i]);CHKERRQ(ierr); 556 ierr = PetscStrcat(coptions," ");CHKERRQ(ierr); 557 if (options->values[i]) { 558 ierr = PetscStrcat(coptions,options->values[i]);CHKERRQ(ierr); 559 ierr = PetscStrcat(coptions," ");CHKERRQ(ierr); 560 } 561 } 562 *copts = coptions; 563 PetscFunctionReturn(0); 564 } 565 566 #undef __FUNCT__ 567 #define __FUNCT__ "PetscOptionsDestroy" 568 /*@C 569 PetscOptionsDestroy - Destroys the option database. 570 571 Note: 572 Since PetscOptionsDestroy() is called by PetscFinalize(), the user 573 typically does not need to call this routine. 574 575 Level: developer 576 577 .seealso: PetscOptionsInsert() 578 @*/ 579 PetscErrorCode PETSC_DLLEXPORT PetscOptionsDestroy(void) 580 { 581 PetscInt i; 582 583 PetscFunctionBegin; 584 if (!options) PetscFunctionReturn(0); 585 for (i=0; i<options->N; i++) { 586 if (options->names[i]) free(options->names[i]); 587 if (options->values[i]) free(options->values[i]); 588 } 589 for (i=0; i<options->Naliases; i++) { 590 free(options->aliases1[i]); 591 free(options->aliases2[i]); 592 } 593 free(options); 594 options = 0; 595 PetscFunctionReturn(0); 596 } 597 598 #undef __FUNCT__ 599 #define __FUNCT__ "PetscOptionsSetValue" 600 /*@C 601 PetscOptionsSetValue - Sets an option name-value pair in the options 602 database, overriding whatever is already present. 603 604 Not collective, but setting values on certain processors could cause problems 605 for parallel objects looking for options. 606 607 Input Parameters: 608 + name - name of option, this SHOULD have the - prepended 609 - value - the option value (not used for all options) 610 611 Level: intermediate 612 613 Note: 614 Only some options have values associated with them, such as 615 -ksp_rtol tol. Other options stand alone, such as -ksp_monitor. 616 617 Concepts: options database^adding option 618 619 .seealso: PetscOptionsInsert() 620 @*/ 621 PetscErrorCode PETSC_DLLEXPORT PetscOptionsSetValue(const char iname[],const char value[]) 622 { 623 size_t len; 624 PetscErrorCode ierr; 625 PetscInt N,n,i; 626 char **names; 627 const char *name = (char*)iname; 628 PetscTruth gt,match; 629 630 PetscFunctionBegin; 631 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 632 633 /* this is so that -h and -help are equivalent (p4 does not like -help)*/ 634 ierr = PetscStrcasecmp(name,"-h",&match);CHKERRQ(ierr); 635 if (match) name = "-help"; 636 637 name++; 638 /* first check against aliases */ 639 N = options->Naliases; 640 for (i=0; i<N; i++) { 641 ierr = PetscStrcasecmp(options->aliases1[i],name,&match);CHKERRQ(ierr); 642 if (match) { 643 name = options->aliases2[i]; 644 break; 645 } 646 } 647 648 N = options->N; 649 n = N; 650 names = options->names; 651 652 for (i=0; i<N; i++) { 653 ierr = PetscStrcasecmp(names[i],name,&match);CHKERRQ(ierr); 654 ierr = PetscStrgrt(names[i],name,>);CHKERRQ(ierr); 655 if (match) { 656 if (options->values[i]) free(options->values[i]); 657 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 658 if (len) { 659 options->values[i] = (char*)malloc((len+1)*sizeof(char)); 660 ierr = PetscStrcpy(options->values[i],value);CHKERRQ(ierr); 661 } else { options->values[i] = 0;} 662 PetscFunctionReturn(0); 663 } else if (gt) { 664 n = i; 665 break; 666 } 667 } 668 if (N >= MAXOPTIONS) { 669 SETERRQ1(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); 670 } 671 /* shift remaining values down 1 */ 672 for (i=N; i>n; i--) { 673 names[i] = names[i-1]; 674 options->values[i] = options->values[i-1]; 675 options->used[i] = options->used[i-1]; 676 } 677 /* insert new name and value */ 678 ierr = PetscStrlen(name,&len);CHKERRQ(ierr); 679 names[n] = (char*)malloc((len+1)*sizeof(char)); 680 ierr = PetscStrcpy(names[n],name);CHKERRQ(ierr); 681 if (value) { 682 ierr = PetscStrlen(value,&len);CHKERRQ(ierr); 683 options->values[n] = (char*)malloc((len+1)*sizeof(char)); 684 ierr = PetscStrcpy(options->values[n],value);CHKERRQ(ierr); 685 } else {options->values[n] = 0;} 686 options->used[n] = PETSC_FALSE; 687 options->N++; 688 PetscOptionsMonitor(name,value); 689 PetscFunctionReturn(0); 690 } 691 692 #undef __FUNCT__ 693 #define __FUNCT__ "PetscOptionsClearValue" 694 /*@C 695 PetscOptionsClearValue - Clears an option name-value pair in the options 696 database, overriding whatever is already present. 697 698 Not Collective, but setting values on certain processors could cause problems 699 for parallel objects looking for options. 700 701 Input Parameter: 702 . name - name of option, this SHOULD have the - prepended 703 704 Level: intermediate 705 706 Concepts: options database^removing option 707 .seealso: PetscOptionsInsert() 708 @*/ 709 PetscErrorCode PETSC_DLLEXPORT PetscOptionsClearValue(const char iname[]) 710 { 711 PetscErrorCode ierr; 712 PetscInt N,n,i; 713 char **names,*name=(char*)iname; 714 PetscTruth gt,match; 715 716 PetscFunctionBegin; 717 if (name[0] != '-') SETERRQ1(PETSC_ERR_ARG_WRONG,"Name must begin with -: Instead %s",name); 718 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 719 720 name++; 721 722 N = options->N; n = 0; 723 names = options->names; 724 725 for (i=0; i<N; i++) { 726 ierr = PetscStrcasecmp(names[i],name,&match);CHKERRQ(ierr); 727 ierr = PetscStrgrt(names[i],name,>);CHKERRQ(ierr); 728 if (match) { 729 if (options->values[i]) free(options->values[i]); 730 PetscOptionsMonitor(name,""); 731 break; 732 } else if (gt) { 733 PetscFunctionReturn(0); /* it was not listed */ 734 } 735 n++; 736 } 737 if (n == N) PetscFunctionReturn(0); /* it was not listed */ 738 739 /* shift remaining values down 1 */ 740 for (i=n; i<N-1; i++) { 741 names[i] = names[i+1]; 742 options->values[i] = options->values[i+1]; 743 options->used[i] = options->used[i+1]; 744 } 745 options->N--; 746 PetscFunctionReturn(0); 747 } 748 749 #undef __FUNCT__ 750 #define __FUNCT__ "PetscOptionsSetAlias" 751 /*@C 752 PetscOptionsReject - Generates an error if a certain option is given. 753 754 Not Collective, but setting values on certain processors could cause problems 755 for parallel objects looking for options. 756 757 Input Parameters: 758 + name - the option one is seeking 759 - mess - error message (may be PETSC_NULL) 760 761 Level: advanced 762 763 Concepts: options database^rejecting option 764 765 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),OptionsHasName(), 766 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(),PetscOptionsTruth(), 767 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 768 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 769 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 770 PetscOptionsList(), PetscOptionsEList() 771 @*/ 772 PetscErrorCode PETSC_DLLEXPORT PetscOptionsSetAlias(const char inewname[],const char ioldname[]) 773 { 774 PetscErrorCode ierr; 775 PetscInt n = options->Naliases; 776 size_t len; 777 char *newname = (char *)inewname,*oldname = (char*)ioldname; 778 779 PetscFunctionBegin; 780 if (newname[0] != '-') SETERRQ1(PETSC_ERR_ARG_WRONG,"aliased must have -: Instead %s",newname); 781 if (oldname[0] != '-') SETERRQ1(PETSC_ERR_ARG_WRONG,"aliasee must have -: Instead %s",oldname); 782 if (n >= MAXALIASES) { 783 SETERRQ1(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); 784 } 785 786 newname++; oldname++; 787 ierr = PetscStrlen(newname,&len);CHKERRQ(ierr); 788 options->aliases1[n] = (char*)malloc((len+1)*sizeof(char)); 789 ierr = PetscStrcpy(options->aliases1[n],newname);CHKERRQ(ierr); 790 ierr = PetscStrlen(oldname,&len);CHKERRQ(ierr); 791 options->aliases2[n] = (char*)malloc((len+1)*sizeof(char)); 792 ierr = PetscStrcpy(options->aliases2[n],oldname);CHKERRQ(ierr); 793 options->Naliases++; 794 PetscFunctionReturn(0); 795 } 796 797 #undef __FUNCT__ 798 #define __FUNCT__ "PetscOptionsFindPair_Private" 799 static PetscErrorCode PetscOptionsFindPair_Private(const char pre[],const char name[],char *value[],PetscTruth *flg) 800 { 801 PetscErrorCode ierr; 802 PetscInt i,N; 803 size_t len; 804 char **names,tmp[256]; 805 PetscTruth match; 806 807 PetscFunctionBegin; 808 if (!options) {ierr = PetscOptionsInsert(0,0,0);CHKERRQ(ierr);} 809 N = options->N; 810 names = options->names; 811 812 if (name[0] != '-') SETERRQ1(PETSC_ERR_ARG_WRONG,"Name must begin with -: Instead %s",name); 813 814 /* append prefix to name */ 815 if (pre) { 816 if (pre[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Prefix should not begin with a -"); 817 ierr = PetscStrncpy(tmp,pre,256);CHKERRQ(ierr); 818 ierr = PetscStrlen(tmp,&len);CHKERRQ(ierr); 819 ierr = PetscStrncat(tmp,name+1,256-len-1);CHKERRQ(ierr); 820 } else { 821 ierr = PetscStrncpy(tmp,name+1,256);CHKERRQ(ierr); 822 } 823 824 /* slow search */ 825 *flg = PETSC_FALSE; 826 for (i=0; i<N; i++) { 827 ierr = PetscStrcasecmp(names[i],tmp,&match);CHKERRQ(ierr); 828 if (match) { 829 *value = options->values[i]; 830 options->used[i] = PETSC_TRUE; 831 *flg = PETSC_TRUE; 832 break; 833 } 834 } 835 if (!*flg) { 836 PetscInt j,cnt = 0,locs[16],loce[16]; 837 size_t n; 838 ierr = PetscStrlen(tmp,&n);CHKERRQ(ierr); 839 /* determine the location and number of all _%d_ in the key */ 840 for (i=0; i< (PetscInt)n; i++) { 841 if (tmp[i] == '_') { 842 for (j=i+1; j< (PetscInt)n; j++) { 843 if (tmp[j] >= '0' && tmp[j] <= '9') continue; 844 if (tmp[j] == '_' && j > i+1) { /* found a number */ 845 locs[cnt] = i+1; 846 loce[cnt++] = j+1; 847 } 848 break; 849 } 850 } 851 } 852 if (cnt) { 853 char tmp2[256]; 854 for (i=0; i<cnt; i++) { 855 ierr = PetscStrcpy(tmp2,"-");CHKERRQ(ierr); 856 ierr = PetscStrncat(tmp2,tmp,locs[i]);CHKERRQ(ierr); 857 ierr = PetscStrcat(tmp2,tmp+loce[i]);CHKERRQ(ierr); 858 ierr = PetscOptionsFindPair_Private(PETSC_NULL,tmp2,value,flg);CHKERRQ(ierr); 859 if (*flg) break; 860 } 861 } 862 } 863 PetscFunctionReturn(0); 864 } 865 866 #undef __FUNCT__ 867 #define __FUNCT__ "PetscOptionsReject" 868 /*@C 869 PetscOptionsReject - Generates an error if a certain option is given. 870 871 Not Collective, but setting values on certain processors could cause problems 872 for parallel objects looking for options. 873 874 Input Parameters: 875 + name - the option one is seeking 876 - mess - error message (may be PETSC_NULL) 877 878 Level: advanced 879 880 Concepts: options database^rejecting option 881 882 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),OptionsHasName(), 883 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 884 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 885 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 886 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 887 PetscOptionsList(), PetscOptionsEList() 888 @*/ 889 PetscErrorCode PETSC_DLLEXPORT PetscOptionsReject(const char name[],const char mess[]) 890 { 891 PetscErrorCode ierr; 892 PetscTruth flag; 893 894 PetscFunctionBegin; 895 ierr = PetscOptionsHasName(PETSC_NULL,name,&flag);CHKERRQ(ierr); 896 if (flag) { 897 if (mess) { 898 SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"Program has disabled option: %s with %s",name,mess); 899 } else { 900 SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Program has disabled option: %s",name); 901 } 902 } 903 PetscFunctionReturn(0); 904 } 905 906 #undef __FUNCT__ 907 #define __FUNCT__ "PetscOptionsHasName" 908 /*@C 909 PetscOptionsHasName - Determines whether a certain option is given in the database. 910 911 Not Collective 912 913 Input Parameters: 914 + name - the option one is seeking 915 - pre - string to prepend to the name or PETSC_NULL 916 917 Output Parameters: 918 . flg - PETSC_TRUE if found else PETSC_FALSE. 919 920 Level: beginner 921 922 Concepts: options database^has option name 923 924 Notes: Name cannot be simply -h 925 926 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 927 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 928 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 929 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 930 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 931 PetscOptionsList(), PetscOptionsEList() 932 @*/ 933 PetscErrorCode PETSC_DLLEXPORT PetscOptionsHasName(const char pre[],const char name[],PetscTruth *flg) 934 { 935 char *value; 936 PetscErrorCode ierr; 937 PetscTruth isfalse,flag; 938 939 PetscFunctionBegin; 940 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 941 942 /* remove if turned off */ 943 if (flag) { 944 ierr = PetscStrcasecmp(value,"FALSE",&isfalse);CHKERRQ(ierr); 945 if (isfalse) flag = PETSC_FALSE; 946 ierr = PetscStrcasecmp(value,"NO",&isfalse);CHKERRQ(ierr); 947 if (isfalse) flag = PETSC_FALSE; 948 ierr = PetscStrcasecmp(value,"0",&isfalse);CHKERRQ(ierr); 949 if (isfalse) flag = PETSC_FALSE; 950 } 951 if (flg) *flg = flag; 952 PetscFunctionReturn(0); 953 } 954 955 #undef __FUNCT__ 956 #define __FUNCT__ "PetscOptionsGetInt" 957 /*@C 958 PetscOptionsGetInt - Gets the integer value for a particular option in the database. 959 960 Not Collective 961 962 Input Parameters: 963 + pre - the string to prepend to the name or PETSC_NULL 964 - name - the option one is seeking 965 966 Output Parameter: 967 + ivalue - the integer value to return 968 - flg - PETSC_TRUE if found, else PETSC_FALSE 969 970 Level: beginner 971 972 Concepts: options database^has int 973 974 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), 975 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 976 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 977 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 978 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 979 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 980 PetscOptionsList(), PetscOptionsEList() 981 @*/ 982 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetInt(const char pre[],const char name[],PetscInt *ivalue,PetscTruth *flg) 983 { 984 char *value; 985 PetscErrorCode ierr; 986 PetscTruth flag; 987 988 PetscFunctionBegin; 989 PetscValidCharPointer(name,2); 990 PetscValidIntPointer(ivalue,3); 991 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 992 if (flag) { 993 if (!value) {if (flg) *flg = PETSC_FALSE;} 994 else { 995 if (flg) *flg = PETSC_TRUE; 996 ierr = PetscOptionsAtoi(value,ivalue);CHKERRQ(ierr); 997 } 998 } else { 999 if (flg) *flg = PETSC_FALSE; 1000 } 1001 PetscFunctionReturn(0); 1002 } 1003 1004 #undef __FUNCT__ 1005 #define __FUNCT__ "PetscOptionsGetEList" 1006 /*@C 1007 PetscOptionsGetEList - Puts a list of option values that a single one may be selected from 1008 1009 Not Collective 1010 1011 Input Parameters: 1012 + pre - the string to prepend to the name or PETSC_NULL 1013 . opt - option name 1014 . list - the possible choices 1015 . ntext - number of choices 1016 1017 Output Parameter: 1018 + value - the index of the value to return 1019 - set - PETSC_TRUE if found, else PETSC_FALSE 1020 1021 Level: intermediate 1022 1023 See PetscOptionsList() for when the choices are given in a PetscFList() 1024 1025 Concepts: options database^list 1026 1027 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1028 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1029 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1030 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1031 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1032 PetscOptionsList(), PetscOptionsEList() 1033 @*/ 1034 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetEList(const char pre[],const char opt[],const char **list,PetscInt ntext,PetscInt *value,PetscTruth *set) 1035 { 1036 PetscErrorCode ierr; 1037 size_t alen,len = 0; 1038 char *svalue; 1039 PetscTruth aset,flg = PETSC_FALSE; 1040 PetscInt i; 1041 1042 PetscFunctionBegin; 1043 for ( i=0; i<ntext; i++) { 1044 ierr = PetscStrlen(list[i],&alen);CHKERRQ(ierr); 1045 if (alen > len) len = alen; 1046 } 1047 len += 5; /* a little extra space for user mistypes */ 1048 ierr = PetscMalloc(len*sizeof(char),&svalue);CHKERRQ(ierr); 1049 ierr = PetscOptionsGetString(pre,opt,svalue,len,&aset);CHKERRQ(ierr); 1050 if (aset) { 1051 if (set) *set = PETSC_TRUE; 1052 for (i=0; i<ntext; i++) { 1053 ierr = PetscStrcasecmp(svalue,list[i],&flg);CHKERRQ(ierr); 1054 if (flg) { 1055 *value = i; 1056 break; 1057 } 1058 } 1059 if (!flg) SETERRQ3(PETSC_ERR_USER,"Unknown option %s for -%s%s",svalue,pre?pre:"",opt+1); 1060 } else if (set) { 1061 *set = PETSC_FALSE; 1062 } 1063 ierr = PetscFree(svalue);CHKERRQ(ierr); 1064 PetscFunctionReturn(0); 1065 } 1066 1067 #undef __FUNCT__ 1068 #define __FUNCT__ "PetscOptionsEnum" 1069 /*@C 1070 PetscOptionsGetEnum - Gets the enum value for a particular option in the database. 1071 1072 Not Collective 1073 1074 Input Parameters: 1075 + pre - option prefix or PETSC_NULL 1076 . opt - option name 1077 . list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null 1078 - defaultv - the default (current) value 1079 1080 Output Parameter: 1081 + value - the value to return 1082 - flg - PETSC_TRUE if found, else PETSC_FALSE 1083 1084 Level: beginner 1085 1086 Concepts: options database 1087 1088 Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd() 1089 1090 list is usually something like PCASMTypes or some other predefined list of enum names 1091 1092 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(), 1093 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth() 1094 PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(), 1095 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1096 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1097 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1098 PetscOptionsList(), PetscOptionsEList(), PetscOptionsGetEList(), PetscOptionsEnum() 1099 @*/ 1100 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetEnum(const char pre[],const char opt[],const char **list,PetscEnum *value,PetscTruth *set) 1101 { 1102 PetscErrorCode ierr; 1103 PetscInt ntext = 0; 1104 1105 PetscFunctionBegin; 1106 while (list[ntext++]) { 1107 if (ntext > 50) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries"); 1108 } 1109 if (ntext < 3) SETERRQ(PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix"); 1110 ntext -= 3; 1111 ierr = PetscOptionsGetEList(pre,opt,list,ntext,(PetscInt*)value,set);CHKERRQ(ierr); 1112 PetscFunctionReturn(0); 1113 } 1114 1115 #undef __FUNCT__ 1116 #define __FUNCT__ "PetscOptionsGetTruth" 1117 /*@C 1118 PetscOptionsGetTruth - Gets the Logical (true or false) value for a particular 1119 option in the database. 1120 1121 Not Collective 1122 1123 Input Parameters: 1124 + pre - the string to prepend to the name or PETSC_NULL 1125 - name - the option one is seeking 1126 1127 Output Parameter: 1128 + ivalue - the logical value to return 1129 - flg - PETSC_TRUE if found, else PETSC_FALSE 1130 1131 Level: beginner 1132 1133 Notes: 1134 TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE 1135 FALSE, false, NO, no, and 0 all translate to PETSC_FALSE 1136 1137 Concepts: options database^has logical 1138 1139 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), 1140 PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsGetInt(), PetscOptionsTruth(), 1141 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1142 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1143 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1144 PetscOptionsList(), PetscOptionsEList() 1145 @*/ 1146 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetTruth(const char pre[],const char name[],PetscTruth *ivalue,PetscTruth *flg) 1147 { 1148 char *value; 1149 PetscTruth flag,istrue,isfalse; 1150 PetscErrorCode ierr; 1151 1152 PetscFunctionBegin; 1153 PetscValidCharPointer(name,2); 1154 PetscValidIntPointer(ivalue,3); 1155 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1156 if (flag) { 1157 if (flg) *flg = PETSC_TRUE; 1158 if (!value) { 1159 *ivalue = PETSC_TRUE; 1160 } else { 1161 *ivalue = PETSC_TRUE; 1162 ierr = PetscStrcasecmp(value,"TRUE",&istrue);CHKERRQ(ierr); 1163 if (istrue) PetscFunctionReturn(0); 1164 ierr = PetscStrcasecmp(value,"YES",&istrue);CHKERRQ(ierr); 1165 if (istrue) PetscFunctionReturn(0); 1166 ierr = PetscStrcasecmp(value,"1",&istrue);CHKERRQ(ierr); 1167 if (istrue) PetscFunctionReturn(0); 1168 ierr = PetscStrcasecmp(value,"on",&istrue);CHKERRQ(ierr); 1169 if (istrue) PetscFunctionReturn(0); 1170 1171 *ivalue = PETSC_FALSE; 1172 ierr = PetscStrcasecmp(value,"FALSE",&isfalse);CHKERRQ(ierr); 1173 if (isfalse) PetscFunctionReturn(0); 1174 ierr = PetscStrcasecmp(value,"NO",&isfalse);CHKERRQ(ierr); 1175 if (isfalse) PetscFunctionReturn(0); 1176 ierr = PetscStrcasecmp(value,"0",&isfalse);CHKERRQ(ierr); 1177 if (isfalse) PetscFunctionReturn(0); 1178 ierr = PetscStrcasecmp(value,"off",&isfalse);CHKERRQ(ierr); 1179 if (isfalse) PetscFunctionReturn(0); 1180 1181 SETERRQ1(PETSC_ERR_ARG_WRONG,"Unknown logical value: %s",value); 1182 } 1183 } else { 1184 if (flg) *flg = PETSC_FALSE; 1185 } 1186 PetscFunctionReturn(0); 1187 } 1188 1189 #undef __FUNCT__ 1190 #define __FUNCT__ "PetscOptionsGetReal" 1191 /*@C 1192 PetscOptionsGetReal - Gets the double precision value for a particular 1193 option in the database. 1194 1195 Not Collective 1196 1197 Input Parameters: 1198 + pre - string to prepend to each name or PETSC_NULL 1199 - name - the option one is seeking 1200 1201 Output Parameter: 1202 + dvalue - the double value to return 1203 - flg - PETSC_TRUE if found, PETSC_FALSE if not found 1204 1205 Level: beginner 1206 1207 Concepts: options database^has double 1208 1209 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1210 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(),PetscOptionsTruth(), 1211 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1212 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1213 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1214 PetscOptionsList(), PetscOptionsEList() 1215 @*/ 1216 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetReal(const char pre[],const char name[],PetscReal *dvalue,PetscTruth *flg) 1217 { 1218 char *value; 1219 PetscErrorCode ierr; 1220 PetscTruth flag; 1221 1222 PetscFunctionBegin; 1223 PetscValidCharPointer(name,2); 1224 PetscValidDoublePointer(dvalue,3); 1225 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1226 if (flag) { 1227 if (!value) {if (flg) *flg = PETSC_FALSE;} 1228 else {if (flg) *flg = PETSC_TRUE; ierr = PetscOptionsAtod(value,dvalue);CHKERRQ(ierr);} 1229 } else { 1230 if (flg) *flg = PETSC_FALSE; 1231 } 1232 PetscFunctionReturn(0); 1233 } 1234 1235 #undef __FUNCT__ 1236 #define __FUNCT__ "PetscOptionsGetScalar" 1237 /*@C 1238 PetscOptionsGetScalar - Gets the scalar value for a particular 1239 option in the database. 1240 1241 Not Collective 1242 1243 Input Parameters: 1244 + pre - string to prepend to each name or PETSC_NULL 1245 - name - the option one is seeking 1246 1247 Output Parameter: 1248 + dvalue - the double value to return 1249 - flg - PETSC_TRUE if found, else PETSC_FALSE 1250 1251 Level: beginner 1252 1253 Usage: 1254 A complex number 2+3i can be specified as 2,3 at the command line. 1255 or a number 2.0e-10 - 3.3e-20 i can be specified as 2.0e-10,3.3e-20 1256 1257 Concepts: options database^has scalar 1258 1259 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1260 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1261 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1262 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1263 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1264 PetscOptionsList(), PetscOptionsEList() 1265 @*/ 1266 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetScalar(const char pre[],const char name[],PetscScalar *dvalue,PetscTruth *flg) 1267 { 1268 char *value; 1269 PetscTruth flag; 1270 PetscErrorCode ierr; 1271 1272 PetscFunctionBegin; 1273 PetscValidCharPointer(name,2); 1274 PetscValidScalarPointer(dvalue,3); 1275 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1276 if (flag) { 1277 if (!value) { 1278 if (flg) *flg = PETSC_FALSE; 1279 } else { 1280 #if !defined(PETSC_USE_COMPLEX) 1281 ierr = PetscOptionsAtod(value,dvalue);CHKERRQ(ierr); 1282 #else 1283 PetscReal re=0.0,im=0.0; 1284 PetscToken *token; 1285 char *tvalue = 0; 1286 1287 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1288 ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr); 1289 if (!tvalue) { SETERRQ(PETSC_ERR_ARG_WRONG,"unknown string specified\n"); } 1290 ierr = PetscOptionsAtod(tvalue,&re);CHKERRQ(ierr); 1291 ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr); 1292 if (!tvalue) { /* Unknown separator used. using only real value */ 1293 *dvalue = re; 1294 } else { 1295 ierr = PetscOptionsAtod(tvalue,&im);CHKERRQ(ierr); 1296 *dvalue = re + PETSC_i*im; 1297 } 1298 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1299 #endif 1300 if (flg) *flg = PETSC_TRUE; 1301 } 1302 } else { /* flag */ 1303 if (flg) *flg = PETSC_FALSE; 1304 } 1305 PetscFunctionReturn(0); 1306 } 1307 1308 #undef __FUNCT__ 1309 #define __FUNCT__ "PetscOptionsGetRealArray" 1310 /*@C 1311 PetscOptionsGetRealArray - Gets an array of double precision values for a 1312 particular option in the database. The values must be separated with 1313 commas with no intervening spaces. 1314 1315 Not Collective 1316 1317 Input Parameters: 1318 + pre - string to prepend to each name or PETSC_NULL 1319 . name - the option one is seeking 1320 - nmax - maximum number of values to retrieve 1321 1322 Output Parameters: 1323 + dvalue - the double value to return 1324 . nmax - actual number of values retreived 1325 - flg - PETSC_TRUE if found, else PETSC_FALSE 1326 1327 Level: beginner 1328 1329 Concepts: options database^array of doubles 1330 1331 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1332 PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsTruth(), 1333 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1334 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1335 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1336 PetscOptionsList(), PetscOptionsEList() 1337 @*/ 1338 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetRealArray(const char pre[],const char name[],PetscReal dvalue[],PetscInt *nmax,PetscTruth *flg) 1339 { 1340 char *value; 1341 PetscErrorCode ierr; 1342 PetscInt n = 0; 1343 PetscTruth flag; 1344 PetscToken *token; 1345 1346 PetscFunctionBegin; 1347 PetscValidCharPointer(name,2); 1348 PetscValidDoublePointer(dvalue,3); 1349 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1350 if (!flag) {if (flg) *flg = PETSC_FALSE; *nmax = 0; PetscFunctionReturn(0);} 1351 if (!value) {if (flg) *flg = PETSC_TRUE; *nmax = 0; PetscFunctionReturn(0);} 1352 1353 if (flg) *flg = PETSC_TRUE; 1354 1355 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1356 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1357 while (n < *nmax) { 1358 if (!value) break; 1359 ierr = PetscOptionsAtod(value,dvalue++);CHKERRQ(ierr); 1360 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1361 n++; 1362 } 1363 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1364 *nmax = n; 1365 PetscFunctionReturn(0); 1366 } 1367 1368 #undef __FUNCT__ 1369 #define __FUNCT__ "PetscOptionsGetIntArray" 1370 /*@C 1371 PetscOptionsGetIntArray - Gets an array of integer values for a particular 1372 option in the database. The values must be separated with commas with 1373 no intervening spaces. 1374 1375 Not Collective 1376 1377 Input Parameters: 1378 + pre - string to prepend to each name or PETSC_NULL 1379 . name - the option one is seeking 1380 - nmax - maximum number of values to retrieve 1381 1382 Output Parameter: 1383 + dvalue - the integer values to return 1384 . nmax - actual number of values retreived 1385 - flg - PETSC_TRUE if found, else PETSC_FALSE 1386 1387 Level: beginner 1388 1389 Concepts: options database^array of ints 1390 1391 .seealso: PetscOptionsGetInt(), PetscOptionsHasName(), 1392 PetscOptionsGetString(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1393 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1394 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1395 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1396 PetscOptionsList(), PetscOptionsEList() 1397 @*/ 1398 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetIntArray(const char pre[],const char name[],PetscInt dvalue[],PetscInt *nmax,PetscTruth *flg) 1399 { 1400 char *value; 1401 PetscErrorCode ierr; 1402 PetscInt n = 0; 1403 PetscTruth flag; 1404 PetscToken *token; 1405 1406 PetscFunctionBegin; 1407 PetscValidCharPointer(name,2); 1408 PetscValidIntPointer(dvalue,3); 1409 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1410 if (!flag) {if (flg) *flg = PETSC_FALSE; *nmax = 0; PetscFunctionReturn(0);} 1411 if (!value) {if (flg) *flg = PETSC_TRUE; *nmax = 0; PetscFunctionReturn(0);} 1412 1413 if (flg) *flg = PETSC_TRUE; 1414 1415 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1416 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1417 while (n < *nmax) { 1418 if (!value) break; 1419 ierr = PetscOptionsAtoi(value,dvalue);CHKERRQ(ierr); 1420 dvalue++; 1421 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1422 n++; 1423 } 1424 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1425 *nmax = n; 1426 PetscFunctionReturn(0); 1427 } 1428 1429 #undef __FUNCT__ 1430 #define __FUNCT__ "PetscOptionsGetString" 1431 /*@C 1432 PetscOptionsGetString - Gets the string value for a particular option in 1433 the database. 1434 1435 Not Collective 1436 1437 Input Parameters: 1438 + pre - string to prepend to name or PETSC_NULL 1439 . name - the option one is seeking 1440 - len - maximum string length 1441 1442 Output Parameters: 1443 + string - location to copy string 1444 - flg - PETSC_TRUE if found, else PETSC_FALSE 1445 1446 Level: beginner 1447 1448 Fortran Note: 1449 The Fortran interface is slightly different from the C/C++ 1450 interface (len is not used). Sample usage in Fortran follows 1451 .vb 1452 character *20 string 1453 integer flg, ierr 1454 call PetscOptionsGetString(PETSC_NULL_CHARACTER,'-s',string,flg,ierr) 1455 .ve 1456 1457 Concepts: options database^string 1458 1459 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1460 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1461 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1462 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1463 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1464 PetscOptionsList(), PetscOptionsEList() 1465 @*/ 1466 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetString(const char pre[],const char name[],char string[],size_t len,PetscTruth *flg) 1467 { 1468 char *value; 1469 PetscErrorCode ierr; 1470 PetscTruth flag; 1471 1472 PetscFunctionBegin; 1473 PetscValidCharPointer(name,2); 1474 PetscValidCharPointer(string,3); 1475 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1476 if (!flag) { 1477 if (flg) *flg = PETSC_FALSE; 1478 } else { 1479 if (flg) *flg = PETSC_TRUE; 1480 if (value) { 1481 ierr = PetscStrncpy(string,value,len);CHKERRQ(ierr); 1482 } else { 1483 ierr = PetscMemzero(string,len);CHKERRQ(ierr); 1484 } 1485 } 1486 PetscFunctionReturn(0); 1487 } 1488 1489 #undef __FUNCT__ 1490 #define __FUNCT__ "PetscOptionsGetStringArray" 1491 /*@C 1492 PetscOptionsGetStringArray - Gets an array of string values for a particular 1493 option in the database. The values must be separated with commas with 1494 no intervening spaces. 1495 1496 Not Collective 1497 1498 Input Parameters: 1499 + pre - string to prepend to name or PETSC_NULL 1500 . name - the option one is seeking 1501 - nmax - maximum number of strings 1502 1503 Output Parameter: 1504 + strings - location to copy strings 1505 - flg - PETSC_TRUE if found, else PETSC_FALSE 1506 1507 Level: beginner 1508 1509 Notes: 1510 The user should pass in an array of pointers to char, to hold all the 1511 strings returned by this function. 1512 1513 The user is responsible for deallocating the strings that are 1514 returned. The Fortran interface for this routine is not supported. 1515 1516 Contributed by Matthew Knepley. 1517 1518 Concepts: options database^array of strings 1519 1520 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(), 1521 PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(), 1522 PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1523 PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1524 PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(), 1525 PetscOptionsList(), PetscOptionsEList() 1526 @*/ 1527 PetscErrorCode PETSC_DLLEXPORT PetscOptionsGetStringArray(const char pre[],const char name[],char *strings[],PetscInt *nmax,PetscTruth *flg) 1528 { 1529 char *value; 1530 PetscErrorCode ierr; 1531 PetscInt n; 1532 PetscTruth flag; 1533 PetscToken *token; 1534 1535 PetscFunctionBegin; 1536 PetscValidCharPointer(name,2); 1537 PetscValidPointer(strings,3); 1538 ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr); 1539 if (!flag) {*nmax = 0; if (flg) *flg = PETSC_FALSE; PetscFunctionReturn(0);} 1540 if (!value) {*nmax = 0; if (flg) *flg = PETSC_FALSE;PetscFunctionReturn(0);} 1541 if (!*nmax) {if (flg) *flg = PETSC_FALSE;PetscFunctionReturn(0);} 1542 if (flg) *flg = PETSC_TRUE; 1543 1544 ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr); 1545 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1546 n = 0; 1547 while (n < *nmax) { 1548 if (!value) break; 1549 ierr = PetscStrallocpy(value,&strings[n]);CHKERRQ(ierr); 1550 ierr = PetscTokenFind(token,&value);CHKERRQ(ierr); 1551 n++; 1552 } 1553 ierr = PetscTokenDestroy(token);CHKERRQ(ierr); 1554 *nmax = n; 1555 PetscFunctionReturn(0); 1556 } 1557 1558 #undef __FUNCT__ 1559 #define __FUNCT__ "PetscOptionsAllUsed" 1560 /*@C 1561 PetscOptionsAllUsed - Returns a count of the number of options in the 1562 database that have never been selected. 1563 1564 Not Collective 1565 1566 Output Parameter: 1567 . N - count of options not used 1568 1569 Level: advanced 1570 1571 .seealso: PetscOptionsPrint() 1572 @*/ 1573 PetscErrorCode PETSC_DLLEXPORT PetscOptionsAllUsed(int *N) 1574 { 1575 PetscInt i,n = 0; 1576 1577 PetscFunctionBegin; 1578 for (i=0; i<options->N; i++) { 1579 if (!options->used[i]) { n++; } 1580 } 1581 *N = n; 1582 PetscFunctionReturn(0); 1583 } 1584 1585 #undef __FUNCT__ 1586 #define __FUNCT__ "PetscOptionsLeft" 1587 /*@ 1588 PetscOptionsLeft - Prints to screen any options that were set and never used. 1589 1590 Not collective 1591 1592 Options Database Key: 1593 . -options_left - Activates OptionsAllUsed() within PetscFinalize() 1594 1595 Level: advanced 1596 1597 .seealso: PetscOptionsAllUsed() 1598 @*/ 1599 PetscErrorCode PETSC_DLLEXPORT PetscOptionsLeft(void) 1600 { 1601 PetscErrorCode ierr; 1602 PetscInt i; 1603 1604 PetscFunctionBegin; 1605 for (i=0; i<options->N; i++) { 1606 if (!options->used[i]) { 1607 if (options->values[i]) { 1608 ierr = PetscPrintf(PETSC_COMM_WORLD,"Option left: name:-%s value: %s\n",options->names[i],options->values[i]);CHKERRQ(ierr); 1609 } else { 1610 ierr = PetscPrintf(PETSC_COMM_WORLD,"Option left: name:-%s no value \n",options->names[i]);CHKERRQ(ierr); 1611 } 1612 } 1613 } 1614 PetscFunctionReturn(0); 1615 } 1616 1617 /* 1618 PetscOptionsCreate - Creates the empty options database. 1619 1620 */ 1621 #undef __FUNCT__ 1622 #define __FUNCT__ "PetscOptionsCreate" 1623 PetscErrorCode PETSC_DLLEXPORT PetscOptionsCreate(void) 1624 { 1625 PetscErrorCode ierr; 1626 1627 PetscFunctionBegin; 1628 options = (PetscOptionsTable*)malloc(sizeof(PetscOptionsTable)); 1629 ierr = PetscMemzero(options->used,MAXOPTIONS*sizeof(PetscTruth));CHKERRQ(ierr); 1630 options->namegiven = PETSC_FALSE; 1631 options->N = 0; 1632 options->Naliases = 0; 1633 PetscFunctionReturn(0); 1634 } 1635 1636 #undef __FUNCT__ 1637 #define __FUNCT__ "PetscOptionsDefaultMonitor" 1638 /*@C 1639 PetscOptionsDefaultMonitor - Print all options set events. 1640 1641 Collective on PETSC_COMM_WORLD 1642 1643 Input Parameters: 1644 + name - option name string 1645 . value - option value string 1646 - dummy - unused monitor context 1647 1648 Level: intermediate 1649 1650 .keywords: PetscOptions, default, monitor 1651 1652 .seealso: PetscOptionsSetMonitor() 1653 @*/ 1654 PetscErrorCode PETSC_DLLEXPORT PetscOptionsDefaultMonitor(const char name[], const char value[], void *dummy) 1655 { 1656 PetscErrorCode ierr; 1657 PetscViewer viewer = (PetscViewer) dummy; 1658 1659 PetscFunctionBegin; 1660 if (!viewer) viewer = PETSC_VIEWER_STDOUT_(PETSC_COMM_WORLD); 1661 ierr = PetscViewerASCIIPrintf(viewer,"Option was set: %s = %s\n",name,value);CHKERRQ(ierr); 1662 PetscFunctionReturn(0); 1663 } 1664 1665 #undef __FUNCT__ 1666 #define __FUNCT__ "PetscOptionsSetMonitor" 1667 /*@C 1668 PetscOptionsSetMonitor - Sets an ADDITIONAL function to be called at every method that 1669 modified the PETSc options database. 1670 1671 Not collective 1672 1673 Input Parameters: 1674 + monitor - pointer to function (if this is PETSC_NULL, it turns off monitoring 1675 . mctx - [optional] context for private data for the 1676 monitor routine (use PETSC_NULL if no context is desired) 1677 - monitordestroy - [optional] routine that frees monitor context 1678 (may be PETSC_NULL) 1679 1680 Calling Sequence of monitor: 1681 $ monitor (const char name[], const char value[], void *mctx) 1682 1683 + name - option name string 1684 . value - option value string 1685 - mctx - optional monitoring context, as set by PetscOptionsSetMonitor() 1686 1687 Options Database Keys: 1688 + -options_monitor - sets PetscOptionsDefaultMonitor() 1689 - -options_cancelmonitors - cancels all monitors that have 1690 been hardwired into a code by 1691 calls to PetscOptionsSetMonitor(), but 1692 does not cancel those set via 1693 the options database. 1694 1695 Notes: 1696 The default is to do nothing. To print the name and value of options 1697 being inserted into the database, use PetscOptionsDefaultMonitor() as the monitoring routine, 1698 with a null monitoring context. 1699 1700 Several different monitoring routines may be set by calling 1701 PetscOptionsSetMonitor() multiple times; all will be called in the 1702 order in which they were set. 1703 1704 Level: beginner 1705 1706 .keywords: PetscOptions, set, monitor 1707 1708 .seealso: PetscOptionsDefaultMonitor(), PetscOptionsClearMonitor() 1709 @*/ 1710 PetscErrorCode PETSC_DLLEXPORT PetscOptionsSetMonitor(PetscErrorCode (*monitor)(const char name[], const char value[], void*),void *mctx,PetscErrorCode (*monitordestroy)(void*)) 1711 { 1712 PetscFunctionBegin; 1713 if (options->numbermonitors >= MAXOPTIONSMONITORS) { 1714 SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many PetscOptions monitors set"); 1715 } 1716 options->monitor[options->numbermonitors] = monitor; 1717 options->monitordestroy[options->numbermonitors] = monitordestroy; 1718 options->monitorcontext[options->numbermonitors++] = (void*)mctx; 1719 PetscFunctionReturn(0); 1720 } 1721 1722 #undef __FUNCT__ 1723 #define __FUNCT__ "PetscOptionsClearMonitor" 1724 /*@ 1725 PetscOptionsClearMonitor - Clears all monitors for a PetscOptions object. 1726 1727 Not collective 1728 1729 Options Database Key: 1730 . -options_cancelmonitors - Cancels all monitors that have 1731 been hardwired into a code by calls to PetscOptionsSetMonitor(), 1732 but does not cancel those set via the options database. 1733 1734 Level: intermediate 1735 1736 .keywords: PetscOptions, set, monitor 1737 1738 .seealso: PetscOptionsDefaultMonitor(), PetscOptionsSetMonitor() 1739 @*/ 1740 PetscErrorCode PETSC_DLLEXPORT PetscOptionsClearMonitor() 1741 { 1742 PetscErrorCode ierr; 1743 PetscInt i; 1744 1745 PetscFunctionBegin; 1746 for (i=0; i<options->numbermonitors; i++) { 1747 if (options->monitordestroy[i]) { 1748 ierr = (*options->monitordestroy[i])(options->monitorcontext[i]);CHKERRQ(ierr); 1749 } 1750 } 1751 options->numbermonitors = 0; 1752 PetscFunctionReturn(0); 1753 } 1754