Actual source code: pstack.c
petsc-3.3-p7 2013-05-11
2: #include <petscsys.h> /*I "petscsys.h" I*/
4: #if defined(PETSC_USE_DEBUG)
6: #if defined(PETSC_PTHREAD_LOCAL)
7: PETSC_PTHREAD_LOCAL PetscStack *petscstack = 0;
8: #else
9: PetscStack *petscstack = 0;
10: #endif
14: PetscErrorCode PetscStackPublish(void)
15: {
17: return(0);
18: }
22: PetscErrorCode PetscStackDepublish(void)
23: {
25: return(0);
26: }
27:
30: PetscErrorCode PetscStackCreate(void)
31: {
34: PetscStack *petscstack_in;
35: if (petscstack) return 0;
36:
37: PetscNew(PetscStack,&petscstack_in);
38: petscstack_in->currentsize = 0;
39: petscstack = petscstack_in;
40: PetscThreadLocalSetValue(petscstack,petscstack); /* Sets the value for the pthread_key_t if it is used */
41: return 0;
42: }
46: PetscErrorCode PetscStackView(PetscViewer viewer)
47: {
49: int i;
50: FILE *file;
52: if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
53: PetscViewerASCIIGetPointer(viewer,&file);
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: }
84: PetscErrorCode PetscStackDestroy(void)
85: {
87: if (petscstack){
88: PetscStack *petscstack_in = petscstack;
89: petscstack = 0;
90: PetscFree(petscstack_in);
91: PetscThreadLocalDestroy(petscstack); /* Deletes pthread_key if it was used */
92: }
93: return 0;
94: }
99: PetscErrorCode PetscStackCopy(PetscStack* sint,PetscStack* sout)
100: {
101: int i;
103: if (!sint) {
104: sout->currentsize = 0;
105: } else {
106: for (i=0; i<sint->currentsize; i++) {
107: sout->function[i] = sint->function[i];
108: sout->file[i] = sint->file[i];
109: sout->directory[i] = sint->directory[i];
110: sout->line[i] = sint->line[i];
111: }
112: sout->currentsize = sint->currentsize;
113: }
114: return 0;
115: }
120: PetscErrorCode PetscStackPrint(PetscStack* sint,FILE *fp)
121: {
122: int i;
124: if (!sint) return(0);
125: for (i=sint->currentsize-3; i>=0; i--) {
126: fprintf(fp," [%d] %s() line %d in %s%s\n",PetscGlobalRank,sint->function[i],sint->line[i],sint->directory[i],sint->file[i]);
127: }
128: return 0;
129: }
131: #else
134: PetscErrorCode PetscStackPublish(void)
135: {
137: return(0);
138: }
141: PetscErrorCode PetscStackDepublish(void)
142: {
144: return(0);
145: }
148: PetscErrorCode PetscStackCreate(void)
149: {
151: return(0);
152: }
155: PetscErrorCode PetscStackView(PetscViewer viewer)
156: {
158: return(0);
159: }
162: PetscErrorCode PetscStackDestroy(void)
163: {
165: return(0);
166: }
168: #endif