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

 20: int PetscStackPublish(void)
 21: {
 22: #if defined(PETSC_HAVE_AMS)
 23:   /*
 24:         Publishes the stack to AMS
 25:   */
 26:   int      ierr;
 27:   AMS_Comm acomm;

 30:   if (!petscstack) SETERRQ(1,"Stack not available to publish");
 31:   PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_WORLD,&acomm);
 32:   AMS_Memory_create(acomm,"stack_memory",&stack_mem);
 33: 
 34:   /* Add a field to the memory */
 35:   AMS_Memory_add_field(stack_mem,"stack",petscstack->function,petscstack->currentsize,
 36:                               AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);
 37: 
 38:   /* Publish the memory */
 39:   AMS_Memory_publish(stack_mem);
 40: #else
 42: #endif
 43:   return(0);
 44: }

 48: int PetscStackDepublish(void)
 49: {
 50: #if defined(PETSC_HAVE_AMS)

 54:   if (stack_mem >= 0) {
 55:     AMS_Memory_destroy(stack_mem);
 56:     stack_mem = -1;
 57:   }
 58: #else
 60: #endif
 61:   return(0);
 62: }
 63: 
 66: int PetscStackCreate(void)
 67: {

 70:   PetscStack *petscstack_in;
 71:   if (petscstack) return 0;
 72: 
 73:   PetscNew(PetscStack,&petscstack_in);
 74:   PetscMemzero(petscstack_in,sizeof(PetscStack));
 75:   petscstack_in->currentsize = 0;
 76:   petscstack = petscstack_in;

 78:   return 0;
 79: }

 83: int PetscStackView(PetscViewer viewer)
 84: {
 85:   int  i,ierr;
 86:   FILE *file;

 88:   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
 89:   PetscViewerASCIIGetPointer(viewer,&file);

 91:   if (file == stdout) {
 92:     (*PetscErrorPrintf)("Note: The EXACT line numbers in the stack are not available,\n");
 93:     (*PetscErrorPrintf)("      INSTEAD the line number of the start of the function\n");
 94:     (*PetscErrorPrintf)("      is given.\n");
 95:     for (i=petscstack->currentsize-1; i>=0; i--) {
 96:       (*PetscErrorPrintf)("[%d] %s line %d %s%s\n",PetscGlobalRank,
 97:                                                    petscstack->function[i],
 98:                                                    petscstack->line[i],
 99:                                                    petscstack->directory[i],
100:                                                    petscstack->file[i]);
101:     }
102:   } else {
103:     fprintf(file,"Note: The EXACT line numbers in the stack are not available,\n");
104:     fprintf(file,"      INSTEAD the line number of the start of the function\n");
105:     fprintf(file,"      is given.\n");
106:     for (i=petscstack->currentsize-1; i>=0; i--) {
107:       fprintf(file,"[%d] %s line %d %s%s\n",PetscGlobalRank,
108:                                             petscstack->function[i],
109:                                             petscstack->line[i],
110:                                             petscstack->directory[i],
111:                                             petscstack->file[i]);
112:     }
113:   }
114:   return 0;
115: }

120: int PetscStackDestroy(void)
121: {

124: #if defined(PETSC_HAVE_AMS)
125:   PetscStackDepublish();
126: #endif
127:   if (petscstack){
128:     PetscStack *petscstack_in = petscstack;
129:     petscstack = 0;
130:     PetscFree(petscstack_in);
131:   }
132:   return 0;
133: }

138: int PetscStackCopy(PetscStack* sint,PetscStack* sout)
139: {
140:   int i;

142:   if (!sint) {
143:     sout->currentsize = 0;
144:   } else {
145:     for (i=0; i<sint->currentsize; i++) {
146:       sout->function[i]  = sint->function[i];
147:       sout->file[i]      = sint->file[i];
148:       sout->directory[i] = sint->directory[i];
149:       sout->line[i]      = sint->line[i];
150:     }
151:     sout->currentsize = sint->currentsize;
152:   }
153:   return 0;
154: }

159: int PetscStackPrint(PetscStack* sint,FILE *fp)
160: {
161:   int i;

163:   if (!sint) return(0);
164:   for (i=sint->currentsize-3; i>=0; i--) {
165:     fprintf(fp,"      [%d]  %s() line %d in %s%s\n",PetscGlobalRank,sint->function[i],sint->line[i],
166:             sint->directory[i],sint->file[i]);
167:   }
168:   return 0;
169: }

171: #else
174: int PetscStackPublish(void)
175: {
177:   return(0);
178: }
181: int PetscStackDepublish(void)
182: {
184:   return(0);
185: }
188: int PetscStackCreate(void)
189: {
191:   return(0);
192: }
195: int PetscStackView(PetscViewer viewer)
196: {
198:   return(0);
199: }
202: int PetscStackDestroy(void)
203: {
205:   return(0);
206: }

208: #endif