<div dir="ltr">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.<div>
<br></div><div><br></div><div>#define A(i,j) A[ j + 5*i ]</div><div>#define b(i,j) b[ j + 5*i ]</div><div><br></div><div>void myFunction(double* A, int* b)</div><div>{</div><div><br></div><div> int i, j;</div><div><br>
</div><div> for (i=0; i<5, ++i)</div><div> {</div><div> for (j=0; j<5; ++j)</div><div> {</div><div> A(i,j) = sin(i+j);</div><div> b(i,j) = i+j;</div><div> }</div><div>
}</div><div><br></div><div>}</div><div><br></div><div>int main(int argc, char **argv)</div><div>{</div><div><br></div><div> PetscErrorCode ierr;</div><div><br></div><div> ierr = PetscInitialize(&argc,&argv,(char*)0,help); CHKERRQ(ierr);</div>
<div> PetscScalar* A;</div><div> PetscInt* b;</div><div><br></div><div>
int n = 5;</div><div><br></div><div> PetscMalloc(sizeof(PetscScalar)*n*n, &A);</div><div> PetscMalloc(sizeof(PetscInt)*n*n, &b);</div><div><br></div><div> myFunction(A, b);</div><div><br></div><div> PetscFree(A);</div>
<div> PetscFree(b);</div><div><br></div><div> ierr = PetscFinalize();</div><div><br></div><div> return 0;</div><div>}</div><div><br></div><div>Thanks, </div><div>Justin</div></div>