Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Assumed shape vs contiguous arrays #46

Open
PierUgit opened this issue Feb 23, 2024 · 0 comments
Open

Assumed shape vs contiguous arrays #46

PierUgit opened this issue Feb 23, 2024 · 0 comments

Comments

@PierUgit
Copy link

We already discussed that on Discourse.

BLAS/LAPACK routines mostly use assumed size arrays, thus contiguous arrays, but can handle non contiguous data by using the inc*/ld* arguments.

In the modern wrapper (e.g. solve) you are developing, you are defining assumed-shape arguments, which is a good thing.

The problem is that compilers may/will generate copy-in/copy-out in the underlying calls to the LAPACK routines.

subroutine brand_new(A)
   real, intent(inout) :: A(:,:)
   interface
      subroutine old_timer(n,A,lda)
         integer n, lda
         real A(lda,*)
      end subroutine old_timer
   end interface
   n = size(A,1)
   call old_timer(n,A,n)   ! possible copy-in/copy-out at this point
end subroutine brand_new

How can we avoid that? We talked about inquiring the strides, using the C interoperability and the C array descriptors. So it could look like:

subroutine brand_new(A)
   real, intent(inout) :: A(:,:)
   interface
      subroutine old_timer(n,A,lda)
         integer n, lda
         real A(lda,*)
      end subroutine old_timer
   end interface
   n = size(A,1)
   inc = stride(A,1)   ! C routine behind
   lda = stride(A,2)   ! C routine behind
   if (inc == 1) then
      call old_timer(n,A(1,1),lda)   ! not nice, but supposed to work and avoid copy-in/copy-out
   else
      call old_timer(n,A,n)   ! copy-in/copy-out cannot be avoided in this case
   end if
end subroutine brand_new

What do you think ?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant