Can I pass NULL to cuSOLVER Fortran interface?

Hello,

I’m computing LU factorization on the GPU using the cusolverDnXgetrf functions. According to the documentation of cuSOLVER, cusolverDnXgetrf performs an LU factorization without pivoting if I pass NULL in place of ipiv_d. This works well in my C++ test code. Now if I use the Fortran interface of cuSOLVER provided in NVIDIA HPC SDK, how do I pass NULL to cuSOLVER? The compiler complains about C_NULL_PTR in the iso_c_binding module.

integer, device, allocatable :: ipiv_d(:)

...

! ipiv_d is never allocated
ierr = cusolverDnDgetrf(cusolver_h,ndim,ndim,mat_d,ndim,work_d,ipiv_d,info_d)

The code above seems to work, but I’m not sure if it’s the correct solution. Can anybody clarify? Thanks in advance!

Victor

Unfortunately, the interfaces are not written to just take a c_null_ptr. You have to pass the correct type, rank, device attribute, etc.

What you have probably is okay. A little better is:
integer, device, pointer :: ipiv_d(:)
and either
ipiv_d => null()
or
call c_f_pointer(c_null_ptr, ipiv_d, [0] )

So, you are explicit about passing null, not just some dangling thing we’re not sure about.

  • Brent

Thanks! Your approach makes a lot of sense. Code updated!

Victor

I was amazed how things are changing over time but when it comes signal transmitters play very very important role so for that you may like to read nice antennas to get best signals.