Shifting array from (1:size_x,1:size_y) to (0:size_x-1,0:size_y-1)

Shifting array from (1:size_x,1:size_y) to (0:size_x-1,0:size_y-1)

Hi,

I am writng a CFD code and I'm using the PETSc library. It has some new functions which help to partition my solution automatically. However, since it's written in C, its output array are always given as A(0:size_x-1,0:size_y-1).

However, my fortran array was allocated as A(1:size_x,1:size_y). Since I am implementing the new functions into my existing code, I'm trying to modify as little codes as possible. I have many subroutines which uses A(1:size_x,1:size_y) as the input array.Is there anyway whereby I can change between A(1:size_x,1:size_y) and A(0:size_x-1,0:size_y-1), without the need to copy one over the other and take up more memory?

Thanks!

4 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Steve Lionel (Intel)

You shouldn't need to make any copies. Is it that you're passing these arrays to the C routines? The C routines have no idea how the arrays are allocated - you'd have to pass the sizes separately. You should be able to just pass the arrays and the bounds in the way C wants them.

If I haven't understood your question correctly, please post some sample code to illustrate the problem and where you think you need to chsange things. I will warn you that a 2-dimension array in C is an array of arrays. More likely that the C routine wants the first element address and the bounds.

Steve
Bild des Benutzers jimdempseyatthecove

If you are taking a C/C++ function and porting(converting) the source to FORTRAN, then you need only do the bounds changing in the declaration of the dummy arguments (IOW no copying required)

ALLOCATE(A(100, 200)) ! i.e. A(1:100, 1:200)
CALL FOO(A, 100, 200)
...
SUBROUTINE FOO(A, nX, nY)
INTEGER :: nX, nY
REAL :: A(0:nX-1,0:nY-1)
...

Jim Dempsey

www.quickthreadprogramming.com

Thanks for the recommendations. I'll try to come up with an example in a few days to make things clearer.

Melden Sie sich an, um einen Kommentar zu hinterlassen.