Actual source code: init.c

petsc-master 2015-03-28
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 <petscvalgrind.h>
 11: #include <petscviewer.h>

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

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

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

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

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

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

 48:    Level: beginner

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

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

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

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

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

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

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

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

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

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

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

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

158: /* ------------------------------------------------------------------------------*/

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

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

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

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

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

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

196:    Collective on PETSC_COMM_WORLD

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

200:    Level: advanced

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

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

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

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

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

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

234:    Level: developer

236:    Concepts: package help message

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

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

253: PetscErrorCode  PetscOptionsCheckInitial_Private(void)
254: {
255:   char           string[64],mname[PETSC_MAX_PATH_LEN],*f;
256:   MPI_Comm       comm = PETSC_COMM_WORLD;
257:   PetscBool      flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE,flag;
259:   PetscReal      si;
260:   PetscInt       intensity;
261:   int            i;
262:   PetscMPIInt    rank;
263:   char           version[256];
264: #if !defined(PETSC_HAVE_THREADSAFETY)
265:   PetscReal      logthreshold;
266:   PetscBool      flg4 = PETSC_FALSE;
267: #endif

270:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

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

312:   flg1 = PETSC_FALSE;
313:   PetscOptionsGetBool(NULL,"-malloc_info",&flg1,NULL);
314:   if (!flg1) {
315:     flg1 = PETSC_FALSE;
316:     PetscOptionsGetBool(NULL,"-memory_info",&flg1,NULL);
317:   }
318:   if (flg1) {
319:     PetscMemorySetGetMaximumUsage();
320:   }
321: #endif

323:   /*
324:       Set the display variable for graphics
325:   */
326:   PetscSetDisplay();

328:   /*
329:       Print the PETSc version information
330:   */
331:   PetscOptionsHasName(NULL,"-v",&flg1);
332:   PetscOptionsHasName(NULL,"-version",&flg2);
333:   PetscOptionsHasName(NULL,"-help",&flg3);
334:   if (flg1 || flg2 || flg3) {

336:     /*
337:        Print "higher-level" package version message
338:     */
339:     if (PetscExternalVersionFunction) {
340:       (*PetscExternalVersionFunction)(comm);
341:     }

343:     PetscGetVersion(version,256);
344:     (*PetscHelpPrintf)(comm,"--------------------------------------------\
345: ------------------------------\n");
346:     (*PetscHelpPrintf)(comm,"%s\n",version);
347:     (*PetscHelpPrintf)(comm,"%s",PETSC_AUTHOR_INFO);
348:     (*PetscHelpPrintf)(comm,"See docs/changes/index.html for recent updates.\n");
349:     (*PetscHelpPrintf)(comm,"See docs/faq.html for problems.\n");
350:     (*PetscHelpPrintf)(comm,"See docs/manualpages/index.html for help. \n");
351:     (*PetscHelpPrintf)(comm,"Libraries linked from %s\n",PETSC_LIB_DIR);
352:     (*PetscHelpPrintf)(comm,"--------------------------------------------\
353: ------------------------------\n");
354:   }

356:   /*
357:        Print "higher-level" package help message
358:   */
359:   if (flg3) {
360:     if (PetscExternalHelpFunction) {
361:       (*PetscExternalHelpFunction)(comm);
362:     }
363:   }

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

391:   /*
392:       Setup debugger information
393:   */
394:   PetscSetDefaultDebugger();
395:   PetscOptionsGetString(NULL,"-on_error_attach_debugger",string,64,&flg1);
396:   if (flg1) {
397:     MPI_Errhandler err_handler;

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

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

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

498:   PetscOptionsGetString(NULL,"-log_trace",mname,250,&flg1);
499:   if (flg1) {
500:     char name[PETSC_MAX_PATH_LEN],fname[PETSC_MAX_PATH_LEN];
501:     FILE *file;
502:     if (mname[0]) {
503:       sprintf(name,"%s.%d",mname,rank);
504:       PetscFixFilename(name,fname);
505:       file = fopen(fname,"w");
506:       if (!file) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to open trace file: %s",fname);
507:     } else file = PETSC_STDOUT;

509:     PetscLogTraceBegin(file);
510:   }
511: #endif

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

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

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

549:         /* First get the device count */
550:         err   = cudaGetDeviceCount(&devCount);
551:         if (err != cudaSuccess)
552:           SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaGetDeviceCount %s",cudaGetErrorString(err));

554:         /* next determine the rank and then set the device via a mod */
555:         MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
556:         device = rank % devCount;
557:         err   = cudaSetDevice(device);
558:         if (err != cudaSuccess)
559:           SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaSetDevice %s",cudaGetErrorString(err));
560:       }

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

567:     } else {
568:       int device;
569:       cudaError_t err = cudaSuccess;

571:       /* the code below works for serial GPU simulations */
572:       PetscOptionsGetInt(NULL,"-cuda_set_device", &device, &flg1);
573:       if (flg1) {
574:         cudaSetDevice(device);
575:       }

577:       /* set the device flags so that it can map host memory ... here, we error check. */
578:       err = cudaSetDeviceFlags(cudaDeviceMapHost);
579:       if (err != cudaSuccess)
580:         SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SYS,"error in cudaSetDevice %s",cudaGetErrorString(err));
581:     }
582:   }
583: #endif


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

640: #if defined(PETSC_HAVE_POPEN)
641:   {
642:   char machine[128];
643:   PetscOptionsGetString(NULL,"-popen_machine",machine,128,&flg1);
644:   if (flg1) {
645:     PetscPOpenSetMachine(machine);
646:   }
647:   }
648: #endif

650:   PetscOptionsGetReal(NULL,"-petsc_sleep",&si,&flg1);
651:   if (flg1) {
652:     PetscSleep(si);
653:   }

655:   PetscOptionsGetString(NULL,"-info_exclude",mname,PETSC_MAX_PATH_LEN,&flg1);
656:   PetscStrstr(mname,"null",&f);
657:   if (f) {
658:     PetscInfoDeactivateClass(0);
659:   }

661: #if defined(PETSC_HAVE_CUSP) || defined(PETSC_HAVE_VIENNACL)
662:   PetscOptionsHasName(NULL,"-log_summary",&flg3);
663:   if (!flg3) {
664:   PetscOptionsHasName(NULL,"-log_view",&flg3);
665:   }
666: #endif
667: #if defined(PETSC_HAVE_CUSP)
668:   PetscOptionsGetBool(NULL,"-cusp_synchronize",&flg3,NULL);
669:   PetscCUSPSynchronize = flg3;
670: #elif defined(PETSC_HAVE_VIENNACL)
671:   PetscOptionsGetBool(NULL,"-viennacl_synchronize",&flg3,NULL);
672:   PetscViennaCLSynchronize = flg3;
673: #endif
674:   return(0);
675: }