Actual source code: init.c

petsc-dev 2014-04-16
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: #define PETSC_DESIRE_COMPLEX
 10: #include <petscsys.h>        /*I  "petscsys.h"   I*/
 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:    #define PETSC_DESIRE_COMPLEX
 46:    #include <petscsys.h>
 47:    PetscComplex PETSC_i;

 49:    Level: beginner

 51:    Note:
 52:    Complex numbers are automatically available if PETSc was configured --with-scalar-type=complex (in which case
 53:    PetscComplex will match PetscScalar), otherwise the macro PETSC_DESIRE_COMPLEX must be defined before including any
 54:    PETSc headers. If the compiler supports complex numbers, PetscComplex and associated variables and functions will be
 55:    defined and PETSC_HAVE_COMPLEX will be set.

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

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

 90: /* ------------------------------------------------------------------------------*/
 91: /*
 92:    Optional file where all PETSc output from various prints is saved
 93: */
 94: FILE *petsc_history = NULL;

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

106:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
107:   if (!rank) {
108:     char        arch[10];
109:     int         err;

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

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

126:     PetscFPrintf(PETSC_COMM_SELF,*fd,"---------------------------------------------------------\n");
127:     PetscFPrintf(PETSC_COMM_SELF,*fd,"%s %s\n",version,date);
128:     PetscGetProgramName(pname,PETSC_MAX_PATH_LEN);
129:     PetscFPrintf(PETSC_COMM_SELF,*fd,"%s on a %s, %d proc. with options:\n",pname,arch,size);
130:     PetscFPrintf(PETSC_COMM_SELF,*fd,"---------------------------------------------------------\n");

132:     err = fflush(*fd);
133:     if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file");
134:   }
135:   return(0);
136: }

140: PetscErrorCode  PetscCloseHistoryFile(FILE **fd)
141: {
143:   PetscMPIInt    rank;
144:   char           date[64];
145:   int            err;

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

162: /* ------------------------------------------------------------------------------*/

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

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

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

184: void Petsc_MPI_DebuggerOnError(MPI_Comm *comm,PetscMPIInt *flag)
185: {

189:   (*PetscErrorPrintf)("MPI error %d\n",*flag);
190:   PetscAttachDebugger();
191:   if (ierr) MPI_Abort(*comm,*flag); /* hopeless so get out */
192: }

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

200:    Collective on PETSC_COMM_WORLD

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

204:    Level: advanced

206:    Note:
207:    See PetscInitialize() for more general runtime options.

209: .seealso: PetscInitialize(), PetscOptionsView(), PetscMallocDump(), PetscMPIDump(), PetscFinalize()
210: @*/
211: PetscErrorCode  PetscEnd(void)
212: {
214:   PetscFinalize();
215:   exit(0);
216:   return 0;
217: }

219: PetscBool PetscOptionsPublish = PETSC_FALSE;
220: extern PetscErrorCode PetscSetUseTrMalloc_Private(void);
221: extern PetscBool      petscsetmallocvisited;
222: static char           emacsmachinename[256];

224: PetscErrorCode (*PetscExternalVersionFunction)(MPI_Comm) = 0;
225: PetscErrorCode (*PetscExternalHelpFunction)(MPI_Comm)    = 0;

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

234:    Input Parameter:
235: +  help - the help function (may be NULL)
236: -  version - the version function (may be NULL)

238:    Level: developer

240:    Concepts: package help message

242: @*/
243: PetscErrorCode  PetscSetHelpVersionFunctions(PetscErrorCode (*help)(MPI_Comm),PetscErrorCode (*version)(MPI_Comm))
244: {
246:   PetscExternalHelpFunction    = help;
247:   PetscExternalVersionFunction = version;
248:   return(0);
249: }

251: #if defined(PETSC_HAVE_CUDA)
252: #include <cublas.h>
253: #endif

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

270:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

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

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

321:   /*
322:       Set the display variable for graphics
323:   */
324:   PetscSetDisplay();

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

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

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

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

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

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

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

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

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

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

507:     PetscLogTraceBegin(file);
508:   }
509: #endif

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

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

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

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

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

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

565:     } else {
566:       int device;
567:       cudaError_t err = cudaSuccess;

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

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


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

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

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

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

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