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

IVF+VB.NET multidimensional arrays

Gilles_R_
Beginner
2,011 Views

Isearch VB.NET-Intel Fortran example with multidimensional arrays.

If I understand (?):

VB6 store arrays in column order
VB.NET store arrays in row order

Fortran store arrays in column order
also VB6+Fortran: memory is exact mapping
but VB.NET+Fortran: no exact mapping

Example: If I have matrix M
147
258
369

VB6 store 1 2 3 4 5 6 7 8 9
i.e. dim M(2,2) aslong
M(0,0) = 1
M(1,0) = 2
M(2,0) = 3
M(0,1) = 4
...

Fortran 1 2 3 4 5 6 7 8 9
i.e. INTEGER M(3,3)
M(1,0) = 1
M(2,0) = 2
M(3,0) = 3
M(1,1) = 4
...
VB.NET 1 4 7 2 5 8 3 6 9
i.e. dim M(2,2) as integer
M(0,0) = 1
M(1,0) = 2
M(2,0) = 3
M(0,1) = 4
...

Also, with VB.NET: dim M(k,l) as Integer
match Fortran INTEGER M(l,*)

0 Kudos
4 Replies
Steven_L_Intel1
Employee
2,011 Views
0 Kudos
pradeepnatekar
Beginner
2,011 Views

Hi

I tried sending multidimensional numeric array to fortran from C#. Even the size of array being passed and one that is receiving at Fortran is same, the elements are being positioned differently.

For eg,

I sent

1 2 3 4

5 6 7 8

The fortran side receives

135 7

24 6 8

What should I do to receive the array in same order at Fortran side.

Please let me know.

Thanks You.

0 Kudos
Steven_L_Intel1
Employee
2,011 Views
Understand that Fortran stores arrays in a different order than C and most other languages. You cannot force the "correct" order when passing, you have to take the order into account when writing your code. Usually this means, in Fortran, declaring the array with the indices in reverse order (3,2) instead of (2,3), for example, and running loops that traverse the array in reverse order as well. Also note that C arrays start at origin 0 and Fortran at origin 1 by default.
0 Kudos
pradeepnatekar
Beginner
2,011 Views

Many Thanks Steve. I understoodbetter now.I already have written acode with lot of arrays at Fortran side based on their desired rows and columns. On the other hand I have only few arrays to pass from C# side. So I interchanged the array row & columns at senders side (c#). For e.g. if Fortran already has array(x,y); I am passing array(y,x) from C#.

Regards,

Pradeep

0 Kudos
Reply