Actual source code: stack.c

  1: #define PETSC_DLL

 3:  #include petscsys.h

  5: #if defined(PETSC_USE_DEBUG)

  7: PetscStack  *petscstack = 0;

 11: PetscErrorCode  PetscStackPublish(void)
 12: {
 14:   return(0);
 15: }

 19: PetscErrorCode  PetscStackDepublish(void)
 20: {
 22:   return(0);
 23: }
 24: 
 27: PetscErrorCode  PetscStackCreate(void)
 28: {

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

 38:   return 0;
 39: }

 43: PetscErrorCode  PetscStackView(PetscViewer viewer)
 44: {
 46:   int  i;
 47:   FILE *file;

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

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

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

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

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

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

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

127: #else
130: PetscErrorCode  PetscStackPublish(void)
131: {
133:   return(0);
134: }
137: PetscErrorCode  PetscStackDepublish(void)
138: {
140:   return(0);
141: }
144: PetscErrorCode  PetscStackCreate(void)
145: {
147:   return(0);
148: }
151: PetscErrorCode  PetscStackView(PetscViewer viewer)
152: {
154:   return(0);
155: }
158: PetscErrorCode  PetscStackDestroy(void)
159: {
161:   return(0);
162: }

164: #endif