array pointer change after calling FORTRAN subroutine in C++
Qianqian Fang
fangqq@gmail.com
Sun Oct 23 04:53:00 GMT 2011
hi
I am working on a library written in F90 and compiled
by gfortran. Now I am trying to write a C++ header to
use the fortran library (.so/.a). I am very new to interfacing
C/Fortran and found a strange issue when calling the
fortran code:
Here is a sample of my header file: DBLQMRPrep
is a function defined in a fortran module:
...
#define DBLQMRPrep __blit_blqmr_real_MOD_blqmrprep
extern void DBLQMRPrep(BLQMRSolver *qmr, int *Ap, double *Ax, int *nz);
template <class T>
class MyClass{
DBLQMRPrep qmr;
int *Ap;
T *Ax;
public:
void Prepare(int *App, T *Axx, int nz){
Ap=App; Ax=Axx;
printf("%XL",(unsigned long)Ap);
DBLQMRPrep(&qmr,Ap,Ax,&nz); // here I call FORTRAN
printf("%XL",(unsigned long)Ap);
}
}
You see I put two printf in the Prepare() function,
I found that the pointer addresses for Ap/Ax
became different after calling DBLQMRPrep().
Inside the fortran function, the arrays Ap/Ax are
automatic(or dynamic) arrays. Something like:
subroutine BLQMRPrep(this, Ap, Ax, nnz)
implicit none
type(BLQMRSolver), intent(inout) :: this
integer, intent(in) :: nnz, Ap(this%n+1)
MTYPE(kind=Kdouble), intent(in) :: Ax(nnz)
...
Can someone explain to me what happened after
calling DBLQMRPrep()? how can I prevent FORTRAN to
mess up with the array pointer?
thanks
Qianqian
More information about the Fortran
mailing list