1 2 #include <petscsys.h> /*I "petscsys.h" I*/ 3 4 #if defined(PETSC_USE_DEBUG) 5 6 #if defined(PETSC_ThreadLocal) 7 PETSC_ThreadLocal PetscStack *petscstack = 0; 8 #else 9 PetscStack *petscstack = 0; 10 #endif 11 12 #undef __FUNCT__ 13 #define __FUNCT__ "PetscStackPublish" 14 PetscErrorCode PetscStackPublish(void) 15 { 16 PetscFunctionBegin; 17 PetscFunctionReturn(0); 18 } 19 20 #undef __FUNCT__ 21 #define __FUNCT__ "PetscStackDepublish" 22 PetscErrorCode PetscStackDepublish(void) 23 { 24 PetscFunctionBegin; 25 PetscFunctionReturn(0); 26 } 27 28 #undef __FUNCT__ 29 #define __FUNCT__ "PetscStackCreate" 30 PetscErrorCode PetscStackCreate(void) 31 { 32 PetscErrorCode ierr; 33 34 PetscStack *petscstack_in; 35 if (petscstack) return 0; 36 37 ierr = PetscNew(PetscStack,&petscstack_in);CHKERRQ(ierr); 38 petscstack_in->currentsize = 0; 39 petscstack = petscstack_in; 40 41 return 0; 42 } 43 44 #undef __FUNCT__ 45 #define __FUNCT__ "PetscStackView" 46 PetscErrorCode PetscStackView(PetscViewer viewer) 47 { 48 PetscErrorCode ierr; 49 int i; 50 FILE *file; 51 52 if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF; 53 ierr = PetscViewerASCIIGetPointer(viewer,&file);CHKERRQ(ierr); 54 55 if (file == PETSC_STDOUT) { 56 (*PetscErrorPrintf)("Note: The EXACT line numbers in the stack are not available,\n"); 57 (*PetscErrorPrintf)(" INSTEAD the line number of the start of the function\n"); 58 (*PetscErrorPrintf)(" is given.\n"); 59 for (i=petscstack->currentsize-1; i>=0; i--) { 60 (*PetscErrorPrintf)("[%d] %s line %d %s%s\n",PetscGlobalRank, 61 petscstack->function[i], 62 petscstack->line[i], 63 petscstack->directory[i], 64 petscstack->file[i]); 65 } 66 } else { 67 fprintf(file,"Note: The EXACT line numbers in the stack are not available,\n"); 68 fprintf(file," INSTEAD the line number of the start of the function\n"); 69 fprintf(file," is given.\n"); 70 for (i=petscstack->currentsize-1; i>=0; i--) { 71 fprintf(file,"[%d] %s line %d %s%s\n",PetscGlobalRank, 72 petscstack->function[i], 73 petscstack->line[i], 74 petscstack->directory[i], 75 petscstack->file[i]); 76 } 77 } 78 return 0; 79 } 80 81 #undef __FUNCT__ 82 #define __FUNCT__ "PetscStackDestroy" 83 /* PetscFunctionBegin; so that make rule checkbadPetscFunctionBegin works */ 84 PetscErrorCode PetscStackDestroy(void) 85 { 86 PetscErrorCode ierr; 87 if (petscstack){ 88 PetscStack *petscstack_in = petscstack; 89 petscstack = 0; 90 ierr = PetscFree(petscstack_in);CHKERRQ(ierr); 91 } 92 return 0; 93 } 94 95 #undef __FUNCT__ 96 #define __FUNCT__ "PetscStackCopy" 97 /* PetscFunctionBegin; so that make rule checkbadPetscFunctionBegin works */ 98 PetscErrorCode PetscStackCopy(PetscStack* sint,PetscStack* sout) 99 { 100 int i; 101 102 if (!sint) { 103 sout->currentsize = 0; 104 } else { 105 for (i=0; i<sint->currentsize; i++) { 106 sout->function[i] = sint->function[i]; 107 sout->file[i] = sint->file[i]; 108 sout->directory[i] = sint->directory[i]; 109 sout->line[i] = sint->line[i]; 110 } 111 sout->currentsize = sint->currentsize; 112 } 113 return 0; 114 } 115 116 #undef __FUNCT__ 117 #define __FUNCT__ "PetscStackPrint" 118 /* PetscFunctionBegin; so that make rule checkbadPetscFunctionBegin works */ 119 PetscErrorCode PetscStackPrint(PetscStack* sint,FILE *fp) 120 { 121 int i; 122 123 if (!sint) return(0); 124 for (i=sint->currentsize-3; i>=0; i--) { 125 fprintf(fp," [%d] %s() line %d in %s%s\n",PetscGlobalRank,sint->function[i],sint->line[i],sint->directory[i],sint->file[i]); 126 } 127 return 0; 128 } 129 130 #else 131 #undef __FUNCT__ 132 #define __FUNCT__ "PetscStackPublish" 133 PetscErrorCode PetscStackPublish(void) 134 { 135 PetscFunctionBegin; 136 PetscFunctionReturn(0); 137 } 138 #undef __FUNCT__ 139 #define __FUNCT__ "PetscStackDepublish" 140 PetscErrorCode PetscStackDepublish(void) 141 { 142 PetscFunctionBegin; 143 PetscFunctionReturn(0); 144 } 145 #undef __FUNCT__ 146 #define __FUNCT__ "PetscStackCreate" 147 PetscErrorCode PetscStackCreate(void) 148 { 149 PetscFunctionBegin; 150 PetscFunctionReturn(0); 151 } 152 #undef __FUNCT__ 153 #define __FUNCT__ "PetscStackView" 154 PetscErrorCode PetscStackView(PetscViewer viewer) 155 { 156 PetscFunctionBegin; 157 PetscFunctionReturn(0); 158 } 159 #undef __FUNCT__ 160 #define __FUNCT__ "PetscStackDestroy" 161 PetscErrorCode PetscStackDestroy(void) 162 { 163 PetscFunctionBegin; 164 PetscFunctionReturn(0); 165 } 166 167 #endif 168 169