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