I want to implement a small and fast qualitative data type in Fortran

前端 未结 1 1647
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 02:59

This is part of a series of questions about implementing a qualitative data type in Fortran.

Background: The topic relates to something called loop

相关标签:
1条回答
  • 2021-01-24 03:45

    The answer to this, and your other two questions (and both parts of those questions), is at best "It Depends". "No" without elaboration might also suffice, given the way you've written the actual questions.

    The answer is almost certainly hardware (assuming you are even solving these problems on a computer...), software and problem detail (particularly problem size) specific.

    I'd suggest that you need to construct a prototype for testing, set some calculations up on representative data, and measure time and memory requirements. Note that the smallest solution may not be the fastest solution, and the fastest solution may depend on problem size.

    Variations that you should consider include using other than default kind logical. The storage for default kind logical has to be the same as for default kind integer and default kind real, which always going to be much larger than the nominal one bit of storage required to hold a true or false value.

    The obvious alternative implementation is to encode the four values for the datatype in a small range integer, perhaps even using the bit intrinsics. Whether that ends up being faster or smaller ... it depends.

    You may also want to rethink your mapping from logical components/bits through to the four values, given the operations that you want to perform on thee values in other questions and how they could be represented using the normal logical operations (and/or/ eqv/neqv, etc). Consider a component or bit that represents "is negative", and one that represents "is positive". You may (or may not) find that simply using the basic logical operations gives a faster result than you precomputed table approach, used in the other two questions, particularly given the logical operations inherent in calculating table indices.

    Another important metric in choosing an approach, beyond speed and memory footprint, is the clarity and usability of the resulting code. In many situations, this is really the most important metric.

    0 讨论(0)
提交回复
热议问题