Actual source code: init.c

petsc-master 2014-12-19
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,flg4 = PETSC_FALSE,flag;
259:   PetscReal      si,logthreshold;
260:   PetscInt       intensity;
261:   int            i;
262:   PetscMPIInt    rank;
263:   char           version[256];

266:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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