Commits

Lisandro Dalcin committed b5d8d61

Update after changes to malloc routines in petsc-dev

Comments (0)

Files changed (17)

   (!PETSC_VERSION_LT(MAJOR,MINOR,SUBMINOR))
 #endif
 
-#ifndef PetscMalloc1
-#define PetscMalloc1(m1,t1,r1) (PetscMalloc((m1)*sizeof(t1),(r1)))
+#ifndef PetscValidRealPointer
+#define PetscValidRealPointer PetscValidDoublePointer
 #endif
 
-#ifndef PetscValidRealPointer
-#define PetscValidRealPointer PetscValidDoublePointer
+#ifndef PetscMalloc1
+#define PetscMalloc1(m1,r1) \
+  PetscMalloc((m1)*sizeof(**(r1)),r1)
+#endif
+
+#ifndef PetscCalloc1
+#define PetscCalloc1(m1,r1) \
+  (PetscMalloc1((m1),r1) || PetscMemzero(*(r1),(m1)*sizeof(**(r1))))
 #endif
 
 /* ---------------------------------------------------------------- */
     SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,
              "Field number must be in range [0,%D], got %D",iga->dof-1,field);
   if (!iga->fieldname) {
-    ierr = PetscMalloc1(iga->dof+1,char*,&iga->fieldname);CHKERRQ(ierr);
+    ierr = PetscMalloc1(iga->dof+1,&iga->fieldname);CHKERRQ(ierr);
     ierr = PetscMemzero(iga->fieldname,(iga->dof+1)*sizeof(char*));CHKERRQ(ierr);
   }
   ierr = PetscStrallocpy(name,&fname);CHKERRQ(ierr);
   }
   ierr = IGACreateSubComms1D(iga,subcomms);CHKERRQ(ierr);
   for (i=0; i<dim; i++) {
-    ierr = PetscMalloc1(procs[i],PetscInt,&ranges[i]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(procs[i],&ranges[i]);CHKERRQ(ierr);
     ierr = MPI_Allgather(&width[i],1,MPIU_INT,ranges[i],1,MPIU_INT,subcomms[i]);CHKERRQ(ierr);
     ierr = MPI_Comm_free(&subcomms[i]);CHKERRQ(ierr);
   }
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidPointer(_axis,1);
-  ierr = PetscNew(struct _n_IGAAxis,_axis);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,_axis);CHKERRQ(ierr);
   (*_axis)->refct = 1; axis = *_axis;
 
   /* */
   axis->periodic = PETSC_FALSE;
   /* */
-  ierr = PetscMalloc1(2,PetscReal,&axis->U);CHKERRQ(ierr);
+  ierr = PetscMalloc1(2,&axis->U);CHKERRQ(ierr);
   axis->p = 0;
   axis->m = 1;
   axis->U[0] = -0.5;
   axis->U[1] = +0.5;
   /* */
-  ierr = PetscMalloc1(1,PetscInt,&axis->span);CHKERRQ(ierr);
+  ierr = PetscMalloc1(1,&axis->span);CHKERRQ(ierr);
   axis->nnp = 1;
   axis->nel = 1;
   axis->span[0] = 0;
 
   if (axis->m != 1) {
     ierr = PetscFree(axis->U);CHKERRQ(ierr);
-    ierr = PetscMalloc1(2,PetscReal,&axis->U);CHKERRQ(ierr);
+    ierr = PetscMalloc1(2,&axis->U);CHKERRQ(ierr);
   }
   axis->p = 0;
   axis->m = 1;
 
   if (axis->nel != 1) {
     ierr = PetscFree(axis->span);CHKERRQ(ierr);
-    ierr = PetscMalloc1(1,PetscInt,&axis->span);CHKERRQ(ierr);
+    ierr = PetscMalloc1(1,&axis->span);CHKERRQ(ierr);
   }
   axis->nnp = 1;
   axis->nel = 1;
   axis->p = base->p;
   axis->m = base->m;
   ierr = PetscFree(axis->U);CHKERRQ(ierr);
-  ierr = PetscMalloc1(axis->m+1,PetscReal,&axis->U);CHKERRQ(ierr);
+  ierr = PetscMalloc1(axis->m+1,&axis->U);CHKERRQ(ierr);
   ierr = PetscMemcpy(axis->U,base->U,(axis->m+1)*sizeof(PetscReal));CHKERRQ(ierr);
 
   axis->nnp = base->nnp;
   axis->nel = base->nel;
   ierr = PetscFree(axis->span);CHKERRQ(ierr);
-  ierr = PetscMalloc1(axis->nel,PetscInt,&axis->span);CHKERRQ(ierr);
+  ierr = PetscMalloc1(axis->nel,&axis->span);CHKERRQ(ierr);
   ierr = PetscMemcpy(axis->span,base->span,axis->nel*sizeof(PetscInt));CHKERRQ(ierr);
 
   PetscFunctionReturn(0);
   PetscFunctionBegin;
   PetscValidPointer(base,1);
   PetscValidPointer(axis,2);
-  ierr = PetscNew(struct _n_IGAAxis,axis);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,axis);CHKERRQ(ierr);
+  (*axis)->refct = 1;
   ierr = IGAAxisCopy(base,*axis);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   if (m != axis->m) {
     PetscReal *V;
-    ierr = PetscMalloc1(m+1,PetscReal,&V);CHKERRQ(ierr);
+    ierr = PetscMalloc1(m+1,&V);CHKERRQ(ierr);
     ierr = PetscFree(axis->U);CHKERRQ(ierr);
     axis->m = m;
     axis->U = V;
     PetscInt m = axis->m;
     PetscInt n = m - p - 1;
     axis->nel = IGA_SpanCount(n,p,axis->U);
-    ierr = PetscMalloc1(axis->nel,PetscInt,&axis->span);CHKERRQ(ierr);
+    ierr = PetscMalloc1(axis->nel,&axis->span);CHKERRQ(ierr);
     (void)IGA_SpanIndex(n,p,axis->U,axis->span);
   }
   if (nel)  *nel  = axis->nel;
   n = m - p - 1; /* last basis function index */
 
   if (m != axis->m) {
-    ierr = PetscMalloc1(m+1,PetscReal,&U);CHKERRQ(ierr);
+    ierr = PetscMalloc1(m+1,&U);CHKERRQ(ierr);
     ierr = PetscFree(axis->U);CHKERRQ(ierr);
     axis->m = m;
     axis->U = U;
 
   axis->nel = r;
   ierr = PetscFree(axis->span);CHKERRQ(ierr);
-  ierr = PetscMalloc1(axis->nel,PetscInt,&axis->span);CHKERRQ(ierr);
+  ierr = PetscMalloc1(axis->nel,&axis->span);CHKERRQ(ierr);
   for(i=0; i<axis->nel; i++) axis->span[i] = p + i*s;
 
   axis->nnp = axis->periodic ? n-C : n+1;
   n = m - p - 1; /* last basis function index */
 
   if (m != axis->m) {
-    ierr = PetscMalloc1(m+1,PetscReal,&U);CHKERRQ(ierr);
+    ierr = PetscMalloc1(m+1,&U);CHKERRQ(ierr);
     ierr = PetscFree(axis->U);CHKERRQ(ierr);
     axis->m = m;
     axis->U = U;
 
   axis->nel = r;
   ierr = PetscFree(axis->span);CHKERRQ(ierr);
-  ierr = PetscMalloc1(axis->nel,PetscInt,&axis->span);CHKERRQ(ierr);
+  ierr = PetscMalloc1(axis->nel,&axis->span);CHKERRQ(ierr);
   for(i=0; i<axis->nel; i++) axis->span[i] = p + i*s;
 
   axis->nnp = axis->periodic ? n-C : n+1;

src/petigabasis.c

   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidPointer(basis,3);
-  ierr = PetscNew(struct _n_IGABasis,basis);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,basis);CHKERRQ(ierr);
   (*basis)->refct = 1;
   PetscFunctionReturn(0);
 }
     ComputeBasis = 0;
   }
 
-  ierr = PetscMalloc1(nel,PetscInt,&offset);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nel,PetscReal,&detJ);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nqp,PetscReal,&weight);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nel*nqp,PetscReal,&point);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nel*nqp*nen*ndr,PetscReal,&value);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel,&offset);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel,&detJ);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nqp,&weight);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel*nqp,&point);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel*nqp*nen*ndr,&value);CHKERRQ(ierr);
   ierr = PetscMemzero(value,nel*nqp*nen*ndr*sizeof(PetscReal));CHKERRQ(ierr);
 
   for (iqp=0; iqp<nqp; iqp++) {
     PetscInt  o0 = offset[0], o1 = offset[nel-1];
     PetscInt  k0 = span[0],   k1 = span[nel-1];
     PetscReal u0 = U[k0],     u1 = U[k1+1];
-    ierr = PetscMalloc1(nen*ndr,PetscReal,&basis->bnd_value[0]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nen*ndr,PetscReal,&basis->bnd_value[1]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*ndr,&basis->bnd_value[0]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*ndr,&basis->bnd_value[1]);CHKERRQ(ierr);
     basis->bnd_offset[0] =  o0; basis->bnd_offset[1] =  o1;
     basis->bnd_detJ  [0] = 1.0; basis->bnd_detJ  [1] = 1.0;
     basis->bnd_weight[0] = 1.0; basis->bnd_weight[1] = 1.0;
   nen  = p+1;
   ndr  = d+1;
 
-  ierr = PetscMalloc1(nel,PetscInt,&offset);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nel,PetscReal,&detJ);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nqp,PetscReal,&weight);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nel*nqp,PetscReal,&point);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nel*nqp*nen*ndr,PetscReal,&value);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel,&offset);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel,&detJ);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nqp,&weight);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel*nqp,&point);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nel*nqp*nen*ndr,&value);CHKERRQ(ierr);
 
   for (iqp=0; iqp<nqp; iqp++) {
     weight[iqp] = 1.0;
   {
     PetscInt  k0 = p,    k1 = n;
     PetscReal u0 = U[p], u1 = U[n+1];
-    ierr = PetscMalloc1(nen*ndr,PetscReal,&basis->bnd_value[0]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nen*ndr,PetscReal,&basis->bnd_value[1]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*ndr,&basis->bnd_value[0]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*ndr,&basis->bnd_value[1]);CHKERRQ(ierr);
     basis->bnd_offset[0] = k0-p; basis->bnd_offset[1] =  k1-p;
     basis->bnd_detJ  [0] =  1.0; basis->bnd_detJ  [1] =   1.0;
     basis->bnd_weight[0] =  1.0; basis->bnd_weight[1] =   1.0;
   PetscValidScalarPointer(S,3);
   IGACheckSetUp(iga,1);
 
-  ierr = PetscMalloc2(n,PetscScalar,&localS,n,PetscScalar,&workS);CHKERRQ(ierr);
-  ierr = PetscMemzero(localS,n*sizeof(PetscScalar));CHKERRQ(ierr);
+  ierr = PetscCalloc1(n,&localS);CHKERRQ(ierr);
+  ierr = PetscMalloc1(n,&workS);CHKERRQ(ierr);
 
   /* Get local vector U and array */
   ierr = IGAGetLocalVecArray(iga,vecU,&localU,&arrayU);CHKERRQ(ierr);
   PetscFunctionBegin;
   PetscValidPointer(dm,1);
 
+#if PETSC_VERSION_LT(3,5,0)
   ierr = PetscNewLog(dm,DM_IGA,&dd);CHKERRQ(ierr);
+#else
+  ierr = PetscNewLog(dm,&dd);CHKERRQ(ierr);
+#endif
   dm->data = dd;
 
 #if PETSC_VERSION_LE(3,3,0)
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidPointer(_element,1);
-  ierr = PetscNew(struct _n_IGAElement,_element);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,_element);CHKERRQ(ierr);
   element = *_element;
   element->refct =  1;
   element->index = -1;
   }
   { /**/
     PetscInt nen = element->nen;
-    ierr = PetscMalloc1(nen,PetscInt,&element->mapping);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen,&element->mapping);CHKERRQ(ierr);
     if (!element->collocation) {
       element->neq = nen;
       element->rowmap = element->mapping;
     } else {
       element->neq = 1;
-      ierr = PetscMalloc1(1,PetscInt,&element->rowmap);CHKERRQ(ierr);
+      ierr = PetscMalloc1(1,&element->rowmap);CHKERRQ(ierr);
     }
     element->colmap = element->mapping;
   }
     PetscInt nen = element->nen;
     PetscInt nqp = element->nqp;
 
-    ierr = PetscMalloc1(nen,PetscReal,&element->rationalW);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nen*nsd,PetscReal,&element->geometryX);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nen*npd,PetscScalar,&element->propertyA);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen,&element->rationalW);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*nsd,&element->geometryX);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*npd,&element->propertyA);CHKERRQ(ierr);
 
-    ierr = PetscMalloc1(nqp*dim,PetscReal,&element->point);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp,PetscReal,&element->weight);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp,PetscReal,&element->detJac);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim,&element->point);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp,&element->weight);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp,&element->detJac);CHKERRQ(ierr);
 
-    ierr = PetscMalloc1(nqp*nen,PetscReal,&element->basis[0]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*nen*dim,PetscReal,&element->basis[1]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*nen*dim*dim,PetscReal,&element->basis[2]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*nen*dim*dim*dim,PetscReal,&element->basis[3]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen,&element->basis[0]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen*dim,&element->basis[1]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen*dim*dim,&element->basis[2]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen*dim*dim*dim,&element->basis[3]);CHKERRQ(ierr);
 
-    ierr = PetscMalloc1(nqp,PetscReal,&element->detX);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*dim*dim,PetscReal,&element->gradX[0]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*dim*dim,PetscReal,&element->gradX[1]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*dim*dim*dim,PetscReal,&element->hessX[0]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*dim*dim*dim,PetscReal,&element->hessX[1]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*dim*dim*dim*dim,PetscReal,&element->der3X[0]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*dim*dim*dim*dim,PetscReal,&element->der3X[1]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp,PetscReal,&element->detS);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*dim,PetscReal,&element->normal);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp,&element->detX);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim*dim,&element->gradX[0]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim*dim,&element->gradX[1]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim*dim*dim,&element->hessX[0]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim*dim*dim,&element->hessX[1]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim*dim*dim*dim,&element->der3X[0]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim*dim*dim*dim,&element->der3X[1]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp,&element->detS);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*dim,&element->normal);CHKERRQ(ierr);
 
-    ierr = PetscMalloc1(nqp*nen,PetscReal,&element->shape[0]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*nen*dim,PetscReal,&element->shape[1]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*nen*dim*dim,PetscReal,&element->shape[2]);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nqp*nen*dim*dim*dim,PetscReal,&element->shape[3]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen,&element->shape[0]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen*dim,&element->shape[1]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen*dim*dim,&element->shape[2]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nqp*nen*dim*dim*dim,&element->shape[3]);CHKERRQ(ierr);
   }
   { /* */
     PetscInt nen = element->nen;
     PetscInt dof = element->dof;
     element->nfix = 0;
-    ierr = PetscMalloc1(nen*dof,PetscInt,   &element->ifix);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nen*dof,PetscScalar,&element->vfix);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nen*dof,PetscScalar,&element->ufix);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*dof,&element->ifix);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*dof,&element->vfix);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*dof,&element->ufix);CHKERRQ(ierr);
     element->nflux = 0;
-    ierr = PetscMalloc1(nen*dof,PetscInt,   &element->iflux);CHKERRQ(ierr);
-    ierr = PetscMalloc1(nen*dof,PetscScalar,&element->vflux);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*dof,&element->iflux);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen*dof,&element->vflux);CHKERRQ(ierr);
   }
   ierr = IGAPointInit(element->iterator,element);CHKERRQ(ierr);
   PetscFunctionReturn(0);
     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,PetscScalar,&element->wval[element->nval]);CHKERRQ(ierr);
+      ierr = PetscMalloc1(n,&element->wval[element->nval]);CHKERRQ(ierr);
     }
     *U = element->wval[element->nval++];
     ierr = PetscMemzero(*U,n*sizeof(PetscScalar));CHKERRQ(ierr);
     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,PetscScalar,&element->wvec[element->nvec]);CHKERRQ(ierr);
+      ierr = PetscMalloc1(n,&element->wvec[element->nvec]);CHKERRQ(ierr);
     }
     *V = element->wvec[element->nvec++];
     ierr = PetscMemzero(*V,m*sizeof(PetscScalar));CHKERRQ(ierr);
     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,PetscScalar,&element->wmat[element->nmat]);CHKERRQ(ierr);
+      ierr = PetscMalloc1(n*n,&element->wmat[element->nmat]);CHKERRQ(ierr);
     }
     *M = element->wmat[element->nmat++];
     ierr = PetscMemzero(*M,m*n*sizeof(PetscScalar));CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidPointer(_form,1);
-  ierr = PetscNew(struct _n_IGAForm,_form);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,_form);CHKERRQ(ierr);
   (*_form)->refct = 1; form = *_form;
   /* */
   form->dof = -1;
-  ierr = PetscNew(struct _IGAFormOps,&form->ops);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,&form->ops);CHKERRQ(ierr);
   for (a=0; a<3; a++)
     for (s=0; s<2; s++) {
-      ierr = PetscNew(struct _IGAFormBC,&form->value[a][s]);CHKERRQ(ierr);
-      ierr = PetscNew(struct _IGAFormBC,&form->load [a][s]);CHKERRQ(ierr);
+      ierr = PetscCalloc1(1,&form->value[a][s]);CHKERRQ(ierr);
+      ierr = PetscCalloc1(1,&form->load [a][s]);CHKERRQ(ierr);
     }
   PetscFunctionReturn(0);
 }
   PetscFunctionBegin;
   PetscValidPointer(grid,9);
 
-  ierr = PetscNew(struct _n_IGA_Grid,grid);CHKERRQ(ierr);
+  ierr = PetscMalloc(sizeof(**grid),grid);CHKERRQ(ierr);
+  ierr = PetscMemzero(*grid,sizeof(**grid));CHKERRQ(ierr);
   g = *grid;
 
   g->comm = comm;
       PetscReal *U;
       ierr = PetscViewerBinaryRead(viewer,&p,1,PETSC_INT);CHKERRQ(ierr);
       ierr = PetscViewerBinaryRead(viewer,&m,1,PETSC_INT);CHKERRQ(ierr);
-      ierr = PetscMalloc1(m,PetscReal,&U);CHKERRQ(ierr);
+      ierr = PetscMalloc1(m,&U);CHKERRQ(ierr);
       ierr = PetscViewerBinaryRead(viewer,U,m,PETSC_REAL);CHKERRQ(ierr);
       ierr = IGAGetAxis(iga,i,&axis);CHKERRQ(ierr);
       ierr = IGAAxisInit(axis,p,m-1,U);CHKERRQ(ierr);CHKERRQ(ierr);
     const PetscScalar *Xw;
     ierr = VecGetSize(lvec,&n);CHKERRQ(ierr);
     n /= (nsd+1);
-    ierr = PetscMalloc1(n*nsd,PetscReal,&iga->geometryX);CHKERRQ(ierr);
-    ierr = PetscMalloc1(n,    PetscReal,&iga->rationalW);CHKERRQ(ierr);
+    ierr = PetscMalloc1(n*nsd,&iga->geometryX);CHKERRQ(ierr);
+    ierr = PetscMalloc1(n,    &iga->rationalW);CHKERRQ(ierr);
     X = iga->geometryX; W = iga->rationalW;
     ierr = VecGetArrayRead(lvec,&Xw);CHKERRQ(ierr);
     for (pos=0,a=0; a<n; a++) {
   {
     PetscInt n; const PetscScalar *A;
     ierr = VecGetSize(lvec,&n);CHKERRQ(ierr);
-    ierr = PetscMalloc1(n,PetscScalar,&iga->propertyA);CHKERRQ(ierr);
+    ierr = PetscMalloc1(n,&iga->propertyA);CHKERRQ(ierr);
     ierr = VecGetArrayRead(lvec,&A);CHKERRQ(ierr);
     ierr = PetscMemcpy(iga->propertyA,A,n*sizeof(PetscScalar));CHKERRQ(ierr);
     ierr = VecRestoreArrayRead(lvec,&A);CHKERRQ(ierr);
     {
       PetscInt i,j,k;
       PetscInt nnz = maxnnz,*indices=0,*ubrows=0,*ubcols=0;
-      ierr = PetscMalloc1(nnz,PetscInt,&indices);CHKERRQ(ierr);
+      ierr = PetscMalloc1(nnz,&indices);CHKERRQ(ierr);
+      #if PETSC_VERSION_LT(3,5,0)
       ierr = PetscMalloc2(bs,PetscInt,&ubrows,nnz*bs,PetscInt,&ubcols);CHKERRQ(ierr);
+      #else
+      ierr = PetscMalloc2(bs,&ubrows,nnz*bs,&ubcols);CHKERRQ(ierr);
+      #endif
       for (k=lstart[2]; k<lstart[2]+lwidth[2]; k++)
         for (j=lstart[1]; j<lstart[1]+lwidth[1]; j++)
           for (i=lstart[0]; i<lstart[0]+lwidth[0]; i++)
   if (aij || baij || sbaij) {
     PetscInt i,j,k;
     PetscInt nnz = maxnnz,*indices=0,*ubrows=0,*ubcols=0;PetscScalar *values=0;
+    #if PETSC_VERSION_LT(3,5,0)
     ierr = PetscMalloc2(nnz,PetscInt,&indices,nnz*bs*nnz*bs,PetscScalar,&values);CHKERRQ(ierr);
     ierr = PetscMalloc2(bs,PetscInt,&ubrows,nnz*bs,PetscInt,&ubcols);CHKERRQ(ierr);
+    #else
+    ierr = PetscMalloc2(nnz,&indices,nnz*bs*nnz*bs,&values);CHKERRQ(ierr);
+    ierr = PetscMalloc2(bs,&ubrows,nnz*bs,&ubcols);CHKERRQ(ierr);
+    #endif
     ierr = PetscMemzero(values,nnz*bs*nnz*bs*sizeof(PetscScalar));CHKERRQ(ierr);
     for (k=lstart[2]; k<lstart[2]+lwidth[2]; k++)
       for (j=lstart[1]; j<lstart[1]+lwidth[1]; j++)
     for (n=dof, i=0; i<dim; n *= (2*overlap[i++] + 1));
 
     ierr = PetscBLASIntCast(n,&m);CHKERRQ(ierr);
-    ierr = PetscMalloc2(n,PetscInt,&indices,n*n,PetscScalar,&values);CHKERRQ(ierr);
-    ierr = PetscMalloc1(m,PetscBLASInt,&ipiv);CHKERRQ(ierr);
+    ierr = PetscMalloc1(n,&indices);CHKERRQ(ierr);
+    ierr = PetscMalloc1(n*n,&values);CHKERRQ(ierr);
+    ierr = PetscMalloc1(m,&ipiv);CHKERRQ(ierr);
     lwork = -1; work = &lwkopt;
     LAPACKgetri_(&m,values,&m,ipiv,work,&lwork,&info);
     lwork = (info==0) ? (PetscBLASInt)work[0] : m*128;
-    ierr = PetscMalloc1(lwork,PetscScalar,&work);CHKERRQ(ierr);
+    ierr = PetscMalloc1(lwork,&work);CHKERRQ(ierr);
 
     for (k=start[2]; k<start[2]+width[2]; k++)
       for (j=start[1]; j<start[1]+width[1]; j++)
   PC_BBB         *bbb = 0;
   PetscErrorCode ierr;
   PetscFunctionBegin;
+#if PETSC_VERSION_LT(3,5,0)
   ierr = PetscNewLog(pc,PC_BBB,&bbb);CHKERRQ(ierr);
+#else
+  ierr = PetscNewLog(pc,&bbb);CHKERRQ(ierr);
+#endif
   pc->data = (void*)bbb;
 
   bbb->overlap[0] = PETSC_DECIDE;
           ierr = MatSetSizes(mat,m,n,M,N);CHKERRQ(ierr);
           ierr = MatSetBlockSize(mat,bs);CHKERRQ(ierr);
 
-          ierr = PetscMalloc1(ia[na],PetscInt,&newja);CHKERRQ(ierr);
+          ierr = PetscMalloc1(ia[na],&newja);CHKERRQ(ierr);
           for (j=0; j<ia[na]; j++) newja[j] = ja[j] + cstart;
           if (aij)   {ierr = MatMPIAIJSetPreallocationCSR  (mat,   ia,newja,NULL);CHKERRQ(ierr);}
           if (baij)  {ierr = MatMPIBAIJSetPreallocationCSR (mat,bs,ia,newja,NULL);CHKERRQ(ierr);}
 
     n = nen*dof;
     ierr = PetscBLASIntCast(n,&m);CHKERRQ(ierr);
-    ierr = PetscMalloc2(n,PetscInt,&indices,n*n,PetscScalar,&values);CHKERRQ(ierr);
-    ierr = PetscMalloc1(m,PetscBLASInt,&ipiv);CHKERRQ(ierr);
+    ierr = PetscMalloc1(n,&indices);CHKERRQ(ierr);
+    ierr = PetscMalloc1(n*n,&values);CHKERRQ(ierr);
+    ierr = PetscMalloc1(m,&ipiv);CHKERRQ(ierr);
     lwork = -1; work = &lwkopt;
     LAPACKgetri_(&m,values,&m,ipiv,work,&lwork,&info);
     lwork = (info==0) ? (PetscBLASInt)work[0] : m*128;
-    ierr = PetscMalloc1(lwork,PetscScalar,&work);CHKERRQ(ierr);
+    ierr = PetscMalloc1(lwork,&work);CHKERRQ(ierr);
 
     ierr = IGABeginElement(iga,&element);CHKERRQ(ierr);
     while (IGANextElement(iga,element)) {
   PC_EBE         *ebe = 0;
   PetscErrorCode ierr;
   PetscFunctionBegin;
+#if PETSC_VERSION_LT(3,5,0)
   ierr = PetscNewLog(pc,PC_EBE,&ebe);CHKERRQ(ierr);
+#else
+  ierr = PetscNewLog(pc,&ebe);CHKERRQ(ierr);
+#endif
   pc->data = (void*)ebe;
 
   pc->ops->setup               = PCSetUp_EBE;

src/petigapoint.c

   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidPointer(_point,3);
-  ierr = PetscNew(struct _n_IGAPoint,_point);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,_point);CHKERRQ(ierr);
   point = *_point;
   point->refct =  1;
   point->index = -1;
     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,PetscScalar,&point->wvec[point->nvec]);CHKERRQ(ierr);
+      ierr = PetscMalloc1(n,&point->wvec[point->nvec]);CHKERRQ(ierr);
     }
     *V = point->wvec[point->nvec++];
     ierr = PetscMemzero(*V,m*sizeof(PetscScalar));CHKERRQ(ierr);
     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,PetscScalar,&point->wmat[point->nmat]);CHKERRQ(ierr);
+      ierr = PetscMalloc1(n*n,&point->wmat[point->nmat]);CHKERRQ(ierr);
     }
     *M = point->wmat[point->nmat++];
     ierr = PetscMemzero(*M,m*n*sizeof(PetscScalar));CHKERRQ(ierr);
   PetscReal *basis[3];
   for(i=0;i<element->dim;i++){
     nen[i] = element->parent->axis[i]->p + 1;
-    ierr = PetscMalloc1(nen[i]*(order+1),PetscReal,&basis[i]);CHKERRQ(ierr);
+    ierr = PetscMalloc1(nen[i]*(order+1),&basis[i]);CHKERRQ(ierr);
     IGA_Basis_BSpline(element->parent->axis[i]->span[element->ID[i]],
 		      point->point[i],
 		      element->parent->axis[i]->p,
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidPointer(rule,1);
-  ierr = PetscNew(struct _n_IGARule,rule);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,rule);CHKERRQ(ierr);
   (*rule)->refct = 1;
   PetscFunctionReturn(0);
 }
   rule->nqp = base->nqp;
   ierr = PetscFree(rule->point);CHKERRQ(ierr);
   if (base->point && base->nqp > 0) {
-    ierr = PetscMalloc1(base->nqp,PetscReal,&rule->point);CHKERRQ(ierr);
+    ierr = PetscMalloc1(base->nqp,&rule->point);CHKERRQ(ierr);
     ierr = PetscMemcpy(rule->point,base->point,base->nqp*sizeof(PetscReal));CHKERRQ(ierr);
   }
   ierr = PetscFree(rule->weight);CHKERRQ(ierr);
   if (base->weight && base->nqp > 0) {
-    ierr = PetscMalloc1(base->nqp,PetscReal,&rule->weight);CHKERRQ(ierr);
+    ierr = PetscMalloc1(base->nqp,&rule->weight);CHKERRQ(ierr);
     ierr = PetscMemcpy(rule->weight,base->weight,base->nqp*sizeof(PetscReal));CHKERRQ(ierr);
   }
   PetscFunctionReturn(0);
   PetscFunctionBegin;
   PetscValidPointer(base,1);
   PetscValidPointer(rule,2);
-  ierr = PetscNew(struct _n_IGARule,rule);CHKERRQ(ierr);
+  ierr = PetscCalloc1(1,rule);CHKERRQ(ierr);
+  (*rule)->refct = 1;
   ierr = IGARuleCopy(base,*rule);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
   if (nqp < 1)
     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,
              "Number of quadrature points must be greater than zero, got %D",nqp);
-  ierr = PetscMalloc1(nqp,PetscReal,&point);CHKERRQ(ierr);
-  ierr = PetscMalloc1(nqp,PetscReal,&weight);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nqp,&point);CHKERRQ(ierr);
+  ierr = PetscMalloc1(nqp,&weight);CHKERRQ(ierr);
   if (GaussLegendreRule(nqp,point,weight) != 0)
     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,
              "Number of quadrature points %D not implemented",nqp);
   if (q < 1)
     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,
              "Number of quadrature points must be greater than zero, got %D",q);
-  ierr = PetscMalloc1(q,PetscReal,&xx);CHKERRQ(ierr);
-  ierr = PetscMalloc1(q,PetscReal,&ww);CHKERRQ(ierr);
+  ierr = PetscMalloc1(q,&xx);CHKERRQ(ierr);
+  ierr = PetscMalloc1(q,&ww);CHKERRQ(ierr);
   ierr = PetscMemcpy(xx,x,q*sizeof(PetscReal));CHKERRQ(ierr);
   ierr = PetscMemcpy(ww,w,q*sizeof(PetscReal));CHKERRQ(ierr);
   ierr = PetscFree(rule->point);CHKERRQ(ierr);
 #include <petscts2.h>
 #include <petsc-private/tsimpl.h>                /*I   "petscts.h"   I*/
 
-#if PETSC_VERSION_LE(3,3,0)
+#if PETSC_VERSION_LT(3,4,0)
 #define PetscObjectComposeFunction(o,n,f) \
         PetscObjectComposeFunction(o,n,"",(PetscVoidFunction)(f))
 #endif
   ierr = PetscObjectComposeFunction((PetscObject)ts,"TSGetSolution2_C",TSGetSolution2_Alpha2);CHKERRQ(ierr);
   ierr = PetscObjectComposeFunction((PetscObject)ts,"TSSolve2_C",TSSolve2_Alpha2);CHKERRQ(ierr);
 
+#if PETSC_VERSION_LT(3,5,0)
   ierr = PetscNewLog(ts,TS_Alpha2,&th);CHKERRQ(ierr);
+#else
+  ierr = PetscNewLog(ts,&th);CHKERRQ(ierr);
+#endif
   ts->data = (void*)th;
   th->Alpha_m = 0.5;
   th->Alpha_f = 0.5;

test/GeometryMap.c

 
   iga->rational = PETSC_TRUE;
   ierr = IGASetGeometryDim(iga,dim);CHKERRQ(ierr);
-  ierr = PetscMalloc1(3*3*(dim-1),    PetscReal,&iga->rationalW);CHKERRQ(ierr);
-  ierr = PetscMalloc1(3*3*(dim-1)*dim,PetscReal,&iga->geometryX);CHKERRQ(ierr);
+  ierr = PetscMalloc(3*3*(dim-1)*sizeof(PetscReal),&iga->rationalW);CHKERRQ(ierr);
+  ierr = PetscMalloc(3*3*(dim-1)*dim*sizeof(PetscReal),&iga->geometryX);CHKERRQ(ierr);
   {
     PetscInt i,j,k,m=dim-1;
     PetscInt posx=0,posw=0;