Fortran findloc内在 [英] Fortran findloc intrinsic

查看:1015
本文介绍了Fortran findloc内在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用英特尔的Visual Fortran Composer XE 2011,12.1.3537.2010,因为它看起来不支持内置的 findloc 函数(在2008年fortran中型扩展中添加)。

我想要做的是在数组中查找特定的值并返回索引。我主要使用小尺寸数组。



我有两个问题:


  1. 我想用这个功能替换线性和二进制搜索,而且当我在其他线程中阅读时,不清楚哪种算法更适合优化性能。内在函数如何处理这个问题? 由于在我的编译器中不支持,所以模拟 findloc 的方法如下:

  2. $ b $

      minloc((array-value)** 2)

    但是......表现如何?任何其他想法? 如果我正确理解你的第一个问题,你想要了解一个尚未实现的功能是如何实现的?具体而言,您想知道 findloc 与线性和二进制搜索相比的性能特点,因为您可能自己实现了它们?语言标准当然没有规定如何实现这个功能,所以你的问题的答案完全是编译器特定的。关于你的第二个问题,我希望大多数编译器能够响应你的表达式 array-value 创建一个临时数组。创建这样一个临时的操作可能是一个相对耗时的操作,并且会被添加到对 minloc 的调用的执行时间中。英特尔如何执行 minloc 的工作原理我不知道,但我预计它是对阵列的线性扫描。没有办法让内部函数知道数组是排序的,而二进制搜索可能会更快。



    如果你的数组很小并且没有排序,我会期望线性搜索是最快的选择。如果它们很小并且被排序,你可能会写一个二进制搜索(或类似的)来超越线性搜索。我期望这两种方法的性能图有一个交叉点,交叉点就是你对小尺寸的想法我不知道。



    然而,一如既往的表现问题,我(或其他人)认为是无用的,数据就是你需要的,为什么你不去做测量?

    I am using Intel's Visual Fortran Composer XE 2011, 12.1.3537.2010 and as it appears, the intrinsic findloc function is not supported (added at 2008 fortran mid-size extrension).

    What I want to do is to look up for a specific value in an array and have the index returned. Mostly I work with small size arrays.

    I have 2 questions:

    1. I would like to replace linear and binary searches with this functionality, and as I read in other threads it is not clear which algorithm is preferred for optimal performance. How does the intrinsic function deals with the problem?
    2. Since with my compiler this is not supported, a way to emulate findloc would be the following:

      minloc( (array-value)**2 )
      

      But... what about the performance? Any other ideas?

    解决方案

    If I understand your first question correctly you want to know how an, as yet unimplemented, function is implemented ? Specifically, you want to know the performance characteristics of findloc compared with linear and binary search as you might have implemented them yourself ? There is certainly nothing in the language standard which mandates how the function is to be implemented, so the answer to your question is entirely compiler specific.

    As to your second question, I would expect most compilers to cause the creation of a temporary array in response to your expression array-value. The creation of such a temporary is likely to be a relatively time-consuming operation and will be added to the execution time of the call to minloc. How the Intel implementation of minloc works I don't know but I expect that it is a linear scan through the array. There's no way for the intrinsic function to know that an array is sorted and that binary search might be faster.

    If your arrays are small and unsorted I would expect linear search to be the fastest option. If they are small and sorted you might be able to write a binary search (or similar) to outperform linear search. I expect the performance graphs of the two approaches to have a crossover, where that crossover sits wrt your idea of small size I haven't a clue.

    However, as always with performance matters, what I (or anybody else) think is useless, data is what you need, why don't you go ahead and make some measurements ?

    这篇关于Fortran findloc内在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆