Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Indexing in Fortran

Coco
Beginner
484 Views

Hi, this isnt really a compiler related question but rather a general fortran question, i have a piece of code that my friend has sent me and in doing so he does this peice of code in which he allocates a bc condition to a whole row but the way in which he does this is confusing because hes write u(:,1) = 20 and u(:,ny) = 40 in which he gets the first row to be 20 and the top or the last row to be 40. Im confused because fortran is a col-maj indexing which means that it should be u(1,:) = 20 for the bottom and u(ny,:) = 40 for the last row.

https://gyazo.com/9ac5341f1010ce7e656580107f0fad7b

https://gyazo.com/5a4b07f4e27617c95a4b513bba8a3149

https://gyazo.com/5bd22ffabb986b4b4e3ffb779edaaf1c

 
 

 

 

0 Kudos
9 Replies
mecej4
Black Belt
472 Views

The subscript convention for two-dimensional arrays is the same in many programming languages as in linear algebra. The first index, starting with 1, is the row number, and the second index is the column number. Thus, u(:,1) is the first column and u(:,ny) is the last column. Row 1 is written at the 'top', and column 1 is written at the left, again as in linear algebra.

Different conventions may be used for screen pixel coordinates, etc.

The question of "row-major" or "column-major" arises only when one tries to map a 2-D array to a 1-D array.

JohnNichols
Valued Contributor II
464 Views

The question of "row-major" or "column-major" arises only when one tries to map a 2-D array to a 1-D array.

This was a real problem in the 70's when we had limited memory and people often used a single vector to hold a lot of the data and not have a lot of wasted zeros

You would see really weird indexing loops 

I undid one of those a few years ago for some 1970 code and it takes days. 

JohnNichols
Valued Contributor II
467 Views

You appear to solving a heat problem on a sheet.  if you matrix is square then the two solutions left to right or down to up will be the same if you have one edge cold and the opposite edge hot,  so setting the boundary conditions relies on knowing how you assigned them in the first place. 

You just have to understand your boundary conditions.  

1    1    1

- --------

40 40 40 

is the same problem as 

1 - 40

1 - 40

1 - 40 

JohnNichols
Valued Contributor II
456 Views

if the second graph is the answer - I would have a deal of difficulty accepting that answer as a long term solution - I assume the problem has a boundary on the left and the right that does not allow heat flow

 

Coco
Beginner
422 Views

Yes you are right there are neumann bcs on all edges except for the top and bottom edges which have dirichlet bcs of 20 and 40. im still trying to make sense of this in my mind cause i cant get over the fact that fortran is supposed to be col-maj.

JohnNichols
Valued Contributor II
400 Views

I would stop worry about the column major stuff, you are reading to much into what you have been taught and not enough into trust your gut and see what happens. 

Your solution as color coded is something you need to look at and ask yourself does it look correct. The results do not look correct. There are four internal corners, these map one line of constant temp at the top onto the top of the web line, the lengths in between vary so unless you have some sort of weird material the constant heat contours should be elliptical or some such shape and not straight lines.  

 

mecej4
Black Belt
376 Views

Coco, if you have Neumann B.C. on the left and right, and the beam is very long (in the z-direction), the temperature distribution is one-dimensional. The temperature varies linearly from 20 at one flange to 40 at the other. No computer is needed to solve such a 1-D problem.

FortranFan
Honored Contributor II
445 Views

@Coco ,

Given what you posted, "this isnt really a compiler related question but rather a general fortran question ..", please also consider this Fortran Discourse site for wider feedback on general Fortran related topics:

https://fortran-lang.discourse.group/

A__King
New Contributor III
339 Views

glad to see "also" in your answer. Even though this is the Intel Fortran forum, it's also a great place to ask generic Fortran questions given the high activity of experts in the forum.

Reply