I used FINDLOC (in the standard since 2008) in a code. Ifort works fine with it, gfortran > 9.1 works fine, but older gfortran does not have it implemented. There is a user of my code that runs older gfortran and is stuck with it. Does anyone maybe have open source function that mimics the functionality of FINDLOC? If the performance is suboptimal, it does not matter much.
Findloc works for arrays of all intrinsic types and ranks, and it has several optional arguments, listed here. How general of a findloc do you need? This could be determined empirically by writing a findloc interface and adding necessary module procedures until the code compiles. Writing a findloc that works for say 1d and 2d integer or character arrays would not be difficult. There was discussion of putting findloc in stdlib for your use case, but I don’t see it here, so I don’t it was implemented.
It does not have to be general at all. It should actually work just for 1D arrays of integers or floats. Yes, I’m aware that this is easy, but I’m getting lazy when I have to do something that probably already exists. I was a bit surprised that I couldn’t google it, so I thought of asking here before doing it myself.
I wrote my own FINDLOC workalike a few years back just so I could
compile code on gfortran and PGI compilers that did not support
FINDLOC at that time. My code supports rank 1 through rank3 arrays of
Integer and real (both 32 and 64 bit) and logicals. I can bundle the code into
a standalone package and put it on github if there is sufficient interest
Are you hoping for a world with full compiler support for recent Fortran standards? Emulating an unsupported feature facilitates using the feature prior to compiler support. This path offers minimal impact on future code.
Those who find the collective subroutines useful might also be interested in language extensions such as the Sourcery library’s co_all subroutine, which provides a parallel, collective logical operation analogous to the all intrinsic function.
Just in case, the array is large and sorted, a binary search would likely be much faster than the intrinsic findloc which presumably uses a linear search.
@shahmoradi That’s an excellent point. I will do some experiments to see how does findloc perform in terms of speed in the case of interest. Thank you!