Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

maxloc question (just curious)

NH_Veldhuijzen
Beginner
737 Views

Dear all,

I am just curious:

As "MAXLOC(V)" returns a vector, why is it not allowed to write "I=MAXLOC(V)(1)"? [I always use the shortcut "I=MAXVAL(MAXLOC(V))", but I am still curious.]

Kind regards,

Niels H. Veldhuijzen

Cito, Arnhem, The Netherlands

0 Kudos
3 Replies
TimP
Honored Contributor III
737 Views
Hardly anyone sticks to f90 nowadays, when f95 added the option
I=MAXLOC(V,dim=1)

I=MAXLOC(V,1)
is permissible, but not recommended, due to its obscurity, and requirement to remember whether that is a DIM or a MASK argument.

Somewhere, I've seen comments from people who were there when the decisions were made. The consistency argument fall short for me, when an absent dim= defaults to 1 for other intrinsics, but to the rank(V) for maxloc and minloc.

Further mysteries about maxloc include the question: Why is it so difficult to parallelize a multiple dimension maxloc? -Qparallel can get a small advantage, but not as much as explicitly assigning a maxloc(V,dim=1) to each thread in an inner loop, with normal care taken to avoid races between the threads. So, maxloc has to be reduced to C++ style when efficient threading is needed.

0 Kudos
Steven_L_Intel1
Employee
737 Views
There is no syntax in Fortran to reference an element of an array expression. You must assign it to a variable first. Tim points out the DIM argument which is probably what you want.
0 Kudos
NH_Veldhuijzen
Beginner
737 Views

Dear Tim18 & Steve,

Thank you both for your quick and lucid replies!

Kind regards,

Niels H. Veldhuijzen

Cito, Arnhem, The Netherlands

0 Kudos
Reply