Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7222 Discussions

FGMRES solver with fixed-size arrays in F77

ljbetche
Beginner
973 Views
Hello,

I am current attempting to modify a rather large CFD code which I have written to use MKL's FGMRES solver to solve the large linear systems generated by my code. My code is written in F77, and uses fixed-size arrays to store the coefficient matrices and right hand side and solution vectors, with the arrays dimension set to large values, so that I do not need to recompile for each problem I wish to solve. For example, I may have a system of 150,000 equations, but the right hand side values and the initial guess for the solutions are stored in the first 150,000 entries of arrays declared as:

REAL*8 B(250000),X(250000)

Is this allowable with the FGMRES solver? For instance, if I were to call:

CALL DFGMRES_INIT(150000, X,B,RCI_REQUEST,IPAR,DPAR,TMP)

would this work as is, even though X and B are allocated with more than 150,000 elements? If not, is there a workaround, apart from setting the right array sizes and recompiling each time, or filling up the extra rows with trivial equations such as X(I) = 0 for I > 150,000 in this example (obviously a tremendous waste of computing resources)? Thanks in advance.

Lee
0 Kudos
3 Replies
ArturGuzik
Valued Contributor I
973 Views
Quoting - ljbetche
would this work as is, even though X and B are allocated with more than 150,000 elements? If not, is there a workaround, apart from setting the right array sizes and recompiling each time, or filling up the extra rows with trivial equations such as X(I) = 0 for I > 150,000 in this example (obviously a tremendous waste of computing resources)? Thanks in advance.

Lee

Lee,

it should work, although as far as I can rember docs claim should be array of length N. Just try it. However, you'll always have a "waste of resources". The simplest and most reliable fix to that is to use a bit of Fortran 90 and allocatable arrays. The only modification would be to change declaration from "fixed" B(2000000) to:

REAL, ALLOCATABLE :: B(:), X(:)

and then when you read your input:

READ (*,*) N

ALLOCATE (B(N), X(N)....)

And that's it. No recompile needed. Memory is allocated at the run-time.

A.
0 Kudos
ljbetche
Beginner
973 Views
Artur,

Thank you so much for the help; getting the results from this code is the last bit of work I need to do for my PhD! I'll try it both ways. Do you happen to know if I would need to make any other modifications to my code to use the little bit of F90 you suggest, or could I just insert it into my routine and go along without further changes (I'm using ifort as the compiler)? Sorry to ask, but I've got no experience programming in anything other than strict F77 (old fashioned, I know).

Lee
0 Kudos
ArturGuzik
Valued Contributor I
973 Views
Quoting - ljbetche
Do you happen to know if I would need to make any other modifications to my code to use the little bit of F90 you suggest, or could I just insert it into my routine and go along without further changes (I'm using ifort as the compiler)?
Lee,

The only changes needed are just that what I showed. I used to work at Uni and saw many old-style F77 HUGE legacy codes modified as that, making a few myself. I mean, the only change required is to use allocatable arrays and replace fixed size with N, which would be read "on the fly". If you have COMMON blocks they can be replaced with use of MODULEs. If you don't (have COMMON) no further changes required. If your code is working fine with ifort (IVF) then you should have no problem at all. The code will behave as working with N equal to that what you normally define as max dimension, with that it's adjusted to what'r really required for particular run. If you have any problems, just post some details here or on IVF Forum, where Steve or others can basically answer ANY programming question.

A.
0 Kudos
Reply