[petsc-users] calloc with MPI and PetSc
Sanjay Kharche
Sanjay.Kharche at manchester.ac.uk
Tue Feb 3 08:21:26 CST 2015
Dear All
I have a code in C that uses Petsc and MPI. My code is an extension of ex15.c in the ts tutorials.
I am trying to allocate memory for 3 int arrays, for which I have already declared int pointers. These arrays are not intended for use by the petsc functions. I am allocating memory using calloc. The use of 1 calloc call is fine, however when I try to allocate memory for 2 or more arrays, the TSSolve(ts,u) gives an error. I found this by including and excluding the TSSolve call. I have tried making the array pointers PetscInt but with same result. The first few lines of the error message are also pasted after the relevant code snippet. Can you let me know how I can allocate memory for 3 arrays. These arrays are not relevant to any petsc functions.
thanks
Sanjay
Relevant code in main():
PetscInt size = 0; /* Petsc/MPI */
PetscInt rank = 0;
int *usr_mybase; // mybase, myend, myblocksize are to be used in non-petsc part of code.
int *usr_myend;
int *usr_myblocksize;
int R_base, transit;
MPI_Status status;
MPI_Request request;
/*********************************end of declarations in main************************/
PetscInitialize(&argc,&argv,(char*)0,help);
/* Initialize user application context */
user.da = NULL;
user.boundary = 1; /* 0: Drichlet BC; 1: Neumann BC */
user.viewJacobian = PETSC_FALSE;
MPI_Comm_size(PETSC_COMM_WORLD, &size);
MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
printf("my size is %d, and rank is %d\n",size, rank);
usr_mybase = (int*) calloc (size,sizeof(int)); // 1st call to calloc is ok.
// usr_myend = (int*) calloc (size,sizeof(int)); // when I uncomment this call to calloc, TSSolve fails. error below.
// usr_myblocksize = (int*) calloc (size,sizeof(int));
.
.
.
TSSolve(ts,u); // has a problem when I use 2 callocs.
The output and error message:
mpiexec -n 4 ./sk2d -draw_pause .1 -ts_monitor_draw_solution
my size is 4, and rank is 2
my size is 4, and rank is 0
my size is 4, and rank is 3
my size is 4, and rank is 1
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR: Floating point exception
[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[1]PETSC ERROR: Floating point exception
[1]PETSC ERROR: Vec entry at local location 320 is not-a-number or infinite at beginning of function: Parameter number 2
[1]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
[2]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[2]PETSC ERROR: Floating point exception
[2]PETSC ERROR: Vec entry at local location 10 is not-a-number or infinite at beginning of function: Parameter number 2
[2]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
[2]PETSC ERROR: Petsc Release Version 3.5.2, unknown
[3]PETSC ERROR: [0]PETSC ERROR: Vec entry at local location 293 is not-a-number or infinite at beginning of function: Parameter number 2
More information about the petsc-users
mailing list