Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29278 Discussions

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

Wee_Beng_T_
Beginner
581 Views

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!

0 Kudos
3 Replies
Steven_L_Intel1
Employee
581 Views
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.
0 Kudos
jimdempseyatthecove
Honored Contributor III
581 Views
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
0 Kudos
Wee_Beng_T_
Beginner
581 Views
Thanks for the recommendations. I'll try to come up with an example in a few days to make things clearer.
0 Kudos
Reply