residualVector pointer in Fortran interface

General CULA Sparse support and troubleshooting. Use this forum if you are having a general problem or have encountered a bug.

residualVector pointer in Fortran interface

Postby alpertdn » Thu Mar 01, 2012 2:22 pm

Hi,
I'm using CULA Sparse S2 within a 64 bit Ubuntu 10.04 OS and CUDA Toolkit 4.1.

I'm testing to see if I can capture the residualVector within a Fortran code but the interface in cula_sparse.F90 seems to implement the interface in a way that doesn't correspond with the Fortran standard.

The module specifies CULA_ITERATIVE_CONFIG%residualVector as a DOUBLE PRECISION, POINTER. In order to capture the array of residuals correctly, I would need the pointer to associate with an target array of dimension at least CULA_ITERATIVE_CONFIG%maxIterations.
A temporary workaround I found was to point the residualVector to the first element in my target array but I thought according to the Fortran standards that I should instead point to the entire target array.

I unsuccessfully tried upgrading the cula_sparse module to Fortran 2003 standards using ISO_C_BINDING.

I then tried simply editing the cula_sparse.F90 interface to include the shape of the residualVector by changing line 15 to become:
Code: Select all
      DOUBLE PRECISION, POINTER, DIMENSION(:) :: residualVector

I then pointed the residualVector to my entire target array but this produced errors such as changing CULA_ITERATIVE_CONFIG%debug and producing an incorrect CULA_ITERATIVE_RESULT%iterations.

I know there may be some interoperability issues here with C pointers. Will the next version of CULA include a Fortran 2003/2008 version of cula and cula_sparse interface modules that utilizes the ISO_C_BINDING?

On a side note, I found that cula_sparse.F90 has interfaces for all the solvers you list in your documentation except for the DOUBLE PRECISION versions of the BICGSTAB algorithms.

Thanks for your help.
alpertdn
 
Posts: 1
Joined: Thu Jan 05, 2012 12:38 pm

Re: residualVector pointer in Fortran interface

Postby john » Fri Mar 02, 2012 2:09 pm

I think it's unlikely we'll convert the sparse module to ISO_C_BINDING, which we only found really necessary for using CUDA Device pointers (which are not used in the CULA Sparse interface at present).

You did however point us towards a problem; here is the fix:

In your module file, phrase the line as:
Code: Select all
DOUBLE PRECISION, POINTER :: residualVector(:)


Then in your code:
Code: Select all
DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE, TARGET :: residual
ALLOCATE(residual(maxIterations)) ! be sure the length is at least config%maxIterations
config%residualVector => residual


Then when the solver completes, residual(1) to residual(res%iterations) will contain your values.

I tested this under gfortran 4.4.
john
Administrator
 
Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

Re: residualVector pointer in Fortran interface

Postby baklazanek » Thu Jun 20, 2013 4:01 am

john wrote:I think it's unlikely we'll convert the sparse module to ISO_C_BINDING, which we only found really necessary for using CUDA Device pointers (which are not used in the CULA Sparse interface at present).

You did however point us towards a problem; here is the fix:

In your module file, phrase the line as:
Code: Select all
DOUBLE PRECISION, POINTER :: residualVector(:)


Then in your code:
Code: Select all
DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE, TARGET :: residual
ALLOCATE(residual(maxIterations)) ! be sure the length is at least config%maxIterations
config%residualVector => residual


Then when the solver completes, residual(1) to residual(res%iterations) will contain your values.

I tested this under gfortran 4.4.


Thank you John! :D
Image
baklazanek
 
Posts: 1
Joined: Thu Jun 20, 2013 3:59 am


Return to CULA Sparse Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron