Re: converting a R code to fortran
- From: Michel Olagnon <molagnon@xxxxxxxxxxxxxxxxx>
- Date: Mon, 26 Feb 2007 16:44:43 +0100
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)
.
- Follow-Ups:
- Re: converting a R code to fortran
- From: e p chandler
- Re: converting a R code to fortran
- References:
- converting a R code to fortran
- From: fortee
- converting a R code to fortran
- Prev by Date: Re: converting a R code to fortran
- Next by Date: Re: fortran 2003 compiler
- Previous by thread: Re: converting a R code to fortran
- Next by thread: Re: converting a R code to fortran
- Index(es):
Relevant Pages
|
|