1. Lisandro Dalcin
  2. PetIGA

Commits

Lisandro Dalcin  committed f785be3

Preallocate work arrays in IGAElement and IGAPoint

  • Participants
  • Parent commits 0828d5d
  • Branches default

Comments (0)

Files changed (2)

File src/petigaelem.c

View file
  • Ignore whitespace
 
   ierr = IGAElementFreeFix(element);CHKERRQ(ierr);
   ierr = IGAElementFreeWork(element);CHKERRQ(ierr);
+
   ierr = IGAPointReset(element->iterator);CHKERRQ(ierr);
+
   PetscFunctionReturn(0);
 }
 
     ierr = PetscMalloc1(nqp*nen*dim*dim*dim,&element->shape[3]);CHKERRQ(ierr);
   }
   { /* */
+    size_t MAX_WORK_VAL = sizeof(element->wval)/sizeof(PetscScalar*);
+    size_t MAX_WORK_VEC = sizeof(element->wvec)/sizeof(PetscScalar*);
+    size_t MAX_WORK_MAT = sizeof(element->wmat)/sizeof(PetscScalar*);
+    size_t i, n = element->nen * element->dof;
+    for (i=0; i<MAX_WORK_VAL; i++)
+      {ierr = PetscMalloc1(n,&element->wval[i]);CHKERRQ(ierr);}
+    for (i=0; i<MAX_WORK_VEC; i++)
+      {ierr = PetscMalloc1(n,&element->wvec[i]);CHKERRQ(ierr);}
+    for (i=0; i<MAX_WORK_MAT; i++)
+      {ierr = PetscMalloc1(n*n,&element->wmat[i]);CHKERRQ(ierr);}
+  }
+  { /* */
     PetscInt nen = element->nen;
     PetscInt dof = element->dof;
     element->nfix = 0;
     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call during element loop");
   {
     size_t MAX_WORK_VAL = sizeof(element->wval)/sizeof(PetscScalar*);
-    PetscInt n = element->nen * element->dof;
+    size_t n = (size_t)(element->nen * element->dof);
     if (PetscUnlikely(element->nval >= (PetscInt)MAX_WORK_VAL))
       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many work values requested");
-    if (PetscUnlikely(!element->wval[element->nval])) {
-      ierr = PetscMalloc1(n,&element->wval[element->nval]);CHKERRQ(ierr);
-    }
     *U = element->wval[element->nval++];
     ierr = PetscMemzero(*U,n*sizeof(PetscScalar));CHKERRQ(ierr);
   }
     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call during element loop");
   {
     size_t MAX_WORK_VEC = sizeof(element->wvec)/sizeof(PetscScalar*);
-    PetscInt m = element->neq * element->dof;
-    PetscInt n = element->nen * element->dof;
+    size_t m = (size_t)(element->neq * element->dof);
     if (PetscUnlikely(element->nvec >= (PetscInt)MAX_WORK_VEC))
       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many work vectors requested");
-    if (PetscUnlikely(!element->wvec[element->nvec])) {
-      ierr = PetscMalloc1(n,&element->wvec[element->nvec]);CHKERRQ(ierr);
-    }
     *V = element->wvec[element->nvec++];
     ierr = PetscMemzero(*V,m*sizeof(PetscScalar));CHKERRQ(ierr);
   }
     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call during element loop");
   {
     size_t MAX_WORK_MAT = sizeof(element->wmat)/sizeof(PetscScalar*);
-    PetscInt m = element->neq * element->dof;
-    PetscInt n = element->nen * element->dof;
+    size_t m = (size_t)(element->neq * element->dof);
+    size_t n = (size_t)(element->nen * element->dof);
     if (PetscUnlikely(element->nmat >= (PetscInt)MAX_WORK_MAT))
       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many work matrices requested");
-    if (PetscUnlikely(!element->wmat[element->nmat])) {
-      ierr = PetscMalloc1(n*n,&element->wmat[element->nmat]);CHKERRQ(ierr);
-    }
     *M = element->wmat[element->nmat++];
     ierr = PetscMemzero(*M,m*n*sizeof(PetscScalar));CHKERRQ(ierr);
   }

File src/petigapoint.c

View file
  • Ignore whitespace
   PetscValidPointer(element,2);
   ierr = IGAPointReset(point);CHKERRQ(ierr);
   point->parent = element;
+  point->neq = element->neq;
+  point->nen = element->nen;
+  point->dof = element->dof;
+  point->dim = element->dim;
+  point->nsd = element->nsd;
+  point->npd = element->npd;
+  { /* */
+    size_t MAX_WORK_VEC = sizeof(point->wvec)/sizeof(PetscScalar*);
+    size_t MAX_WORK_MAT = sizeof(point->wmat)/sizeof(PetscScalar*);
+    size_t i, n = point->nen * point->dof;
+    for (i=0; i<MAX_WORK_VEC; i++)
+      {ierr = PetscMalloc1(n,&point->wvec[i]);CHKERRQ(ierr);}
+    for (i=0; i<MAX_WORK_MAT; i++)
+      {ierr = PetscMalloc1(n*n,&point->wmat[i]);CHKERRQ(ierr);}
+  }
   PetscFunctionReturn(0);
 }
 
     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call during point loop");
   {
     size_t MAX_WORK_VEC = sizeof(point->wvec)/sizeof(PetscScalar*);
-    PetscInt m = point->neq * point->dof;
-    PetscInt n = point->nen * point->dof;
+    size_t m = (size_t)(point->neq * point->dof);
     if (PetscUnlikely(point->nvec >= (PetscInt)MAX_WORK_VEC))
       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many work vectors requested");
-    if (PetscUnlikely(!point->wvec[point->nvec])) {
-      ierr = PetscMalloc1(n,&point->wvec[point->nvec]);CHKERRQ(ierr);
-    }
     *V = point->wvec[point->nvec++];
     ierr = PetscMemzero(*V,m*sizeof(PetscScalar));CHKERRQ(ierr);
   }
     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call during point loop");
   {
     size_t MAX_WORK_MAT = sizeof(point->wmat)/sizeof(PetscScalar*);
-    PetscInt m = point->neq * point->dof;
-    PetscInt n = point->nen * point->dof;
+    size_t m = (size_t)(point->neq * point->dof);
+    size_t n = (size_t)(point->nen * point->dof);
     if (PetscUnlikely(point->nmat >= (PetscInt)MAX_WORK_MAT))
       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many work matrices requested");
-    if (PetscUnlikely(!point->wmat[point->nmat])) {
-      ierr = PetscMalloc1(n*n,&point->wmat[point->nmat]);CHKERRQ(ierr);
-    }
     *M = point->wmat[point->nmat++];
     ierr = PetscMemzero(*M,m*n*sizeof(PetscScalar));CHKERRQ(ierr);
   }