Actual source code: init.c

petsc-master 2014-11-26
Report Typos and Errors
  1: /*

  3:    This file defines part of the initialization of PETSc

  5:   This file uses regular malloc and free because it cannot known
  6:   what malloc is being used until it has already processed the input.
  7: */

  9: #include <petscsys.h>        /*I  "petscsys.h"   I*/
 10: #include <petscviewer.h>

 12: #if defined(PETSC_HAVE_SYS_SYSINFO_H)
 13: #include <sys/sysinfo.h>
 14: #endif
 15: #if defined(PETSC_HAVE_UNISTD_H)
 16: #include <unistd.h>
 17: #endif

 19: /* ------------------------Nasty global variables -------------------------------*/
 20: /*
 21:      Indicates if PETSc started up MPI, or it was
 22:    already started before PETSc was initialized.
 23: */
 24: PetscBool   PetscBeganMPI         = PETSC_FALSE;
 25: PetscBool   PetscInitializeCalled = PETSC_FALSE;
 26: PetscBool   PetscFinalizeCalled   = PETSC_FALSE;

 28: PetscMPIInt PetscGlobalRank       = -1;
 29: PetscMPIInt PetscGlobalSize       = -1;

 31: #if defined(PETSC_HAVE_COMPLEX)
 32: #if defined(PETSC_COMPLEX_INSTANTIATE)
 33: template <> class std::complex<double>; /* instantiate complex template class */
 34: #endif
 35: #if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
 36: MPI_Datatype MPIU_C_DOUBLE_COMPLEX;
 37: MPI_Datatype MPIU_C_COMPLEX;
 38: #endif

 40: /*MC
 41:    PETSC_i - the imaginary number i

 43:    Synopsis:
 44:    #include <petscsys.h>
 45:    PetscComplex PETSC_i;

 47:    Level: beginner

 49:    Note:
 50:    Complex numbers are automatically available if PETSc located a working complex implementation

 52: .seealso: PetscRealPart(), PetscImaginaryPart(), PetscRealPartComplex(), PetscImaginaryPartComplex()
 53: M*/
 54: PetscComplex PETSC_i;
 55: #endif
 56: #if defined(PETSC_USE_REAL___FLOAT128)
 57: MPI_Datatype MPIU___FLOAT128 = 0;
 58: #if defined(PETSC_HAVE_COMPLEX)
 59: MPI_Datatype MPIU___COMPLEX128 = 0;
 60: #endif
 61: #endif
 62: MPI_Datatype MPIU_2SCALAR = 0;
 63: #if defined(PETSC_USE_64BIT_INDICES) || !defined(MPI_2INT)
 64: MPI_Datatype MPIU_2INT = 0;
 65: #endif
 66: MPI_Datatype MPIU_BOOL;
 67: MPI_Datatype MPIU_ENUM;

 69: /*
 70:        Function that is called to display all error messages
 71: */
 72: PetscErrorCode (*PetscErrorPrintf)(const char [],...)          = PetscErrorPrintfDefault;
 73: PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char [],...)  = PetscHelpPrintfDefault;
 74: #if defined(PETSC_HAVE_MATLAB_ENGINE)
 75: PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list)    = PetscVFPrintf_Matlab;
 76: #else
 77: PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list)    = PetscVFPrintfDefault;
 78: #endif
 79: /*
 80:   This is needed to turn on/off GPU synchronization
 81: */
 82: PetscBool PetscCUSPSynchronize = PETSC_FALSE;
 83: PetscBool PetscViennaCLSynchronize = PETSC_FALSE;

 85: /* ------------------------------------------------------------------------------*/
 86: /*
 87:    Optional file where all PETSc output from various prints is saved
 88: */
 89: FILE *petsc_history = NULL;

 93: PetscErrorCode  PetscOpenHistoryFile(const char filename[],FILE **fd)
 94: {
 96:   PetscMPIInt    rank,size;
 97:   char           pfile[PETSC_MAX_PATH_LEN],pname[PETSC_MAX_PATH_LEN],fname[PETSC_MAX_PATH_LEN],date[64];
 98:   char           version[256];

101:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
102:   if (!rank) {
103:     char        arch[10];
104:     int         err;

106:     PetscGetArchType(arch,10);
107:     PetscGetDate(date,64);
108:     PetscGetVersion(version,256);
109:     MPI_Comm_size(PETSC_COMM_WORLD,&size);
110:     if (filename) {
111:       PetscFixFilename(filename,fname);
112:     } else {
113:       PetscGetHomeDirectory(pfile,240);
114:       PetscStrcat(pfile,"/.petschistory");
115:       PetscFixFilename(pfile,fname);
116:     }

118:     *fd = fopen(fname,"a");
119:     if (!fd) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot open file: %s",fname);

121:     PetscFPrintf(PETSC_COMM_SELF,*fd,"---------------------------------------------------------\n");
122:     PetscFPrintf(PETSC_COMM_SELF,*fd,"%s %s\n",version,date);
123:     PetscGetProgramName(pname,PETSC_MAX_PATH_LEN);
124:     PetscFPrintf(PETSC_COMM_SELF,*fd,"%s on a %s, %d proc. with options:\n",pname,arch,size);
125:     PetscFPrintf(PETSC_COMM_SELF,*fd,"---------------------------------------------------------\n");

127:     err = fflush(*fd);
128:     if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
129:   }
130:   return(0);
131: }

135: PetscErrorCode  PetscCloseHistoryFile(FILE **fd)
136: {
138:   PetscMPIInt    rank;
139:   char           date[64];
140:   int            err;

143:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
144:   if (!rank) {
145:     PetscGetDate(date,64);
146:     PetscFPrintf(PETSC_COMM_SELF,*fd,"---------------------------------------------------------\n");
147:     PetscFPrintf(PETSC_COMM_SELF,*fd,"Finished at %s\n",date);
148:     PetscFPrintf(PETSC_COMM_SELF,*fd,"---------------------------------------------------------\n");
149:     err  = fflush(*fd);
150:     if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
151:     err = fclose(*fd);
152:     if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file");
153:   }
154:   return(0);
155: }

157: /* ------------------------------------------------------------------------------*/

159: /*
160:    This is ugly and probably belongs somewhere else, but I want to
161:   be able to put a true MPI abort error handler with command line args.

163:     This is so MPI errors in the debugger will leave all the stack
164:   frames. The default MP_Abort() cleans up and exits thus providing no useful information
165:   in the debugger hence we call abort() instead of MPI_Abort().
166: */

170: void Petsc_MPI_AbortOnError(MPI_Comm *comm,PetscMPIInt *flag)
171: {
173:   (*PetscErrorPrintf)("MPI error %d\n",*flag);
174:   abort();
175: }

179: void Petsc_MPI_DebuggerOnError(MPI_Comm *comm,PetscMPIInt *flag)
180: {

184:   (*PetscErrorPrintf)("MPI error %d\n",*flag);
185:   PetscAttachDebugger();
186:   if (ierr) MPI_Abort(*comm,*flag); /* hopeless so get out */
187: }

191: /*@C
192:    PetscEnd - Calls PetscFinalize() and then ends the program. This is useful if one
193:      wishes a clean exit somewhere deep in the program.

195:    Collective on PETSC_COMM_WORLD

197:    Options Database Keys are the same as for PetscFinalize()

199:    Level: advanced

201:    Note:
202:    See PetscInitialize() for more general runtime options.

204: .seealso: PetscInitialize(), PetscOptionsView(), PetscMallocDump(), PetscMPIDump(), PetscFinalize()
205: @*/
206: PetscErrorCode  PetscEnd(void)
207: {
209:   PetscFinalize();
210:   exit(0);
211:   return 0;
212: }

214: PetscBool PetscOptionsPublish = PETSC_FALSE;
215: extern PetscErrorCode PetscSetUseTrMalloc_Private(void);
216: extern PetscBool      petscsetmallocvisited;
217: static char           emacsmachinename[256];

219: PetscErrorCode (*PetscExternalVersionFunction)(MPI_Comm) = 0;
220: PetscErrorCode (*PetscExternalHelpFunction)(MPI_Comm)    = 0;

224: /*@C
225:    PetscSetHelpVersionFunctions - Sets functions that print help and version information
226:    before the PETSc help and version information is printed. Must call BEFORE PetscInitialize().
227:    This routine enables a "higher-level" package that uses PETSc to print its messages first.

229:    Input Parameter:
230: +  help - the help function (may be NULL)
231: -  version - the version function (may be NULL)

233:    Level: developer

235:    Concepts: package help message

237: @*/
238: PetscErrorCode  PetscSetHelpVersionFunctions(PetscErrorCode (*help)(MPI_Comm),PetscErrorCode (*version)(MPI_Comm))
239: {
241:   PetscExternalHelpFunction    = help;
242:   PetscExternalVersionFunction = version;
243:   return(0);
244: }

246: #if defined(PETSC_HAVE_CUDA)
247: #include <cublas.h>
248: #endif

252: PetscErrorCode  PetscOptionsCheckInitial_Private(void)
253: {
254:   char           string[64],mname[PETSC_MAX_PATH_LEN],*f;
255:   MPI_Comm       comm = PETSC_COMM_WORLD;
256:   PetscBool      flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE,flg4 = PETSC_FALSE,flag;
258:   PetscReal      si,logthreshold;
259:   PetscInt       intensity;
260:   int            i;
261:   PetscMPIInt    rank;
262:   char           version[256];

265:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

267:   /*
268:       Setup the memory management; support for tracing malloc() usage
269:   */
270:   PetscOptionsHasName(NULL,"-malloc_log",&flg3);
271:   logthreshold = 0.0;
272:   PetscOptionsGetReal(NULL,"-malloc_log_threshold",&logthreshold,&flg1);
273:   if (flg1) flg3 = PETSC_TRUE;
274: #if defined(PETSC_USE_DEBUG)
275:   PetscOptionsGetBool(NULL,"-malloc",&flg1,&flg2);
276:   if ((!flg2 || flg1) && !petscsetmallocvisited) {
277:     if (flg2 || !(PETSC_RUNNING_ON_VALGRIND)) {
278:       /* turn off default -malloc if valgrind is being used */
279:       PetscSetUseTrMalloc_Private();
280:     }
281:   }
282: #else
283:   PetscOptionsGetBool(NULL,"-malloc_dump",&flg1,NULL);
284:   PetscOptionsGetBool(NULL,"-malloc",&flg2,NULL);
285:   if (flg1 || flg2 || flg3) {PetscSetUseTrMalloc_Private();}
286: #endif
287:   if (flg3) {
288:     PetscMallocSetDumpLogThreshold((PetscLogDouble)logthreshold);
289:   }
290:   flg1 = PETSC_FALSE;
291:   PetscOptionsGetBool(NULL,"-malloc_debug",&flg1,NULL);
292:   if (flg1) {
293:     PetscSetUseTrMalloc_Private();
294:     PetscMallocDebug(PETSC_TRUE);
295:   }
296:   flg1 = PETSC_FALSE;
297:   PetscOptionsGetBool(NULL,"-malloc_test",&flg1,NULL);
298: #if defined(PETSC_USE_DEBUG)
299:   if (flg1 && !PETSC_RUNNING_ON_VALGRIND) {
300:     PetscSetUseTrMalloc_Private();
301:     PetscMallocSetDumpLog();
302:     PetscMallocDebug(PETSC_TRUE);
303:   }
304: #endif

306:   flg1 = PETSC_FALSE;
307:   PetscOptionsGetBool(NULL,"-malloc_info",&flg1,NULL);
308:   if (!flg1) {
309:     flg1 = PETSC_FALSE;
310:     PetscOptionsGetBool(NULL,"-memory_info",&flg1,NULL);
311:   }
312:   if (flg1) {
313:     PetscMemorySetGetMaximumUsage();
314:   }

316:   /*
317:       Set the display variable for graphics
318:   */
319:   PetscSetDisplay();

321:   /*
322:       Print the PETSc version information
323:   */
324:   PetscOptionsHasName(NULL,"-v",&flg1);
325:   PetscOptionsHasName(NULL,"-version",&flg2);
326:   PetscOptionsHasName(NULL,"-help",&flg3);
327:   if (flg1 || flg2 || flg3) {

329:     /*
330:        Print "higher-level" package version message
331:     */
332:     if (PetscExternalVersionFunction) {
333:       (*PetscExternalVersionFunction)(comm);
334:     }

336:     PetscGetVersion(version,256);
337:     (*PetscHelpPrintf)(comm,"--------------------------------------------\
338: ------------------------------\n");
339:     (*PetscHelpPrintf)(comm,"%s\n",version);
340:     (*PetscHelpPrintf)(comm,"%s",PETSC_AUTHOR_INFO);
341:     (*PetscHelpPrintf)(comm,"See docs/changes/index.html for recent updates.\n");
342:     (*PetscHelpPrintf)(comm,"See docs/faq.html for problems.\n");
343:     (*PetscHelpPrintf)(comm,"See docs/manualpages/index.html for help. \n");
344:     (*PetscHelpPrintf)(comm,"Libraries linked from %s\n",PETSC_LIB_DIR);
345:     (*PetscHelpPrintf)(comm,"--------------------------------------------\
346: ------------------------------\n");
347:   }

349:   /*
350:        Print "higher-level" package help message
351:   */
352:   if (flg3) {
353:     if (PetscExternalHelpFunction) {
354:       (*PetscExternalHelpFunction)(comm);
355:     }
356:   }

358:   /*
359:       Setup the error handling
360:   */
361:   flg1 = PETSC_FALSE;
362:   PetscOptionsGetBool(NULL,"-on_error_abort",&flg1,NULL);
363:   if (flg1) {
364:     MPI_Comm_set_errhandler(PETSC_COMM_WORLD,MPI_ERRORS_ARE_FATAL);
365:     PetscPushErrorHandler(PetscAbortErrorHandler,0);
366:   }
367:   flg1 = PETSC_FALSE;
368:   PetscOptionsGetBool(NULL,"-on_error_mpiabort",&flg1,NULL);
369:   if (flg1) { PetscPushErrorHandler(PetscMPIAbortErrorHandler,0);}
370:   flg1 = PETSC_FALSE;
371:   PetscOptionsGetBool(NULL,"-mpi_return_on_error",&flg1,NULL);
372:   if (flg1) {
373:     MPI_Comm_set_errhandler(comm,MPI_ERRORS_RETURN);
374:   }
375:   flg1 = PETSC_FALSE;
376:   PetscOptionsGetBool(NULL,"-no_signal_handler",&flg1,NULL);
377:   if (!flg1) {PetscPushSignalHandler(PetscSignalHandlerDefault,(void*)0);}
378:   flg1 = PETSC_FALSE;
379:   PetscOptionsGetBool(NULL,"-fp_trap",&flg1,NULL);
380:   if (flg1) {PetscSetFPTrap(PETSC_FP_TRAP_ON);}
381:   PetscOptionsGetInt(NULL,"-check_pointer_intensity",&intensity,&flag);

384:   /*
385:       Setup debugger information
386:   */
387:   PetscSetDefaultDebugger();
388:   PetscOptionsGetString(NULL,"-on_error_attach_debugger",string,64,&flg1);
389:   if (flg1) {
390:     MPI_Errhandler err_handler;

392:     PetscSetDebuggerFromString(string);
393:     MPI_Comm_create_errhandler((MPI_Handler_function*)Petsc_MPI_DebuggerOnError,&err_handler);
394:     MPI_Comm_set_errhandler(comm,err_handler);
395:     PetscPushErrorHandler(PetscAttachDebuggerErrorHandler,0);
396:   }
397:   PetscOptionsGetString(NULL,"-debug_terminal",string,64,&flg1);
398:   if (flg1) { PetscSetDebugTerminal(string); }
399:   PetscOptionsGetString(NULL,"-start_in_debugger",string,64,&flg1);
400:   PetscOptionsGetString(NULL,"-stop_for_debugger",string,64,&flg2);
401:   if (flg1 || flg2) {
402:     PetscMPIInt    size;
403:     PetscInt       lsize,*nodes;
404:     MPI_Errhandler err_handler;
405:     /*
406:        we have to make sure that all processors have opened
407:        connections to all other processors, otherwise once the
408:        debugger has stated it is likely to receive a SIGUSR1
409:        and kill the program.
410:     */
411:     MPI_Comm_size(PETSC_COMM_WORLD,&size);
412:     if (size > 2) {
413:       PetscMPIInt dummy = 0;
414:       MPI_Status  status;
415:       for (i=0; i<size; i++) {
416:         if (rank != i) {
417:           MPI_Send(&dummy,1,MPI_INT,i,109,PETSC_COMM_WORLD);
418:         }
419:       }
420:       for (i=0; i<size; i++) {
421:         if (rank != i) {
422:           MPI_Recv(&dummy,1,MPI_INT,i,109,PETSC_COMM_WORLD,&status);
423:         }
424:       }
425:     }
426:     /* check if this processor node should be in debugger */
427:     PetscMalloc1(size,&nodes);
428:     lsize = size;
429:     PetscOptionsGetIntArray(NULL,"-debugger_nodes",nodes,&lsize,&flag);
430:     if (flag) {
431:       for (i=0; i<lsize; i++) {
432:         if (nodes[i] == rank) { flag = PETSC_FALSE; break; }
433:       }
434:     }
435:     if (!flag) {
436:       PetscSetDebuggerFromString(string);
437:       PetscPushErrorHandler(PetscAbortErrorHandler,0);
438:       if (flg1) {
439:         PetscAttachDebugger();
440:       } else {
441:         PetscStopForDebugger();
442:       }
443:       MPI_Comm_create_errhandler((MPI_Handler_function*)Petsc_MPI_AbortOnError,&err_handler);
444:       MPI_Comm_set_errhandler(comm,err_handler);
445:     }
446:     PetscFree(nodes);
447:   }

449:   PetscOptionsGetString(NULL,"-on_error_emacs",emacsmachinename,128,&flg1);
450:   if (flg1 && !rank) {PetscPushErrorHandler(PetscEmacsClientErrorHandler,emacsmachinename);}

452:   /*
453:         Setup profiling and logging
454:   */
455: #if defined(PETSC_USE_INFO)
456:   {
457:     char logname[PETSC_MAX_PATH_LEN]; logname[0] = 0;
458:     PetscOptionsGetString(NULL,"-info",logname,250,&flg1);
459:     if (flg1 && logname[0]) {
460:       PetscInfoAllow(PETSC_TRUE,logname);
461:     } else if (flg1) {
462:       PetscInfoAllow(PETSC_TRUE,NULL);
463:     }
464:   }
465: #endif
466: #if defined(PETSC_USE_LOG)
467:   mname[0] = 0;
468:   PetscOptionsGetString(NULL,"-history",mname,PETSC_MAX_PATH_LEN,&flg1);
469:   if (flg1) {
470:     if (mname[0]) {
471:       PetscOpenHistoryFile(mname,&petsc_history);
472:     } else {
473:       PetscOpenHistoryFile(NULL,&petsc_history);
474:     }
475:   }
476: #if defined(PETSC_HAVE_MPE)
477:   flg1 = PETSC_FALSE;
478:   PetscOptionsHasName(NULL,"-log_mpe",&flg1);
479:   if (flg1) {PetscLogMPEBegin();}
480: #endif
481:   flg1 = PETSC_FALSE;
482:   flg2 = PETSC_FALSE;
483:   flg3 = PETSC_FALSE;
484:   PetscOptionsGetBool(NULL,"-log_all",&flg1,NULL);
485:   PetscOptionsGetBool(NULL,"-log",&flg2,NULL);
486:   PetscOptionsHasName(NULL,"-log_summary",&flg3);
487:   PetscOptionsHasName(NULL,"-log_view",&flg4);
488:   if (flg1)                      { PetscLogAllBegin(); }
489:   else if (flg2 || flg3 || flg4) { PetscLogBegin();}

491:   PetscOptionsGetString(NULL,"-log_trace",mname,250,&flg1);
492:   if (flg1) {
493:     char name[PETSC_MAX_PATH_LEN],fname[PETSC_MAX_PATH_LEN];
494:     FILE *file;
495:     if (mname[0]) {
496:       sprintf(name,"%s.%d",mname,rank);
497:       PetscFixFilename(name,fname);
498:       file = fopen(fname,"w");
499:       if (!file) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to open trace file: %s",fname);
500:     } else file = PETSC_STDOUT;

502:     PetscLogTraceBegin(file);
503:   }
504: #endif

506:   PetscOptionsGetBool(NULL,"-saws_options",&PetscOptionsPublish,NULL);

508: #if defined(PETSC_HAVE_CUDA)
509:   PetscOptionsHasName(NULL,"-cuda_show_devices",&flg1);
510:   if (flg1) {
511:     struct cudaDeviceProp prop;
512:     int                   devCount;
513:     int                   device;
514:     cudaError_t           err = cudaSuccess;
515:     err = cudaGetDeviceCount(&devCount);
516:     if (err != cudaSuccess)
517:       SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaGetDeviceCount %s",cudaGetErrorString(err));
518:     for (device = 0; device < devCount; ++device) {
519:       err = cudaGetDeviceProperties(&prop, device);
520:       if (err != cudaSuccess)
521:         SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaGetDeviceProperties %s",cudaGetErrorString(err));
522:       PetscPrintf(PETSC_COMM_WORLD, "CUDA device %d: %s\n", device, prop.name);
523:     }
524:   }
525:   {
526:     int size;
527:     MPI_Comm_size(PETSC_COMM_WORLD,&size);
528:     if (size>1) {
529:       int devCount, device, rank;
530:       cudaError_t err = cudaSuccess;

532:       /* check to see if we force multiple ranks to hit the same GPU */
533:       PetscOptionsGetInt(NULL,"-cuda_set_device", &device, &flg1);
534:       if (flg1) {
535:         cudaSetDevice(device);
536:         if (err != cudaSuccess)
537:           SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaSetDevice %s",cudaGetErrorString(err));
538:       } else {
539:         /* we're not using the same GPU on multiple MPI threads. So try to allocated different
540:          GPUs to different threads */

542:         /* First get the device count */
543:         err   = cudaGetDeviceCount(&devCount);
544:         if (err != cudaSuccess)
545:           SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaGetDeviceCount %s",cudaGetErrorString(err));

547:         /* next determine the rank and then set the device via a mod */
548:         MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
549:         device = rank % devCount;
550:         err   = cudaSetDevice(device);
551:         if (err != cudaSuccess)
552:           SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaSetDevice %s",cudaGetErrorString(err));
553:       }

555:       /* set the device flags so that it can map host memory ... do NOT throw exception on err!=cudaSuccess
556:        multiple devices may try to set the flags on the same device. So long as one of them succeeds, things
557:        are ok. */
558:       err = cudaSetDeviceFlags(cudaDeviceMapHost);

560:     } else {
561:       int device;
562:       cudaError_t err = cudaSuccess;

564:       /* the code below works for serial GPU simulations */
565:       PetscOptionsGetInt(NULL,"-cuda_set_device", &device, &flg1);
566:       if (flg1) {
567:         cudaSetDevice(device);
568:       }

570:       /* set the device flags so that it can map host memory ... here, we error check. */
571:       err = cudaSetDeviceFlags(cudaDeviceMapHost);
572:       if (err != cudaSuccess)
573:         SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaSetDevice %s",cudaGetErrorString(err));
574:     }
575:   }
576: #endif


579:   /*
580:        Print basic help message
581:   */
582:   PetscOptionsHasName(NULL,"-help",&flg1);
583:   if (flg1) {
584:     (*PetscHelpPrintf)(comm,"Options for all PETSc programs:\n");
585:     (*PetscHelpPrintf)(comm," -help: prints help method for each option\n");
586:     (*PetscHelpPrintf)(comm," -on_error_abort: cause an abort when an error is detected. Useful \n ");
587:     (*PetscHelpPrintf)(comm,"       only when run in the debugger\n");
588:     (*PetscHelpPrintf)(comm," -on_error_attach_debugger [gdb,dbx,xxgdb,ups,noxterm]\n");
589:     (*PetscHelpPrintf)(comm,"       start the debugger in new xterm\n");
590:     (*PetscHelpPrintf)(comm,"       unless noxterm is given\n");
591:     (*PetscHelpPrintf)(comm," -start_in_debugger [gdb,dbx,xxgdb,ups,noxterm]\n");
592:     (*PetscHelpPrintf)(comm,"       start all processes in the debugger\n");
593:     (*PetscHelpPrintf)(comm," -on_error_emacs <machinename>\n");
594:     (*PetscHelpPrintf)(comm,"    emacs jumps to error file\n");
595:     (*PetscHelpPrintf)(comm," -debugger_nodes [n1,n2,..] Nodes to start in debugger\n");
596:     (*PetscHelpPrintf)(comm," -debugger_pause [m] : delay (in seconds) to attach debugger\n");
597:     (*PetscHelpPrintf)(comm," -stop_for_debugger : prints message on how to attach debugger manually\n");
598:     (*PetscHelpPrintf)(comm,"                      waits the delay for you to attach\n");
599:     (*PetscHelpPrintf)(comm," -display display: Location where X window graphics and debuggers are displayed\n");
600:     (*PetscHelpPrintf)(comm," -no_signal_handler: do not trap error signals\n");
601:     (*PetscHelpPrintf)(comm," -mpi_return_on_error: MPI returns error code, rather than abort on internal error\n");
602:     (*PetscHelpPrintf)(comm," -fp_trap: stop on floating point exceptions\n");
603:     (*PetscHelpPrintf)(comm,"           note on IBM RS6000 this slows run greatly\n");
604:     (*PetscHelpPrintf)(comm," -malloc_dump <optional filename>: dump list of unfreed memory at conclusion\n");
605:     (*PetscHelpPrintf)(comm," -malloc: use our error checking malloc\n");
606:     (*PetscHelpPrintf)(comm," -malloc no: don't use error checking malloc\n");
607:     (*PetscHelpPrintf)(comm," -malloc_info: prints total memory usage\n");
608:     (*PetscHelpPrintf)(comm," -malloc_log: keeps log of all memory allocations\n");
609:     (*PetscHelpPrintf)(comm," -malloc_debug: enables extended checking for memory corruption\n");
610:     (*PetscHelpPrintf)(comm," -options_table: dump list of options inputted\n");
611:     (*PetscHelpPrintf)(comm," -options_left: dump list of unused options\n");
612:     (*PetscHelpPrintf)(comm," -options_left no: don't dump list of unused options\n");
613:     (*PetscHelpPrintf)(comm," -tmp tmpdir: alternative /tmp directory\n");
614:     (*PetscHelpPrintf)(comm," -shared_tmp: tmp directory is shared by all processors\n");
615:     (*PetscHelpPrintf)(comm," -not_shared_tmp: each processor has separate tmp directory\n");
616:     (*PetscHelpPrintf)(comm," -memory_info: print memory usage at end of run\n");
617:     (*PetscHelpPrintf)(comm," -server <port>: Run PETSc webserver (default port is 8080) see PetscWebServe()\n");
618: #if defined(PETSC_USE_LOG)
619:     (*PetscHelpPrintf)(comm," -get_total_flops: total flops over all processors\n");
620:     (*PetscHelpPrintf)(comm," -log[_summary _summary_python]: logging objects and events\n");
621:     (*PetscHelpPrintf)(comm," -log_trace [filename]: prints trace of all PETSc calls\n");
622: #if defined(PETSC_HAVE_MPE)
623:     (*PetscHelpPrintf)(comm," -log_mpe: Also create logfile viewable through Jumpshot\n");
624: #endif
625:     (*PetscHelpPrintf)(comm," -info <optional filename>: print informative messages about the calculations\n");
626: #endif
627:     (*PetscHelpPrintf)(comm," -v: prints PETSc version number and release date\n");
628:     (*PetscHelpPrintf)(comm," -options_file <file>: reads options from file\n");
629:     (*PetscHelpPrintf)(comm," -petsc_sleep n: sleeps n seconds before running program\n");
630:     (*PetscHelpPrintf)(comm,"-----------------------------------------------\n");
631:   }

633: #if defined(PETSC_HAVE_POPEN)
634:   {
635:   char machine[128];
636:   PetscOptionsGetString(NULL,"-popen_machine",machine,128,&flg1);
637:   if (flg1) {
638:     PetscPOpenSetMachine(machine);
639:   }
640:   }
641: #endif

643:   PetscOptionsGetReal(NULL,"-petsc_sleep",&si,&flg1);
644:   if (flg1) {
645:     PetscSleep(si);
646:   }

648:   PetscOptionsGetString(NULL,"-info_exclude",mname,PETSC_MAX_PATH_LEN,&flg1);
649:   PetscStrstr(mname,"null",&f);
650:   if (f) {
651:     PetscInfoDeactivateClass(0);
652:   }

654: #if defined(PETSC_HAVE_CUSP) || defined(PETSC_HAVE_VIENNACL)
655:   PetscOptionsHasName(NULL,"-log_summary",&flg3);
656:   if (!flg3) {
657:   PetscOptionsHasName(NULL,"-log_view",&flg3);
658:   }
659: #endif
660: #if defined(PETSC_HAVE_CUSP)
661:   PetscOptionsGetBool(NULL,"-cusp_synchronize",&flg3,NULL);
662:   PetscCUSPSynchronize = flg3;
663: #elif defined(PETSC_HAVE_VIENNACL)
664:   PetscOptionsGetBool(NULL,"-viennacl_synchronize",&flg3,NULL);
665:   PetscViennaCLSynchronize = flg3;
666: #endif
667:   return(0);
668: }