[petsc-users] Compatibility between PETSc typedefs and regular typedefs?

Justin Dong jsd1 at rice.edu
Sat Nov 23 00:40:39 CST 2013


I’m still trying to get the hang of PETSc but am adapting pretty well. I
was cleaning up some code I wrote today and realized that my function
prototype expects a pointer to a double but I accidentally gave it a
pointer to a PetscScalar instead. I didn't get any errors during compiling
or execution so I was just wondering if the two types are compatible. The
same goes for PetscInt and ints. Here's a minimal example below. Is this
considered a major error? I'm correcting it anyway but just wanted to
satisfy my curiosity.


#define A(i,j) A[ j + 5*i ]
#define b(i,j) b[ j + 5*i ]

void myFunction(double* A, int* b)
{

    int i, j;

    for (i=0; i<5, ++i)
    {
        for (j=0; j<5; ++j)
        {
            A(i,j) = sin(i+j);
            b(i,j)  = i+j;
        }
    }

}

int main(int argc, char **argv)
{

    PetscErrorCode ierr;

    ierr = PetscInitialize(&argc,&argv,(char*)0,help); CHKERRQ(ierr);
    PetscScalar* A;
    PetscInt* b;

    int n = 5;

    PetscMalloc(sizeof(PetscScalar)*n*n, &A);
    PetscMalloc(sizeof(PetscInt)*n*n, &b);

    myFunction(A, b);

    PetscFree(A);
    PetscFree(b);

    ierr = PetscFinalize();

    return 0;
}

Thanks,
Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131123/02fab39e/attachment.html>


More information about the petsc-users mailing list