Monday, 15 March 2010

performance - construct a structured matrix efficiently in fortran -


After leaving Fortran for several years, now I have to pick it up and start working with it again.

I would like to create the matrix with the entry (i, j) form as the f (x_i, y_j) , where f < / Code> is a function of two variables, such as, f (x, y) = cos (xy) . In Matlab or Python (Numpy), there are efficient methods to control such a specific issue. I wonder if there is such optimization in Fortran or not.

BTW, is it also true in Fortran that the operation with a vector is faster than Do / Four Loop (as it is in Matab and Nampi)?

If you mean the same by vectors as you say in Matlab and Python, then the short form you Do not call the entire array, no, these forms are often slow, because they are hard to adapt to simpler loops, what happens faster when the compiler actually uses the CPU's vector instructions, but it does not And for the simple loop, use the compiler for them San.

Fundamental works , concurrent , forall and where build in Fortran, And the array constructor is. There is no repetition here, they have been described many times in this tutorial or on this site.

Your example is most commonly done using a loop

  do j = 1, ny do i = 1, nx entry (i, j) = f (X (i), y (j))  

In a small way, you will probably have vectoring, full-array operation like Python, e.g.,

< Pre-> a = cos (b) c = a * bd = f (a * b)

and similar functions (called on each element of the array) , Should be original . These operations are not necessarily efficient, for example, the last call may require a temporary array, which will be avoided when using the loop.


No comments:

Post a Comment