Lisandro Dalcin avatar Lisandro Dalcin committed 7638672

ABI compatibility for debug and optimized builds

Comments (0)

Files changed (7)

include/petscerror.h

   do {                                                                \
     PetscStackPopNoCheck;                                             \
     return;} while (0)
+
+#else
+
+#if defined(PETSC_HAVE_PTHREADCLASSES)
+#if defined(PETSC_PTHREAD_LOCAL)
+PETSC_EXTERN PETSC_PTHREAD_LOCAL void *petscstack;
 #else
+PETSC_EXTERN PetscThreadKey petscstack;
+#endif
+#elif defined(PETSC_HAVE_OPENMP)
+PETSC_EXTERN void *petscstack;
+#pragma omp threadprivate(petscstack)
+#else
+PETSC_EXTERN void *petscstack;
+#endif
 
 #define PetscStackPushNoCheck(funct,petsc_routine) do {} while (0)
 #define PetscStackPopNoCheck                       do {} while (0)

src/sys/error/pstack.c

 #if defined(PETSC_HAVE_PTHREADCLASSES)
 #if defined(PETSC_PTHREAD_LOCAL)
 PETSC_PTHREAD_LOCAL PetscStack *petscstack = 0;
+#else
+PetscThreadKey petscstack;
 #endif
 #else
 PetscStack *petscstack = 0;
     PetscStack *petscstack_in;
     petscstack_in = (PetscStack*)PetscThreadLocalGetValue(petscstack);
     free(petscstack_in);
-    PetscThreadLocalSetValue((PetscThreadKey*)&petscstack,(PetscStack*)0);
-    PetscThreadLocalDestroy(petscstack); /* Deletes pthread_key if it was used */
+    PetscThreadLocalSetValue((PetscThreadKey*)&petscstack,NULL);
   }
   return 0;
 }
 
 #else
 
+#if defined(PETSC_HAVE_PTHREADCLASSES)
+#if defined(PETSC_PTHREAD_LOCAL)
+PETSC_PTHREAD_LOCAL void *petscstack = 0;
+#else
+PetscThreadKey petscstack;
+#endif
+#else
+void *petscstack = 0;
+#endif
+
 #undef __FUNCT__
 #define __FUNCT__ "PetscStackCreate"
 PetscErrorCode  PetscStackCreate(void)
 }
 #undef __FUNCT__
 #define __FUNCT__ "PetscStackView"
-PetscErrorCode  PetscStackView(FILE *file)
+PetscErrorCode  PetscStackView(PETSC_UNUSED FILE *file)
 {
   PetscFunctionBegin;
   PetscFunctionReturn(0);
   PetscFunctionBegin;
   PetscFunctionReturn(0);
 }
+#undef __FUNCT__
+#define __FUNCT__ "PetscStackCopy"
+PetscErrorCode  PetscStackCopy(PETSC_UNUSED void *sint,PETSC_UNUSED void *sout)
+{
+  PetscFunctionBegin;
+  PetscFunctionReturn(0);
+}
+#undef __FUNCT__
+#define __FUNCT__ "PetscStackPrint"
+PetscErrorCode  PetscStackPrint(PETSC_UNUSED void *sint,PETSC_UNUSED FILE *fp)
+{
+  PetscFunctionBegin;
+  PetscFunctionReturn(0);
+}
 
 #if defined(PETSC_HAVE_AMS)     /* AMS stack functions do nothing in optimized mode */
 void PetscStackAMSGrantAccess(void) {}

src/sys/memory/mtr.c

   TRfrags++;
 
 #if defined(PETSC_USE_DEBUG)
-  ierr = PetscStackCopy((PetscStack*)PetscThreadLocalGetValue(petscstack),&head->stack);CHKERRQ(ierr);
-  /* fix the line number to where the malloc() was called, not the PetscFunctionBegin; */
-  head->stack.line[head->stack.currentsize-2] = lineno;
+  if (PetscStackActive()) {
+    ierr = PetscStackCopy((PetscStack*)PetscThreadLocalGetValue(petscstack),&head->stack);CHKERRQ(ierr);
+    /* fix the line number to where the malloc() was called, not the PetscFunctionBegin; */
+    head->stack.line[head->stack.currentsize-2] = lineno;
+  }
 #endif
 
   /*
   *stack = &head->stack;
   PetscFunctionReturn(0);
 }
+#else
+#undef __FUNCT__
+#define __FUNCT__ "PetscMallocGetStack"
+PetscErrorCode  PetscMallocGetStack(void *ptr,void **stack)
+{
+  PetscFunctionBegin;
+  *stack = 0;
+  PetscFunctionReturn(0);
+}
 #endif
 
 #undef __FUNCT__

src/sys/objects/ftn-custom/zstart.c

   *ierr = PetscThreadCommInitializePackage();
   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:Calling PetscThreadCommInitialize()\n");return;}
 
+  PetscThreadLocalRegister((PetscThreadKey*)&petscstack); /* Creates pthread_key */
 #if defined(PETSC_USE_DEBUG)
-  PetscThreadLocalRegister((PetscThreadKey*)&petscstack); /* Creates petscstack_key if needed */
   *ierr = PetscStackCreate();
   if (*ierr) {(*PetscErrorPrintf)("PetscInitialize:PetscStackCreate()\n");return;}
 #endif

src/sys/objects/inherit.c

         ierr = PetscObjectName(h);CHKERRQ(ierr);
         {
 #if defined(PETSC_USE_DEBUG)
-        PetscStack *stack;
+        PetscStack *stack = 0;
         char       *create,*rclass;
 
         /* if the PETSc function the user calls is not a create then this object was NOT directly created by them */
         ierr = PetscMallocGetStack(h,&stack);CHKERRQ(ierr);
-        k    = stack->currentsize-2;
-        if (!all) {
-          k = 0;
-          while (!stack->petscroutine[k]) k++;
-          ierr = PetscStrstr(stack->function[k],"Create",&create);CHKERRQ(ierr);
-          if (!create) {
-            ierr = PetscStrstr(stack->function[k],"Get",&create);CHKERRQ(ierr);
+        if (stack) {
+          k = stack->currentsize-2;
+          if (!all) {
+            k = 0;
+            while (!stack->petscroutine[k]) k++;
+            ierr = PetscStrstr(stack->function[k],"Create",&create);CHKERRQ(ierr);
+            if (!create) {
+              ierr = PetscStrstr(stack->function[k],"Get",&create);CHKERRQ(ierr);
+            }
+            ierr = PetscStrstr(stack->function[k],h->class_name,&rclass);CHKERRQ(ierr);
+            if (!create) continue;
+            if (!rclass) continue;
           }
-          ierr = PetscStrstr(stack->function[k],h->class_name,&rclass);CHKERRQ(ierr);
-
-          if (!create) continue;
-          if (!rclass) continue;
         }
 #endif
 
 
 #if defined(PETSC_USE_DEBUG)
         ierr = PetscMallocGetStack(h,&stack);CHKERRQ(ierr);
-        for (j=k; j>=0; j--) {
-          fprintf(fd,"      [%d]  %s() in %s%s\n",PetscGlobalRank,stack->function[j],stack->directory[j],stack->file[j]);
+        if (stack) {
+          for (j=k; j>=0; j--) {
+            fprintf(fd,"      [%d]  %s() in %s%s\n",PetscGlobalRank,stack->function[j],stack->directory[j],stack->file[j]);
+          }
         }
 #endif
         }

src/sys/objects/pinit.c

 PetscBool PetscPreLoadingUsed = PETSC_FALSE;
 PetscBool PetscPreLoadingOn   = PETSC_FALSE;
 
-/* pthread_key for PetscStack */
-#if defined(PETSC_HAVE_PTHREADCLASSES) && !defined(PETSC_PTHREAD_LOCAL)
-pthread_key_t petscstack;
-#endif
-
 /*
        Checks the options database for initializations related to the
     PETSc components
   /*
       Setup building of stack frames for all function calls
   */
+  PetscThreadLocalRegister((PetscThreadKey*)&petscstack); /* Creates pthread_key */
 #if defined(PETSC_USE_DEBUG)
-  PetscThreadLocalRegister((PetscThreadKey*)&petscstack); /* Creates petscstack_key if needed */
   ierr = PetscStackCreate();CHKERRQ(ierr);
 #endif
 
   ierr = PetscObjectRegisterDestroyAll();CHKERRQ(ierr);
 
   ierr = PetscStackDestroy();CHKERRQ(ierr);
+  PetscThreadLocalDestroy((PetscThreadKey)petscstack); /* Deletes pthread_key */
 
   flg1 = PETSC_FALSE;
   ierr = PetscOptionsGetBool(NULL,"-no_signal_handler",&flg1,NULL);CHKERRQ(ierr);

src/sys/threadcomm/interface/threadcomm.c

 
 #if defined(PETSC_USE_DEBUG)
 
-PetscErrorCode PetscThreadCommStackCreate_kernel(PetscInt trank)
+static PetscErrorCode PetscThreadCommStackCreate_kernel(PetscInt trank)
 {
-  PetscStack *petscstack_in;
-  if (!trank && PetscStackActive()) return 0;
-
-  petscstack_in              = (PetscStack*)malloc(sizeof(PetscStack));
-  petscstack_in->currentsize = 0;
-  PetscThreadLocalSetValue((PetscThreadKey*)&petscstack,petscstack_in);
+  if (trank && !PetscStackActive()) {
+    PetscStack *petscstack_in;
+    petscstack_in = (PetscStack*)malloc(sizeof(PetscStack));
+    petscstack_in->currentsize = 0;
+    PetscThreadLocalSetValue((PetscThreadKey*)&petscstack,petscstack_in);
+  }
   return 0;
 }
 
 PetscErrorCode  PetscThreadCommStackCreate(void)
 {
   PetscErrorCode ierr;
-
   ierr = PetscThreadCommRunKernel0(PETSC_COMM_SELF,(PetscThreadKernel)PetscThreadCommStackCreate_kernel);CHKERRQ(ierr);
   ierr = PetscThreadCommBarrier(PETSC_COMM_SELF);CHKERRQ(ierr);
   return 0;
 }
 
-PetscErrorCode PetscThreadCommStackDestroy_kernel(PetscInt trank)
+static PetscErrorCode PetscThreadCommStackDestroy_kernel(PetscInt trank)
 {
   if (trank && PetscStackActive()) {
     PetscStack *petscstack_in;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.