Use of ANY
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Use of ANY         


Author: Gib 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
Re: Use of ANY         


Author: Craig 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
Re: Use of ANY         


Author: Arjen 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
Re: Use of ANY         


Author: Craig 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
Re: Use of ANY         


Author: Dick 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
Re: Use of ANY         


Author: Gib 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
Re: Use of ANY         


Author: Dick 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
Re: Use of ANY         


Author: nospam
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
Re: Use of ANY         


Author: glen 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
Re: Use of ANY         


Author: Gib 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
1 2