Is this code computationally economical?
- From: "qquito" <qquito@xxxxxxxxxxx>
- Date: 26 Jan 2007 23:36:06 -0800
Hello, All:
I am using Fortran 90 and have an array, a(1:N), whose some elements
are larger than 0, and others less than or equal to 0.
My task is to find the average of those elements that are larger than
0.
I am thinking to use the code
average=sum(a, mask=(a>0.0))/count(mask=(a>0.0))
But since I have to do it with enormous data and many similar
operations, I am wondering if it is as computationally economic as the
following do-loop with an imbedded if-loop:
s=0.0
n=0
do i=1, N
if(a(i)>0.0) then
s=s+a(i)
n=n+1
endif
enddo
average=s/n
I figure that the one-line code given above will have to go through all
the elements twice, and so it is not as computationally economical as
the loop. Is this correct?
Thank you for reading and replying!
--Roland
.
- Follow-Ups:
- Re: Is this code computationally economical?
- From: Gib Bogle
- Re: Is this code computationally economical?
- From: Beliavsky
- Re: Is this code computationally economical?
- From: andy2O
- Re: Is this code computationally economical?
- From: highegg
- Re: Is this code computationally economical?
- From: Dick Hendrickson
- Re: Is this code computationally economical?
- From: Thomas Koenig
- Re: Is this code computationally economical?
- From: Walter Spector
- Re: Is this code computationally economical?
- From: Arjen Markus
- Re: Is this code computationally economical?
- From: glen herrmannsfeldt
- Re: Is this code computationally economical?
- Prev by Date: Re: A file managment question
- Next by Date: Re: string concatenation
- Previous by thread: A file managment question
- Next by thread: Re: Is this code computationally economical?
- Index(es):
Relevant Pages
|