See http://www.mcs.anl.gov/petsc/petsc-current/include/petscsys.h.html#PetscMalloc2 , ligne 566 :
#if defined(PETSC_USE_DEBUG)
#define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
#else
#define PetscMalloc2(m1,t1,r1,m2,t2,r2) ((*(r2) = 0,PetscMalloc((m1)*sizeof(t1) (m2)*sizeof(t2)+(PETSC_MEMALIGN-1),r1)) || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),0))
#endif
If you are in debug mode, PetscMalloc2
is equivalent to two PetscMalloc
.
Otherwise PetscMalloc2
ensures that both buffers are one after another in memory, with a little space due to memory alignement. http://en.wikipedia.org/wiki/Data_structure_alignment Allocation through PetscMalloc
be called only once, which would be better if you call this function a large number of times in your code. If you call it once in a while, it won't change much !
Bye,