|
|
Up |
|
|
  |
Author: Gib BogleGib Bogle Date: Aug 11, 2008 16:15
Hi,
I'd like to know the fastest way to do a check on all elements of a slice of an array, looking for
any occurrence of a particular condition. To be precise:
fu(NX,NY,NZ) is an array of derived type, something like
type fu_type
integer :: bar
integer :: status
...
end type
type(fu_type) :: fu(NX,NY,NZ)
For a given x, and a status value stat0 I want to determine whether there is any (y,z) 1<=y<=NY,
1<=z<=NZ, such that
fu(x,y,z)%%status /= stat0
Is there a clever way to use the ANY intrinsic for this, or do I have to use dumb loops?
|
| |
|
| | 13 Comments |
|
  |
Author: Craig PowersCraig Powers Date: Aug 11, 2008 16:20
Gib Bogle wrote:
> Hi,
> I'd like to know the fastest way to do a check on all elements of a
> slice of an array, looking for any occurrence of a particular
> condition. To be precise:
>
> fu(NX,NY,NZ) is an array of derived type, something like
>
> type fu_type
> integer :: bar
> integer :: status
> ...
> end type
>
> type(fu_type) :: fu(NX,NY,NZ)
>
> For a given x, and a status value stat0 I want to determine whether
> there is any (y,z) 1<=y<=NY, 1<=z<=NZ, such that
> fu(x,y,z)%%status /= stat0
> ...
|
| Show full article (0.78Kb) |
|
| | no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Aug 11, 2008 21:40
On 12 aug, 01:20, Craig Powers wrote:
> Gib Bogle wrote:
>> Hi,
>> I'd like to know the fastest way to do a check on all elements of a
>> slice of an array, looking for any occurrence of a particular
>> condition. To be precise:
>
>> fu(NX,NY,NZ) is an array of derived type, something like
>
>> type fu_type
>> integer :: bar
>> integer :: status
>> ...
>> end type
>
>> type(fu_type) :: fu(NX,NY,NZ)
>
>> For a given x, and a status value stat0 I want to determine whether
>> there is any (y,z) 1<=y<=NY, 1<=z<=NZ, such that
>> fu(x,y,z)%%status /= stat0 ...
|
| Show full article (1.07Kb) |
| no comments |
|
  |
Author: Craig PowersCraig Powers Date: Aug 12, 2008 09:17
Arjen Markus wrote:
> On 12 aug, 01:20, Craig Powers wrote:
>> Gib Bogle wrote:
>>> Hi,
>>> I'd like to know the fastest way to do a check on all elements of a
>>> slice of an array, looking for any occurrence of a particular
>>> condition. To be precise:
>>> fu(NX,NY,NZ) is an array of derived type, something like
>>> type fu_type
>>> integer :: bar
>>> integer :: status
>>> ...
>>> end type
>>> type(fu_type) :: fu(NX,NY,NZ)
>>> For a given x, and a status value stat0 I want to determine whether
>>> there is any (y,z) 1<=y<=NY, 1<=z<=NZ, such that
>>> fu(x,y,z)%%status /= stat0
>>> Is there a clever way to use the ANY intrinsic for this, or do I have to
>>> use dumb loops?
>> How about: ...
|
| Show full article (1.20Kb) |
| no comments |
|
  |
Author: Dick HendricksonDick Hendrickson Date: Aug 12, 2008 09:30
Gib Bogle wrote:
> Hi,
> I'd like to know the fastest way to do a check on all elements of a
> slice of an array, looking for any occurrence of a particular
> condition. To be precise:
>
> fu(NX,NY,NZ) is an array of derived type, something like
>
> type fu_type
> integer :: bar
> integer :: status
> ...
> end type
>
> type(fu_type) :: fu(NX,NY,NZ)
>
> For a given x, and a status value stat0 I want to determine whether
> there is any (y,z) 1<=y<=NY, 1<=z<=NZ, such that
> fu(x,y,z)%%status /= stat0
> ...
|
| Show full article (1.04Kb) |
| no comments |
|
  |
Author: Gib BogleGib Bogle Date: Aug 12, 2008 13:12
Dick Hendrickson wrote:
> Gib Bogle wrote:
>> Hi,
>> I'd like to know the fastest way to do a check on all elements of a
>> slice of an array, looking for any occurrence of a particular
>> condition. To be precise:
>>
>> fu(NX,NY,NZ) is an array of derived type, something like
>>
>> type fu_type
>> integer :: bar
>> integer :: status
>> ...
>> end type
>>
>> type(fu_type) :: fu(NX,NY,NZ)
>>
>> For a given x, and a status value stat0 I want to determine whether
>> there is any (y,z) 1<=y<=NY, 1<=z<=NZ, such that
>> fu(x,y,z)%%status /= stat0 ...
|
| Show full article (1.20Kb) |
| no comments |
|
  |
Author: Dick HendricksonDick Hendrickson Date: Aug 12, 2008 14:27
Gib Bogle wrote:
> Dick Hendrickson wrote:
>> Gib Bogle wrote:
>>> Hi,
>>> I'd like to know the fastest way to do a check on all elements of a
>>> slice of an array, looking for any occurrence of a particular
>>> condition. To be precise:
>>>
>>> fu(NX,NY,NZ) is an array of derived type, something like
>>>
>>> type fu_type
>>> integer :: bar
>>> integer :: status
>>> ...
>>> end type
>>>
>>> type(fu_type) :: fu(NX,NY,NZ)
>>>
>>> For a given x, and a status value stat0 I want to determine whether
>>> there is any (y,z) 1<=y<=NY, 1<=z<=NZ, such that ...
|
| Show full article (1.88Kb) |
| no comments |
|
  |
Author: nospamnospam Date: Aug 12, 2008 14:48
Dick Hendrickson att.net> wrote:
>>> Depends on what you mean by "fastest". If the condition is an
>>> "unusual" condition, than letting the compiler generate code for the
>>> ANY intrinsic is almost always fastest. If the condition "almost
>>> always" occurs, then a DO loop with a short circuit exit on the first
>>> occurrence is likely to be fastest.
...
> Then a serious idea popped
> up, try experimenting with FIRSTLOC. That will possibly short-circuit
> the tests when it finds a true instance. But, it's also likely that the
> compiler will generate efficient code (unrolling, pipelined execution,
> whatever) for the implied loop. Again, it will be hardware and compiler
> dependent; but, you might be surprised.
This prompts me to ask a question that I wondered about, but hadn't
asked, after seeing your prior post in this thread (quoted above).
|
| Show full article (1.82Kb) |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Aug 12, 2008 16:42
Richard Maine wrote:
(snip)
(previously snipped)
ANY( fu(:,1:NY,1:NZ) %% status /= stat0 )
> This prompts me to ask a question that I wondered about, but hadn't
> asked, after seeing your prior post in this thread (quoted above).
> Why wouldn't an optimizing compiler also short-circuit the evaluation of
> the ANY intrinsic? At least for serial architectures, that seems to me
> like the obvious thing to do. (Parallel systems make all kinds of
> questions harder, so I could imagine differences there.) Your first
> quote above sounds to me as though you are assuming that the compiler
> loops through the whole array to implement ANY. I can certainly see that
> as the "obvious" unoptimized solution, but I'd think that a short
> circuit would be a natural candidate for optimization here. Is it just
> that compilers don't tend to optimize those kinds of expressions much at
> all?
|
| Show full article (2.49Kb) |
| no comments |
|
  |
|
|
  |
Author: Gib BogleGib Bogle Date: Aug 12, 2008 23:12
Dick Hendrickson wrote:
> Gib Bogle wrote:
>> Dick Hendrickson wrote:
>>> Gib Bogle wrote:
>>>> Hi,
>>>> I'd like to know the fastest way to do a check on all elements of a
>>>> slice of an array, looking for any occurrence of a particular
>>>> condition. To be precise:
>>>>
>>>> fu(NX,NY,NZ) is an array of derived type, something like
>>>>
>>>> type fu_type
>>>> integer :: bar
>>>> integer :: status
>>>> ...
>>>> end type
>>>>
>>>> type(fu_type) :: fu(NX,NY,NZ)
>>>>
>>>> For a given x, and a status value stat0 I want to determine whether ...
|
| Show full article (2.04Kb) |
| no comments |
|
|
|
|