Re: converting a R code to fortran



fortee wrote:
I am now trying to convert a R code to fortran. I did what I can do my
best but a running time of my code is forever with n=5000 and r=20000.
The following R code comes from http://www.mcs.vuw.ac.nz/~ray/Brownian/algorithms.shtml
I need to iteration the following code 20, 000 times and get a
Kolmogorov-Smirnov(KS) statistics.


It is said on the web site: "With R though there is a distinct value to be
gained in performing computations in a vectorised (or even matrix) form, rather
than one value at a time."

I believe that the opposite is very often true for Fortran. You should try
to do as much as you can with each scalar value once you have fetched it
from memory to the CPU registers and before you store it again to memory,
and you should minimize memory use.

Look at the program that I posted on 2007-02-22. You should start from that
one. I tried to add comments to the inner loop now that I know what it does...

!
ks = 0.0
do j1 = 1, N+1 ! for each of the vertical lines s = cst
xd = 0.0 ! xd = sum_i I (x1_i < x1_j1
! & x2_i < x2_j2)
x1j = x1e(j1)
do m2 = 1, N+1
j2 = j2e (m2) ! take points in increasing t order
ks = max(ks, abs(xd-ns*x1j*x2e(j2))) ! check for supremum
if (x1e(j2)< x1j) then
xd = xd + 1.0 ! update xd for the rest of the loop, when
! point for the current t value is to the left
! of the current vertical line s = x1j
endif
enddo
enddo
!
ks= ks / sqrt (ns)

.



Relevant Pages

  • Re: Im missing something here with range vs. xrange
    ... the cost of creating the ... Allocate a big chunk of memory ... iteration is a separate step, ... The creation of the xrange object is massively faster - at least an ...
    (comp.lang.python)
  • Re: FASTER PERFORMANCE
    ... It depends on what apps you run, but that's enough for most people. ... If you are not using the page file significantly, more memory will do ... When I said forever, I mean, it's like a minute or two for some programs. ... Microsoft MVP Windows - Shell/User ...
    (microsoft.public.windowsxp.general)
  • Re: FASTER PERFORMANCE
    ... 504MB of Ram ... It depends on what apps you run, but that's enough for most people. ... If you are not using the page file significantly, more memory will do ... When I said forever, I mean, it's like a minute or two for some programs. ...
    (microsoft.public.windowsxp.general)
  • Re: FASTER PERFORMANCE
    ... If you are not using the page file significantly, more memory will do ... When I said forever, I mean, it's like a minute or two for some programs. ... Ken Blake, Microsoft MVP Windows - Shell/User ...
    (microsoft.public.windowsxp.general)
  • Re: Fearsome Parsing challenge, round 2.
    ... On all the platform's I've encountered, the behaviour when you change a long sting into a shorter one is to re-use the memory associated with the long string to contain the shorter string, leaving some unused, but not forgotten memory. ... The first iteration is fast, the second iteration is really slow, the third is fast, but not as fast as the first. ...
    (comp.lang.rexx)