faster version of anint()
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
faster version of anint()         


Author: zhngbn
Date: Jul 6, 2008 12:51

Hi, all
I have heard that the build-in function anint of fortran is kind
of slow, but I have to used it quite frequent in my code. Anyone know
a more efficient version of it?

Thanks a lot.
12 Comments
Re: faster version of anint()         


Author: nospam
Date: Jul 6, 2008 13:16

zhngbn gmail.com> wrote:
> I have heard that the build-in function anint of fortran is kind
> of slow, but I have to used it quite frequent in my code. Anyone know
> a more efficient version of it?

That's pretty much a meaningless question without a whole lot more
context. That kind of thing depends 100%% on the particular compiler
implementation. It would not be a property of the Fortran language,
which doesn't say anything about how the function is implemented. If
there were a faster implementation of exactly the same thing, then
presumably the compiler vendor would adopt it and that would then *BE*
the intrinsic one for that compiler.

There are basically only two ways that can make any sense.

1. If it is a problem with a particular compiler. In that case, well, it
would depend on that particular compiler.

2. The suggestion is that the functionality of anint is inherently slow.
In that case, the interesting question would be what alternate
finctionality would suit your needs.
Show full article (1.50Kb)
no comments
Re: faster version of anint()         


Author: zhngbn
Date: Jul 6, 2008 14:53

> 2. The suggestion is that the functionality of anint is inherently slow.
> In that case, the interesting question would be what alternate
> functionality would suit your needs.

This is what I wanted. :) Any suggestions?
Sorry for any misunderstanding.
Thanks.
no comments
Re: faster version of anint()         


Author: dpb
Date: Jul 6, 2008 14:56

zhngbn wrote:
>> 2. The suggestion is that the functionality of anint is inherently slow.
>> In that case, the interesting question would be what alternate
>> functionality would suit your needs.
>
> This is what I wanted. :) Any suggestions?
...

Profile the code to first prove what you have is actually a
bottleneck...like Richard, I am also skeptical this is a real problem.

--
no comments
Re: faster version of anint()         


Author: zhngbn
Date: Jul 6, 2008 15:19

On Jul 6, 2:56 pm, dpb non.net> wrote:
> zhngbn wrote:
>>> 2. The suggestion is that the functionality of anint is inherently slow.
>>> In that case, the interesting question would be what alternate
>>> functionality would suit your needs.
>
>> This is what I wanted. :) Any suggestions?
>
> ...
>
> Profile the code to first prove what you have is actually a
> bottleneck...like Richard, I am also skeptical this is a real problem.
>
> --

This is the flat profile I got from gprof:

1 Flat profile:
2
3 Each sample counts as 0.01 seconds.
4 %% cumulative self self total
5 time seconds seconds calls s/call s/call name...
Show full article (1.44Kb)
no comments
Re: faster version of anint()         


Author: dpb
Date: Jul 6, 2008 15:25

zhngbn wrote:
> On Jul 6, 2:56 pm, dpb non.net> wrote:
...
>> Profile the code to first prove what you have is actually a
>> bottleneck...like Richard, I am also skeptical this is a real problem.
...
> This is the flat profile I got from gprof:
...
> 4 %% cumulative self self total
> 5 time seconds seconds calls s/call s/call name
> 6 38.95 47.07 47.07 20001 0.00 0.00 derv_
> 7 20.59 71.96 24.89 20001 0.00 0.00 second_
> 8 17.76 93.42 21.46 20001 0.00 0.00 third_
> 9 10.08 105.60 12.18 f_ldnint_val
...
> Is the function on line 9 "f_ldnint_val" the build-in "anint"? I have
> clearly not defined this function.

Perhaps, I'm not positive.
Show full article (1.06Kb)
no comments
Re: faster version of anint()         


Author: zhngbn
Date: Jul 6, 2008 15:53

On Jul 6, 3:25 pm, dpb non.net> wrote:
> zhngbn wrote:
>> On Jul 6, 2:56 pm, dpb non.net> wrote:
>
> ...
>
>>> Profile the code to first prove what you have is actually a
>>> bottleneck...like Richard, I am also skeptical this is a real problem.
>
> ...
>
>
>
>> This is the flat profile I got from gprof:
> ...
>>       4   %%   cumulative   self              self     total
>>       5  time   seconds   seconds    calls   s/call   s/call  name
>>       6  38.95     47.07    47.07    20001     0.00     0.00  derv_
>>       7  20.59     71.96    24.89    20001     0.00     0.00  second_
>>       8  17.76     93.42    21.46    20001     0.00     0.00  third_ ...
Show full article (1.58Kb)
no comments
Re: faster version of anint()         


Author: James Van Buskirk
Date: Jul 6, 2008 17:08

"zhngbn" gmail.com> wrote in message
news:acfb4dcd-602f-4823-9c98-fb0723836883@d1g2000hsg.googlegroups.com...
> I have heard that the build-in function anint of fortran is kind
> of slow, but I have to used it quite frequent in my code. Anyone know
> a more efficient version of it?

The Fortran definition of ANINT isn't consistent with the IEEE
rounding modes. I can't recall whether SSE has an appropriate
instruction, but in module IEEE_ARITHMETIC there is a function
IEEE_RINT which maps to normal processor arithmetic instructions:

C:\gfortran\clf\rint>type rint.f90
program rint
use IEEE_ARITHMETIC
implicit none
integer, parameter :: dp = selected_real_kind(15,300)
integer N
real(dp), allocatable :: harvest(:)
real(dp) t0,t1
integer i, j
real(dp) total
Show full article (1.99Kb)
no comments
Re: faster version of anint()         


Author: zhngbn
Date: Jul 6, 2008 22:56

On Jul 6, 5:08 pm, "James Van Buskirk" comcast.net> wrote:
> "zhngbn" gmail.com> wrote in message
>
> news:acfb4dcd-602f-4823-9c98-fb0723836883@d1g2000hsg.googlegroups.com...
>
>>    I have heard that the build-in function anint of fortran is kind
>> of slow, but I have to used it quite frequent in my code.  Anyone know
>> a more efficient version of it?
>
> The Fortran definition of ANINT isn't consistent with the IEEE
> rounding modes.  I can't recall whether SSE has an appropriate
> instruction, but in module IEEE_ARITHMETIC there is a function
> IEEE_RINT which maps to normal processor arithmetic instructions:
>
> C:\gfortran\clf\rint>type rint.f90
> program rint
>    use IEEE_ARITHMETIC
>    implicit none
>    integer, parameter :: dp = selected_real_kind(15,300)
>    integer N ...
Show full article (2.52Kb)
no comments
Re: faster version of anint()         


Author: James Van Buskirk
Date: Jul 6, 2008 23:42

"zhngbn" gmail.com> wrote in message
news:ce78ab03-e8ac-437a-b05b-7a5120be18f1@34g2000hsf.googlegroups.com...
> I tried to use g95 to compile the code, but got the following error:
> In file rint.f90:30
> total = total+IEEE_RINT(1.1) !(harvest(j))
1
> Error: Too many arguments in call to 'ieee_rint' at (1)
> any idea why?

Beats me. Looks like a good question for Andy.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
no comments
1 2