Actual source code: stack.c
1: /*$Id: stack.c,v 1.35 2001/09/07 20:08:25 bsmith Exp $*/
3: #include petsc.h
4: #include petscsys.h
6: #if defined(PETSC_USE_STACK)
8: PetscStack *petscstack = 0;
10: #if defined(PETSC_HAVE_AMS)
11: /* AMS Variables */
12: AMS_Memory stack_mem = -1;
13: AMS_Comm Petsc_AMS_Comm = -1;
14: int stack_err;
15: char *msg;
16: #endif
18: int PetscStackPublish(void)
19: {
20: #if defined(PETSC_HAVE_AMS)
21: /*
22: Publishes the stack to AMS
23: */
24: int ierr;
25: AMS_Comm acomm;
28: if (!petscstack) SETERRQ(1,"Stack not available to publish");
29: PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_WORLD,&acomm);
30: AMS_Memory_create(acomm,"stack_memory",&stack_mem);
31:
32: /* Add a field to the memory */
33: AMS_Memory_add_field(stack_mem,"stack",petscstack->function,petscstack->currentsize,
34: AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);
35:
36: /* Publish the memory */
37: AMS_Memory_publish(stack_mem);
38: #else
40: #endif
41: return(0);
42: }
44: int PetscStackDepublish(void)
45: {
46: #if defined(PETSC_HAVE_AMS)
50: if (stack_mem >= 0) {
51: ierr = AMS_Memory_destroy(stack_mem);
52: stack_mem = -1;
53: }
54: #else
56: #endif
57: return(0);
58: }
59:
60: int PetscStackCreate(void)
61: {
64: PetscStack *petscstack_in;
65: if (petscstack) return 0;
66:
67: PetscNew(PetscStack,&petscstack_in);
68: PetscMemzero(petscstack_in,sizeof(PetscStack));
69: petscstack_in->currentsize = 0;
70: petscstack = petscstack_in;
72: return 0;
73: }
75: int PetscStackView(PetscViewer viewer)
76: {
77: int i,ierr;
78: FILE *file;
80: if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
81: PetscViewerASCIIGetPointer(viewer,&file);
83: if (file == stdout) {
84: (*PetscErrorPrintf)("Note: The EXACT line numbers in the stack are not available,n");
85: (*PetscErrorPrintf)(" INSTEAD the line number of the start of the functionn");
86: (*PetscErrorPrintf)(" is given.n");
87: for (i=petscstack->currentsize-1; i>=0; i--) {
88: (*PetscErrorPrintf)("[%d] %s line %d %s%sn",PetscGlobalRank,
89: petscstack->function[i],
90: petscstack->line[i],
91: petscstack->directory[i],
92: petscstack->file[i]);
93: }
94: } else {
95: fprintf(file,"Note: The EXACT line numbers in the stack are not available,n");
96: fprintf(file," INSTEAD the line number of the start of the functionn");
97: fprintf(file," is given.n");
98: for (i=petscstack->currentsize-1; i>=0; i--) {
99: fprintf(file,"[%d] %s line %d %s%sn",PetscGlobalRank,
100: petscstack->function[i],
101: petscstack->line[i],
102: petscstack->directory[i],
103: petscstack->file[i]);
104: }
105: }
106: return 0;
107: }
110: int PetscStackDestroy(void)
111: {
114: #if defined(PETSC_HAVE_AMS)
115: PetscStackDepublish();
116: #endif
117: if (petscstack){
118: PetscStack *petscstack_in = petscstack;
119: petscstack = 0;
120: PetscFree(petscstack_in);
121: }
122: return 0;
123: }
126: int PetscStackCopy(PetscStack* sint,PetscStack* sout)
127: {
128: int i;
130: if (!sint) {
131: sout->currentsize = 0;
132: } else {
133: for (i=0; i<sint->currentsize; i++) {
134: sout->function[i] = sint->function[i];
135: sout->file[i] = sint->file[i];
136: sout->directory[i] = sint->directory[i];
137: sout->line[i] = sint->line[i];
138: }
139: sout->currentsize = sint->currentsize;
140: }
141: return 0;
142: }
145: int PetscStackPrint(PetscStack* sint,FILE *fp)
146: {
147: int i;
149: if (!sint) return(0);
150: for (i=sint->currentsize-3; i>=0; i--) {
151: fprintf(fp," [%d] %s() line %d in %s%sn",PetscGlobalRank,sint->function[i],sint->line[i],
152: sint->directory[i],sint->file[i]);
153: }
154: return 0;
155: }
157: #else
158: int PetscStackPublish(void)
159: {
161: return(0);
162: }
163: int PetscStackDepublish(void)
164: {
166: return(0);
167: }
168: int PetscStackCreate(void)
169: {
171: return(0);
172: }
173: int PetscStackView(PetscViewer viewer)
174: {
176: return(0);
177: }
178: int PetscStackDestroy(void)
179: {
181: return(0);
182: }
184: #endif