Actual source code: stack.c

      1: #define PETSC_DLL

     3:  #include petsc.h
     4:  #include petscsys.h

      6: #if defined(PETSC_USE_DEBUG)

      8: PetscStack PETSC_DLLEXPORT *petscstack = 0;

     12: PetscErrorCode PETSC_DLLEXPORT PetscStackPublish(void)
     13: {
     15:   return(0);
     16: }

     20: PetscErrorCode PETSC_DLLEXPORT PetscStackDepublish(void)
     21: {
     23:   return(0);
     24: }
     25:
     28: PetscErrorCode PETSC_DLLEXPORT PetscStackCreate(void)
     29: {

     32:   PetscStack *petscstack_in;
     33:   if (petscstack) return 0;
     34:
     35:   PetscNew(PetscStack,&petscstack_in);
     36:   petscstack_in->currentsize = 0;
     37:   petscstack = petscstack_in;

     39:   return 0;
     40: }

     44: PetscErrorCode PETSC_DLLEXPORT PetscStackView(PetscViewer viewer)
     45: {
     47:   int  i;
     48:   FILE *file;

     50:   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
     51:   PetscViewerASCIIGetPointer(viewer,&file);

     53:   if (file == stdout) {
     54:     (*PetscErrorPrintf)("Note: The EXACT line numbers in the stack are not available,\n");
     55:     (*PetscErrorPrintf)("      INSTEAD the line number of the start of the function\n");
     56:     (*PetscErrorPrintf)("      is given.\n");
     57:     for (i=petscstack->currentsize-1; i>=0; i--) {
     58:       (*PetscErrorPrintf)("[%d] %s line %d %s%s\n",PetscGlobalRank,
     59:                                                    petscstack->function[i],
     60:                                                    petscstack->line[i],
     61:                                                    petscstack->directory[i],
     62:                                                    petscstack->file[i]);
     63:     }
     64:   } else {
     65:     fprintf(file,"Note: The EXACT line numbers in the stack are not available,\n");
     66:     fprintf(file,"      INSTEAD the line number of the start of the function\n");
     67:     fprintf(file,"      is given.\n");
     68:     for (i=petscstack->currentsize-1; i>=0; i--) {
     69:       fprintf(file,"[%d] %s line %d %s%s\n",PetscGlobalRank,
     70:                                             petscstack->function[i],
     71:                                             petscstack->line[i],
     72:                                             petscstack->directory[i],
     73:                                             petscstack->file[i]);
     74:     }
     75:   }
     76:   return 0;
     77: }

     82: PetscErrorCode PETSC_DLLEXPORT PetscStackDestroy(void)
     83: {
     85:   if (petscstack){
     86:     PetscStack *petscstack_in = petscstack;
     87:     petscstack = 0;
     88:     PetscFree(petscstack_in);
     89:   }
     90:   return 0;
     91: }

     96: PetscErrorCode PETSC_DLLEXPORT PetscStackCopy(PetscStack* sint,PetscStack* sout)
     97: {
     98:   int i;

    100:   if (!sint) {
    101:     sout->currentsize = 0;
    102:   } else {
    103:     for (i=0; i<sint->currentsize; i++) {
    104:       sout->function[i]  = sint->function[i];
    105:       sout->file[i]      = sint->file[i];
    106:       sout->directory[i] = sint->directory[i];
    107:       sout->line[i]      = sint->line[i];
    108:     }
    109:     sout->currentsize = sint->currentsize;
    110:   }
    111:   return 0;
    112: }

    117: PetscErrorCode PETSC_DLLEXPORT PetscStackPrint(PetscStack* sint,FILE *fp)
    118: {
    119:   int i;

    121:   if (!sint) return(0);
    122:   for (i=sint->currentsize-3; i>=0; i--) {
    123:     fprintf(fp,"      [%d]  %s() line %d in %s%s\n",PetscGlobalRank,sint->function[i],sint->line[i],sint->directory[i],sint->file[i]);
    124:   }
    125:   return 0;
    126: }

    128: #else
    131: PetscErrorCode PETSC_DLLEXPORT PetscStackPublish(void)
    132: {
    134:   return(0);
    135: }
    138: PetscErrorCode PETSC_DLLEXPORT PetscStackDepublish(void)
    139: {
    141:   return(0);
    142: }
    145: PetscErrorCode PETSC_DLLEXPORT PetscStackCreate(void)
    146: {
    148:   return(0);
    149: }
    152: PetscErrorCode PETSC_DLLEXPORT PetscStackView(PetscViewer viewer)
    153: {
    155:   return(0);
    156: }
    159: PetscErrorCode PETSC_DLLEXPORT PetscStackDestroy(void)
    160: {
    162:   return(0);
    163: }

    165: #endif