Supercomputing Institute Technical User Support

Array Formats

The Matrix (C notation)

A[1][1] A[1][2] A[1][3]
A[2][1] A[2][2] A[2][3]
(or in Fortran notation)
A(1,1) A(1,2) A(1,3)
A(2,1) A(2,2) A(2,3)
is really stored as a 1-Dimensional array. C stores it row by row (Row Majority) , Fortran stores it Column by Column (Column Majority). This is also how an array is dumped to a file (unformatted write in Fortran, fwrite in C). Be careful: Fortran writes extra information before and after each unformated write.

Some packages use Row Majority, some Column and some can handle both. The following table summarizes Row and Column Majority, and shows how the packages want their multi-dimensional arrays.

Majority Index How Stored The Loop
C

Fortran
Packages
Row
(C-order)
Last Index Varies Fastest A[1][1]
A[1][2]
A[1][3]
A[2][1]
A[2][2]
A[2][3]
for(i=1;i<3;i++)
  for(j=1;j<2;j++)
    printf("%d\n",A[i][j]);

WRITE(IUNIT)((A(I,J),j=1,2),I=1,3)
PV~Wave
DX(Row)
Column (Fortran-order) First Index Varies Fastest A[1][1]
A[2][1]
A[1][2]
A[2][2]
A[1][3]
A[2][3]
for(j=1;j<2;j++)
  for(i=1;i<3;i++)
    printf("%d\n",A[i][j]);

WRITE(IUNIT)((A(I,J),I=1,3),j=1,2)
Bob
Fast
DX(Column)
Tecplot

This information is available in alternative formats upon request by individuals with disabilities. Please send email to alt-format@msi.umn.edu or call 612-624-0528.

HOME | QUESTIONS | FEEDBACK
Events | Links | People | Programs | Publications | Support | Welcome
 


URL: http://www.msi.umn.edu /user_support/scivis/array-order.html
This page last modified on Wednesday, 23-Apr-2008 11:15:51 CDT  
Please direct questions or problems to help@msi.umn.edu  
Website related questions or problems should be directed to webmaster@msi.umn.edu
The Supercomputing Institute does not collect personal information on visitors to our website. For the University of Minnesota policy, see www.privacy.umn.edu.