| Fortran numerical server using Com server wizard. |
|
 |
Index ‹ fortran
|
- Previous
- 1
- interface-implementation separation
Hi all,
the topic of this post was discussed earlier in c.l.f [1] and possible
solutions were shown [2].
In 1997, it was suggested to have types and interfaces in one file and
external routines as the implementation of those interfaces in another
file.
Did different solutions or coding patterns to solve the problem of
separating interface and implementation in F90/F95 emerge since then?
Regards
Daniel
[1]
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/f0c2f853d45746f4
(Van Snyder, reply 10)
[2]
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/154579afbce7f1cb
(Artur Swietanowski, reply 19)
- 5
- Optimisation questionHi all.
I've got a chunk of code which for some of our programs eats up 50% of
the CPU time, and I would appreciate suggestions for optimising it.
Given that it involves an exponential I've tried using a lookup table
(accuracy is not critical here) and to my surprise it's slower :). The
times here (on a P4):
Intel compiler:
ifc -O3 -fpp -tpp6 -xW -ip -pad -rcd -w95 -cm testmorse.f -o testmorse
true : -2.272892E+07 in 1.620000 secs
table: -2.272892E+07 in 4.050000 secs
(with -xK instead, the 'table' value is 5.98 secs!)
G77:
g77-3.3 -O3 -malign-double -Wall -funroll-loops -finline-functions
-march=pentium4 -mfpmath=sse testmorse.f -o testmorse
true : -22728924. in 21.4400005 secs
table: -22728922. in 3.01000023 secs
Interestingly, g77 is faster for the lookup table but _much_ slower for
the 'true' calculation. On an Athlon the 'true' calculation still wins
over the lookup table with ifc, but the margin is smaller:
true : -2.272892E+07 in 2.110000 secs
table: -2.272892E+07 in 2.610000 secs
I need this code to run as fast as possible on a mixed cluster of P4 and
Athlon chips, and my days of inspecting and optimising assembly language
are sufficiently behind me that modern SIMD code is incomprehensible :(.
Suggestions as to ways to calculate this faster are welcome: note that
accuracy is not critical for this application (errors of 1% are
perfectly acceptable, which is why I'm nor using doubles).
Test code is below: apologies for the horrible F77-ness of it but it's
part of a massive F77 application which nobody's had the time or
patience to translate to anything more modern yet...
program morsetest
implicit none
integer i
real ee(100),rr(100),rm(100),en,en2,t,t2
c Test data: in the real world ee, rr, and rm have 'real' data in them
c and are generally 50-200 in length
do i=1,100
ee(i)=2.0
rr(i)=2.0
rm(i)=1.6+i/20.
enddo
call cpu_time(t)
en2=0
do i=1,1000000
call morsef2(100,ee,rr,rm,en)
en2=en2+en
enddo
call cpu_time(t2)
write(0,*) 'true : ',en2,' in ',t2-t,' secs'
en2=0
do i=1,1000000
call fastmorsef2(100,ee,rr,rm,en)
en2=en2+en
enddo
call cpu_time(t)
write(0,*) 'table: ',en2,' in ',t-t2,' secs'
stop
end
c*************************************************************************
subroutine morsef2(n,ee,rr,rm,en)
implicit none
integer j,n
real b,alp,exe,eng
real ee(n),rr(n),rm(n),en
data b/5.643/
en=0.0
do j=1,n
alp=rm(j)/rr(j)
exe=exp(b*(1.0e0-alp))
eng=ee(j)*((exe**2)-(2.0e0*exe))
en=en+eng
enddo
return
end
c*************************************************************************
subroutine fastmorsef2(n,ee,rr,rm,en)
implicit none
integer mtsize
parameter (mtsize=8192)
real mtinterval
parameter (mtinterval=8.0/mtsize)
common /morstab/ mtable,MORSETEST
real mtable(0:mtsize)
logical MORSETEST
integer i,j,n
real x,t1,t2,m
real ee(n),rr(n),rm(n),en
if (.not.MORSETEST) call fminit()
en=0.0
do j=1,n
x=rm(j)/rr(j) * 1/mtinterval
i=x
if (x.lt.(mtsize-1)) then
t1=x-i
t2=1.-t1
m=mtable(i)*t2 + mtable(i+1)*t1
en=en+m*ee(j)
endif
enddo
return
end
c*************************************************************************
subroutine fminit()
c Calculates the look-up table for use in fastmorse()
c Value stored:
c f(x)=exp(5.643*(1-x))
c g(x)=(f(x)**2-2*f(x))
c Store g(x) at 0.001 intervals over x=0:10
c Note that at x=10, g(x)=~1e-21, which is 0.0 to all intents and
c purposes.
integer mtsize
parameter (mtsize=8192)
real mtinterval
parameter (mtinterval=8.0/mtsize)
common /morstab/ mtable,MORSETEST
real mtable(0:mtsize)
logical MORSETEST
integer i
real f,g
real x
if (MORSETEST) return
do i=0,mtsize
f=exp(5.643*(1.0-(i*mtinterval)))
g=f**2-2*f
mtable(i)=g
x=i*mtinterval
enddo
c Flag table as initialised
MORSETEST=.true.
return
end
c*************************************************************************
--
Mark Mackey http://www.swallowtail.org/
Generally speaking, things have gone about as far as they can possibly
go, when things have got as bad as they can reasonably get.
- 7
- WG5-J3 Joint MeetingHello,
I'd like to remind everyone that WG5 and J3 will hold
their 2006 meeting next week on the Fairfax Campus
of George Mason University, histed by the School of
Computational Sciences.
Everyone, especially those in the Washington DC area,
is welcome to attend.
The meeting will be held in meeting rooms 2, 3, 4
of Student Union II.
The main agenda topic is the final selection of features
of Fortran 2008.
--
Cheers!
Dan Nagle
Purple Sage Computing Solutions, Inc.
- 7
- [newbe]: help me debugging this script, please!why does this script containing a function 'f_1' don't run?
PROGRAM bisezione
implicit none
real::a,b,prova !definisco gli estremi della funzione
real::f_1
write(*,*)("dammi il limite inferiore del dominio")
read(*,*) a
write(*,*)("dammi il limite superiore del dominio")
read(*,*) b
if (f_1(a)*f_1(b)<0) then
prova=(b-a)/2
write(*,*)("ci sono zeri nell'intervallo")
else
write(*,*)("non ci sono zeri nell'intervallo")
end if
write(*,*) prova,f_1(a),f_1(b)
end program
and f_1 is the following function
REAL FUNCTION f_1(x)
!prima funzione dell'esercizio 2
IMPLICIT NONE
REAL,INTENT(IN)::x !per fare in modo che la funzione non modifichi
accidentalmente gli argomenti di un programma
f_1=(x-1)**(-1)
END FUNCTION
- 7
- binary vs unformatted outputHi,
I'm getting biten by the difference between fortran 'unformatted' files
and the non-standard 'binary' format some compilers support. Apparently
'binary' files are written by neanderthals:
write(unitno) var
outputs the bits in var, no start/stop info, no record length, etc. If
you then use another program (matlab) to read it in, you read just the
bytes you wrote.
I have a program that uses 'binary' output. I'm trying to compile it on
a machine where 'binary' isn't supported. So I learn 'binary' is
non-standard! 'unformatted' is very close, except for the header and
footer bytes after every variable you write.
Is there any way to get rid of this extra info? I don't want to change
all my matlab scripts that read in data, or have two different data
formats to deal with.
I suppose it would be too much to ask for 'binary' to be supported in
fortan 2003!
Thanks,
David
- 10
- Interesting (but useless?) Fortran feature.Hi,
I was amazed to find that this is legitimate Fortran-90 code:
PROGRAM TEST
REAL, DIMENSION(3,0) :: P
REAL, DIMENSION(0,3) :: S
PRINT *, MATMUL(P, S)
END PROGRAM TEST
The result of this matrix multiplication is defined (in Fortran-90 at
least), and you get a 3x3 matrix full of 0s.
Tim.
- 11
- line printer subroutine in F90Here is a Fortran 90 interface to a Fortran 77 line printer
subroutine. It is
assumed that x ranges from 1 to N (# y values). The output is crude,
but the interface is as simple as
call line_plot_90(yy) .
If someone can recommend a public-domain F77 subroutine for X-Y
scatterplots,
I will make an interface for that too.
The F77 subroutine 'linplt' is at
http://ccl.osc.edu/cca/software/SOURCES/FORTRAN/simplex/linplt.f.shtml
module line_plot_mod
implicit none
private
public :: line_plot_90
integer, private, parameter :: istdout=6
contains
subroutine line_plot_90(yy,ncols,lp,kflag)
real , intent(in) :: yy(:) ! data to be plotted
integer, optional, intent(in) :: lp ! output unit -- set to s.o.
by default
integer, optional, intent(in) :: ncols ! # cols used in printing
graph
integer, optional, intent(out) :: kflag ! error flag
integer, parameter :: ncols_def = 51 ! default # of cols
used in printing graph
integer :: iu,n,mcols,iflag
n = size(yy)
if (present(lp)) then
iu = lp
else
iu = istdout
end if
if (present(ncols)) then
mcols = ncols
else
mcols = ncols_def
end if
call linplt(yy,n,mcols,iu,iflag)
if (present(kflag)) then
kflag = iflag
end if
end subroutine line_plot_90
end module line_plot_mod
program xlinplt
! driver for line_plot_90, which produces line printer graphics
use line_plot_mod, only: line_plot_90
integer, parameter :: n = 1000
real :: yy(n)
integer :: i
xk = 0.1
forall (i=1:n) yy(i) = sin(i*xk)
call line_plot_90(yy)
end program xlinplt
- 11
- Fortran booksBeliavsky <email***@***.com> wrote:
> When is the Fortran 2003 Handbook going to be published? In early 2004
> Walt Brainerd mentioned here that you would be co-authoring this book.
> I look forward to reading it. I like the Fortran 95 version.
Our contract with Springer says we deliver it in June (I'm not sure
whether we'll meet that - hope so) and it will be published in December
2007.
On the f95 version... well...let me try to put this gently. The f2003
one has been taking an awful long time to get out; you might have
noticed. When I joined with the other coauthors, I had no idea how big a
job it was going to be. Part of that was just my mis-estimation of how
long such things take. Part is that I'm just slow. But part is that I
thought we would be spending most of the time on the features new to
f2003. Turns out that by far the largest part of the time has been spent
in...umm...fixing material in the f95 handbook.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
- 11
- f77 and dynamic arrays in common blocksIs it at all possible to have dynamic 1d/2d arrays in fortran 77 common
blocks? I have figured out how to make dynamic 1d/2d arrays mixing c and
fortran but I cannot seem to get these to work in a common block. Is
there ANY way to do this? I would gladly use f90 modules and
'allocatable' declarations but there isn't a free f90 compiler for my OS
so I'm a bit stuck :(
An example would be greatly appreciated!
Thanks in advance,
Jamie
- 12
- Block data transfer, Fortran on LinuxHi,
(presently working with gnu f77 compiler)
I have an array with 100 columns and 1000 rows. Declared as 'double
precision arr(100,1000)' because fortran stores arrays in column major
format. Is there any thing really close to block data transfer that
can be done in assembly language (using the movs instruction) to move
data from one row to another.
I want to exchange rows really fastly, without copying one data item
at a time to a temp variable.
I have tried intel fortran compiler (fortran 95), which supports
copying an entire array into another. (say arrTemp=array1 ;
array1=array2; array2=arrTemp). This takes about double the time than
the simpe loop based idea using a single item temp.
Any suggestions please!
Thanks for ur time
Sincerely
Bhaskar
- 14
- f90 module variable scope and interactions with OpenMPhello
I am asking help in understanding the behavior of module variables and
opemmp. here is the program (at the end of this post):
the main program used a module called globaldata, and called a driver
internal subroutine "allocme" of the module.
inside the allocme subroutine, a do-loop allocates array a(:,:) with
different sizes and performs some operations.
now, I compile this code in Compaq Alpha f90 without -omp with the
following command: f90 testmod.f90 -o testmod
it prints out the right answer:
--------------------------------------------------------
allocme::n= 1
initme::n= 1 p= 1
------------------------------------
2.00000000000000
allocme::n= 2
initme::n= 2 p= 2
------------------------------------
2.00000000000000 3.00000000000000 3.00000000000000
4.00000000000000
allocme::n= 3
initme::n= 3 p= 3
------------------------------------
2.00000000000000 3.00000000000000 4.00000000000000
3.00000000000000 4.00000000000000 5.00000000000000
4.00000000000000 5.00000000000000 6.00000000000000
allocme::n= 4
initme::n= 4 p= 4
------------------------------------
2.00000000000000 3.00000000000000 4.00000000000000
5.00000000000000 3.00000000000000 4.00000000000000
5.00000000000000 6.00000000000000 4.00000000000000
5.00000000000000 6.00000000000000 7.00000000000000
5.00000000000000 6.00000000000000 7.00000000000000
8.00000000000000
--------------------------------------------------------
however, if i compile it with -omp option, f90 testmod.f90 -o testmod
-omp
it dies with the following message:
allocme::n= 2
initme::n= 5 p= 2
allocme::n= 1
initme::n= 5 p= 1
allocme::n= 3
initme::n= 5 p= 3
allocme::n= 4
initme::n= 5 p= 4
forrtl: severe (174): SIGSEGV, segmentation fault occurred
forrtl: severe (174): SIGSEGV, segmentation fault occurred
forrtl: severe (174): SIGSEGV, segmentation fault occurred
forrtl: severe (174): SIGSEGV, segmentation fault occurred
you can see that the value of n inside initme is always 5, which is
wield to me because I assume this n is the same as the n in globaldata
module and the n=5 in the main program as well. However, it seems
OpenMP created a temporary "n" which is different from globaldata::n.
Is is the expected behavior in OpenMP?
how can I call some subroutines inside the openmp parallel do loop
which do not need to pass arrays? (my actually subroutine needs about
30 arrays)
thank you very much
Qianqian
!=================================================
module globaldata
implicit none
real*8 , allocatable :: a(:,:)
integer :: n
contains
subroutine allocme
implicit none
!$omp parallel do default(shared) private(n,a)
do n=1,4
print *, 'allocme::n=',n
allocate(a(n,n))
call initme(n)
! passing n into initme just for verification
deallocate(a)
enddo
!$omp end parallel do
contains
subroutine initme(p)
implicit none
integer :: i,j,p
print *, 'initme::n=',n,'p=',p
do i=1,n
do j=1,n
a(i,j)=i+j
enddo
enddo
print *,'------------------------------------'
print *,a
end subroutine initme
end subroutine allocme
end module
!=================================================
program test
use globaldata
implicit none
n=5;
call allocme
end program test
!=================================================
--
- 14
- problem with iargc() and lnblnk() in cvfHi,
I obtained a library of fortran routines and I have trouble compiling
it because of two functions used in the subroutines -
iargc() and lnblnk()
I believe that (from google)
iargc() - no of command line arguments
lnblnk()- index of last non-blank character
Is there a simple way around this in CVF?
I would like some input on following -
lnblnk(argv) - Is it same as LEN_TRIM(argv) ?
iargc() --- don't know the equivalent
Any help will be appreciated. Thanks.
Veda.
- 14
- lm minpack f90Hello,
for one of my projects I wanted a reliable Levenberg-Marquardt
algorithm with generic precision, so
I downloaded Alan Miller's converted MINPACK subset (LMDER and LMDIF
subroutines) from
http://users.bigpond.net.au/amiller/lm.zip
which is converted using his to_f90 converter with a couple of manual
adjustments.
I played with the code much further,
replaced almost all GOTOs with block IF constructs or EXIT/CYCLE
statements,
replaced simple loops by array constructs, removed arguments with no or
little information value etc.
I intended to offer it to Alan, but the "What's New" section looks like
he has stopped maintaining his
site some 2 years ago.
Does anyone know about a F90 repository I could post the code to?
And a philosophical question:
Do you think converting old Fortran is a beneficial effort? Would you
use such a conversion rather than the original?
- 15
- Conversion of Fortran File unit to C File streamHello
I am using a data file which is opened in FORTRAN and the same file
goes inside the C code for writing. I send the file unit in the
fortran part and the same needs to be mapped to the File stream on
entering in to C so that i can continue working with the same file. I
wonder if this conversion is possible.
My scenario looks like this....
void fprint_message(int fileUnit)
{
/* conversion from fileUnit to File *f should happen here*/
call cprint_message(File *f);
}
Here i call fprint_message from Fortran and before this the file is
opened. Kindly help me out if any of you have ideas on this.
Arun
- 15
- Just fo fun: a minimal implementation of QuickSortHello,
the other day I realised that Fortran 90/95 offers a lot of features
that are commonly
referred to as "functional programming". While it is by no means a
functional programming
language - like for instance Haskell or ML - you can program in a more
or less functional
prgramming style. The code below shows an example:
! An implementation of QuickSort in functional programming style
!
program sortdata
real, dimension(1000) :: data
call random_number( data )
write(*,*) 'First 20: '
write(*,'(5f10.4)') data(1:20)
write(*,*) 'Last 20: '
write(*,'(5f10.4)') data(1000-21:1000)
data = qsort_reals( data )
write(*,*) 'Sorted:'
write(*,*) 'First 20: '
write(*,'(5f10.4)') data(1:20)
write(*,*) 'Last 20: '
write(*,'(5f10.4)') data(1000-21:1000)
contains
recursive function qsort_reals( data ) result( sorted )
real, dimension(:), intent(in) :: data
real, dimension(1:size(data)) :: sorted
if ( size(data) > 1 ) then
sorted = (/ qsort_reals( pack( data(2:), data(2:) > data(1) )
), &
data(1),
&
qsort_reals( pack( data(2:), data(2:) <= data(1) )
) /)
else
sorted = data
endif
end function
end program
I have not measured the performance in comparison to a more traditional
implementation using explicit do-loop and reusing the array "data".
Like
I say in the title: this is just for fun.
Regards,
Arjen
|
| Author |
Message |
Andrew Smith

|
Posted: 2008-7-3 4:57:26 |
Top |
fortran, Fortran numerical server using Com server wizard.
I have a large mainly numerical application for Win32 that employs a dll
written in F95/2003 code and has about 300 entry points attached to a
GUI developed in an old GUI language.
I need to move to 64 bit to obtain more memory space for the
calculations. The GUI is mainly outside my control and will remain 32
bit for some time but I am thinking about separating the dll into a
standalone application.
I have already been able to create this numerical application using the
Intel Com server Wizard and then using the Intel module wizard to create
the client code. The client code would be a new Fortran dll attached to
the GUI.
My problem is how to implement callbacks from the numerical server to
the client application. The Intel Com server wizard and module wizard do
not appear to support events or callbacks. Currently the whole thing is
envisaged as single threaded and synchronous but other solutions would
be acceptable.
Maybe I should use some other communication method instead of com
automation or maybe another language for the top level of the numerical
application. I have tried looking into C++ but could not understand much
at all.
Andy
|
| |
|
| |
 |
| |
 |
Index ‹ fortran |
- Next
- 1
- 2
- closing unit=5 and unit=6 and print *email***@***.com wrote:
> James Giles wrote:
>
>>> I don't believe that subtle distinction is strong enough to allow
>>> what DEC, Cray, and now Sun do. Suppose * and 6 (for example) are
>>> two different identifiers for the same unit. Then closing the unit
>>> idenitified by 6 should close the unit idenified by *, and that does
>>> not happen for those implementations. I could weasel-word my
>>> way around that, but if 6 is used to identify a unit in a subsequent
>>> OPEN statement, it does not change the connection for * in those
>>> implementations. I see no way to weasel-word my way around that.
>>
>> Suppose that * and 6 (for example) were two different identifiers
>> for a different units both of which (by default) talk to an
>> interactive terminal. Since that's not a file, there's no violation
>> of the rule about two units connecting to the same file. So,
>> closing 6 and reopening it need not change the connection for *.
>
> The Fortran standard has no concept of an interactive terminal.
You asked for weasel-words. The fact that the Standard has no
concept of interactive terminal makes the weasel-word explanation
I gave even more convincing. Something beyond the scope of
the standard is the ultimate weasel.
> [...] The DEC/Compaq/HP implementation (I don't know if the
> behavior has carried over to Intel's implementation), Cray's
> implementation, and Sun's implementation treat the units identified
> by one of the uses of * and 6 as if they are the same unit initially,
> but as different units if the unit identified by 6 is closed.
Then I agree that those are bad *if* that initial connection was a file.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
- 3
- fftw and g77Hi,
sorry, but I am not able to find, how I can tell g77 to use
the fftw library for a sample program.
fftw puts its files into:
/usr/bin/fftw-wisdom-to-conf
/usr/bin/fftwf-wisdom
/usr/include/fftw3.f
/usr/include/fftw3.h
/usr/lib/libfftw3f.a
/usr/lib/libfftw3f.la
/usr/lib/pkgconfig/fftw3f.pc
The sample fortran program looks like:
program test
implicit none
#include "fftw3.f"
integer N
parameter(N=4)
integer*8 plan
complex in, out
dimension in(N),out(N)
integer i
write(*,*) 'Input array:'
do i = 1,N,1
in(i) = cmplx(float(i),float(i+1))
write(*,*) ' in(',i,') = ',in(i)
enddo
call sfftw_plan_dft_1d ( plan, N, in, out,
^ FFTW_FORWARD, FFTW_ESTIMATE )
...
...
...
I tried to compile it with:
g77 f77_testf.F -L/usr/lib/libfftw3f.a
I get:
/tmp/cczBhlks.o(.text+0x157): In function `MAIN__':
: undefined reference to `sfftw_plan_dft_1d__'
/tmp/cczBhlks.o(.text+0x162): In function `MAIN__':
: undefined reference to `sfftw_execute__'
/tmp/cczBhlks.o(.text+0x272): In function `MAIN__':
: undefined reference to `sfftw_destroy_plan__'
/tmp/cczBhlks.o(.text+0x2a3): In function `MAIN__':
: undefined reference to `sfftw_plan_dft_1d__'
/tmp/cczBhlks.o(.text+0x2ae): In function `MAIN__':
: undefined reference to `sfftw_execute__'
/tmp/cczBhlks.o(.text+0x406): In function `MAIN__':
: undefined reference to `sfftw_destroy_plan__'
collect2: ld returned 1 exit status
Do you have any hint?
Greetings, Fabian
- 4
- [visual fortran 6.0] problem with array name
<email***@***.com> wrote in message
news:email***@***.com...
> A colleague of me has a problem. Calling a function an giving two
> arrays as parameters does not work as expected (and i do have no clue
> about fortran ;)
> Calling the function (defined in an extra file(module) with testarray
> and DDSCRE as parameters does work, but using MAT_INV results in an
> error:
>
> Compiling Fortran...
> C:\Program Files\Microsoft Visual Studio\MyProjects\p2\Potential.for
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\p2\Potential.for(435) : Error: The type of the actual
> argument differs from the type of the dummy argument. [MAT_INV]
>
>
> This is an excerpt of the code:
>
>
> SUBROUTINE UMAT(STRESS,STATEV,DDSDDE,SSE,SPD,SCD,
> RPL,DDSDDT,DRPLDE,DRPLDT,STRAN,DSTRAN,
> TIME,DTIME,TEMP,DTEMP,PREDEF,DPRED,MATERL,NDI,NSHR,NTENS,
> NSTATV,PROPS,NPROPS,COORDS,DROT,PNEWDT,CELENT,
> DFGRD0,DFGRD1,NOEL,NPT,KSLAY,KSPT,KSTEP,KINC)
> USE nrtype;USE nrutil;USE nr
>
>
> ! INCLUDE 'ABA_PARAM.INC'
>
> CHARACTER*80 MATERL
>
> DIMENSION STRESS(NTENS),STATEV(NSTATV),
> DDSDDE(NTENS,NTENS),DDSDDT(NTENS),DRPLDE(NTENS),
> STRAN(NTENS),DSTRAN(NTENS),TIME(2),PREDEF(1),DPRED(1),
> PROPS(NPROPS),COORDS(3),DROT(3,3),
> DFGRD0(3,3),DFGRD1(3,3)
>
> DIMENSION EELAS(NTENS),ECREE(NTENS),DDSELA(NTENS,NTENS),
> MAT_INV(NTENS,NTENS),DDSCRE(NTENS,NTENS),
> STRANG(NTENS), DSTRANC(NTENS),STRANE(NTENS),SD(NTENS),
> DSTRANEL(NTENS),PART_EPSILON_WITHC(NDI),BMATRIX(NTENS,NTENS),
> testarray(10,10)
>
> PARAMETER (ONE=1.0D0,TWO=2.0D0,THREE=3.0D0,SIX=6.0D0)
>
>
>
> [...]
>
> do i=1,6
>
>
> Call asaaa9876678 !no error, why?
> call gaussj(BMATRIX(1:i,1:i),DDSCRE(1:i,1:i)) !this works
>
> Call gaussj(MAT_INV(1:i,1:i), BMATRIX(1:i,1:i)) !this gives an error
One or the other has to be correct. You haven't shown us the definition of
Mat_Inv, but gaussj must expect it to be real. However, the default (i. e.
if you don't say otherwise) type of Mat_Inv is integer.
The solution is to declare Mat_Inv to be real.
Jim
>
>
>
> Thank you in advance,
> Bernd
>
- 5
- Read errorDear Fortran group,
I have run into a strange problem which I believe is a compiler bug.
What I do is the following. I read a whole line from a file and then I read parts of this line using a loop. See the source code
extract below.
DO i = 1, obss
READ(line(-15+i*16:i*16), '(F14.3,I1,I1)', IOSTAT=readStat) &
rinexObs%meas(typeObs(i,1))%value, lli, &
rinexObs%meas(typeObs(i,1))%strength
IF (readStat < 0) THEN
endOfLine = .TRUE.
ELSE IF (readStat > 0) THEN
EXIT Body
END IF
END DO
The problem that I have is that the contents of the file is incorrect. Rather than a F14.3 the file contains F16.3,I1,I1 blocks.
So for i=1 the above loop works OK but for i=2 I end up reading something like:
123-5678901234 into the F14.3. Now I would expect that this would set the readStat to be something >0 but in effect at this point
the program crashes (and I am 100% sure that it crashes at this point).
So to my understanding this is a compiler bug, right!? Or I am doing something against the fortran standard, e.g., reading from a
string (line) rather than from a file unit?
Cheers,
Tim
ps. I am working on Sun Solaris 2.8 using a (very) old compiler (WS6).
- 6
- Compaq Visual Fortran VB6 dllHello,
I have created a Fortran dll program under Compaq Visual Fortran. I am
calling this from a VB6 program. ( See partial listings).
When I run the VB program I get "Sub or function not defined" error.
Why? Where am I doing wrong. Thank you.
Athena
---------------------------------------------------------
Fortran Program:
! DunnettTukey.f90
!
! FUNCTIONS/SUBROUTINES exported from DunnettTukey.dll:
! DunnettTukey - subroutine
!
module comm
real, dimension(:,:),allocatable::vc,hm,p,c,gg,vcc
integer k,k1,ndenom,lines,mocar,irep,mm,notempty,icontrol
real zero,zone,two,zoneplus,sx,ssx,zrep,coc,sd,zmean,se
real brakl,braku,conf,xacc,seed,givense,zmocar
parameter (mr=714025,ia=1366,ic=150889,rm=1./mr)
end module comm
! Program Dunnett-Tukey Critical Values
Subroutine DunnettTukey(iType,r,df,Alpha,CritValue)
!DEC$ ATTRIBUTES DLLEXPORT::DunnettTukey
!DEC$ ATTRIBUTES ALIAS:"DunnettTukey"::DunnettTukey
use comm
integer,intent(in)::r
integer,intent(in)::df
integer,intent(in)::iType
real,intent(in)::Alpha
real,intent(OUT)::CritValue
conf=Alpha
ndenom=df
k=r
call DBatch(iType,iseed1)
CritValue=zmean
return
end subroutine DunnettTukey
Subroutine DBatch(swtype,iseed1)
.........
VB6 Program form:
Option Explicit
Dim CritValue As Single
Dim r As Integer
Dim df As Integer
Dim iType As Integer
Dim Alpha As Single
Private Sub cmdCalc_Click()
df = CInt(txtdf.Text)
r = CInt(txtr.Text)
Call DunnettTukey(iType, r, df, Alpha, CritValue)
txtCritValue = CritValue
End Sub
VB6 Bas Module:
Declare Sub DunnnettTukey Lib "c:\windows\system32\DunnettTukey.dll" (iType
As Long, r As Long, df As Long, Alpha As Single, CritValue As Single)
- 7
- problem between c++ and fortran memory boundaryHi All,
I am having a peculiar problem. I used to link between intel fortran 7.0
and g++ without any problem. Now the intel compiler is upgraded to version
9.0 and I am getting segmenatation fault. While debugging I found when data
structures are allocated in C++ and passed to fortran subroutines the
fortran subroutines are accessing a different location in the address space.
For example I have created a very simple program that shows the problem
The fortran subroutine in the file b.f
subroutine fortran_sub(MAXNODS,NODES)
type node
integer :: order
integer :: father
integer :: sons(3)
double precision :: zdofs(10)
endtype node
type(node) ::NODES(MAXNODS)
integer MAXNODS,i
do i = 1 , MAXNODS
NODES(i)%order = i
NODES(i)%father = i
enddo
return
end
The C++ main function in a.cpp
#include <iostream>
using namespace std;
class node_contiguous_struct {
public:
int order;
int father;
int sons[3];
double zdofs[10];
};
typedef node_contiguous_struct * node_array_contiguous;
extern "C" {
void fortran_sub_(int *MAXNODS,node_array_contiguous NODES);
}
int main(void)
{
node_array_contiguous NODES;
int MAXNODS = 5;
NODES = new node_contiguous_struct[MAXNODS];
fortran_sub_(&MAXNODS,NODES);
for (int i = 0; i < MAXNODS; i++) {
cout << "\nNODES["<<i<<"]\n";
cout << " .order = " << NODES[i].order;
cout << " .father = " << NODES[i].father;
}
return 0;
}
and the output of the program
NODES[0]
.order = 1 .father = 1
NODES[1]
.order = 0 .father = 2
NODES[2]
.order = 0 .father = 0
NODES[3]
.order = 0 .father = 0
NODES[4]
.order = 0 .father = 0
Obviously the fortran subroutine is writing somewhere else in the memory
space, thus after the first index everything is messed up. I did not had
this problem with intel fortran compiler version 7. Can this be a compiler
specific problem? Am I doing something wrong here?
Any help is appreciated.
Thanks
NM
- 8
- DDJ article on ACML for OpteronThe March 2005 issue of Dr. Dobb's Journal has an article
"High-Performance Math Libraries" by Mick Pont of NAG on the use of AMD
Core Math Library (ACML) to speed up BLAS, LAPACK, and FFT routines.
The article can be purchased online from
http://www.ddj.com/articles/2005/0503/ .
- 9
- Ragged arrayHi there,
I need to create a number of data objects, whose types are like this:
type
real v (:)
! other structure members
end type
Each object should contain a 1D array of different, in general,
length. Unfortunately, I cannot use allocatable arrays in types. If I
could create some
2D mattrix, whose rows (or columns) are of different lengths, then I
would
probably be able to store pointers to appropriate sections of this
matrix inside
the said data objects. How could I implement this data structure most
simply and efficiently?
- 10
- GFortran run time error codes. Where to find them?Hello,
Apologies for posting this to clf rather than contacting the GFortran folks directly (I
will be doing that too), but I sorta need these numbers quickly and I'm hoping someone out
there has a list.
I've switched all the test code I distribute to explicitly use gfortran. Some users are
reporting my test codes are failing during an allocation, e.g.
Allocate_CloudCoeff(FAILURE):Error allocating CloudCoeff data arrays. STAT = 390
I am having trouble finding an official list of the GFortran run time error codes for
things like STAT and IOSTAT specifiers. I've checked the GFortran manuals but can't find
any reference to the actual numbers GFortran generates for DE/ALLOCATE STAT and READ/WRITE
IOSTAT specifiers when an error occurs.
Can anyone out there point me to such a list for GFortran? I need to know what an allocate
STAT of 390 means.
Thanks,
paulv
p.s. Note that the errors occurs running code compiled using gfortran v4.1.2 20070626. On
my machine, which has gfortran v4.3.0 20080215 (experimental) [trunk revision 132330], the
code runs fine. Both gfortran versions compile the code fine. Is this a earlier version
gfortran bug? I did check bugzilla, but got lost in a bunch of C-code. :o)
- 11
- howto optimize this stupid subroutineSorry for my poor english
Hi all
For my work, i developed a simple gentic algorithm(GA).
In this GA is present one subroutine same as:
----------------------------------
program prova
implicit none
integer,parameter :: x=10000
integer, parameter ::y=3
integer :: i,j
real,dimension(x,y) :: matrice
real,dimension(3) :: tmp
call random_seed()
call random_number(matrice)
do i=1,x-1
do j=i+1,x
if(matrice(j,1) < matrice(i,1)) then
tmp = matrice(i,:)
matrice(i,:) = matrice(j,:)
matrice(j,:) = tmp
endif
enddo
enddo
print*,10,1,matrice(10,1)
end program prova
--------------------------------------------------
$ ifort riordino.f90
$ time -p ./a.out
10 1 1.3077976E-03
real 4.14
user 4.12
sys 0.01
i try to implement this code in C (most prolisse code :( )
------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define X 1000
#define Y 3
int main(void){
int i,j;
float **matrice;
float *tmp;
srand48(time(NULL)); //not standard
matrice = malloc(sizeof(float)*X);
for(i=0;i<X;i++){
matrice[i] = malloc(sizeof(float)*Y);
}
for(i=0;i<X;i++){
for(j=0;j<Y;j++){
matrice[i][j] = drand48();
}
}
for(i=0;i<X-1;i++){
for(j=i+1;j<Y;j++){
if(matrice[j][1] < matrice[i][1]){
tmp = matrice[j];
matrice[j] = matrice[i];
matrice[i] = tmp;
}
}
}
fprintf(stdout,"%d %d %f\n",9,0,matrice[9][0]);
return 0;
return 0;
}
------------------------------------------------
$ cc riordino.c
$ time -p ./a.out
9 0 0.243124
real 0.03
user 0.02
sys 0.00
mmhhh run very fast.
How to implement a poiter metod in fortran95 like C?
new test whit DIM1 = 100000
cc riordino.c
$ time -p ./a.out
9 0 0.555556
real 0.24
user 0.22
sys 0.02
$ ifort -O2 -fast riordino.f90
$ time -p ./a.out
Very slow then CTRL-C
forrtl: error (69): process interrupted (SIGINT)
real 208.84
user 184.58
sys 0.13
C metodo swap only pointer, Fortran95 swap all cells of array
:(
tanks all
- 12
- Online CVF/DVF manualUntil recently I could view the CVF Version 6.6 Programmer's Guide and
Language Reference online, but now I find that all the links take me to
here:
http://h21007.www2.hp.com/portal/site/dspp/menuitem.968f6ac7b9e623e32c24b83f8973a801/
which is the page for HP's Developer & Solution Partner Program.
Is there a site where these useful documents can still be viewed?
- 13
- translate FORTRAN to MATLAB codehi all,
can someone help me out? I got some FORTRAN code and I want to use it in
MATLAB. I dont know FORTRAN, so can someone please recode this in MATLAB
functions? thx! Eelco
here's the code:
CC=======================================================================
CC======CALCULATES THE TEST STATISTIC T1_{n,a}===========================
CC=======================================================================
SUBROUTINE TESTLP1(AL,PHI,X,N,Tn)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION X(N)
ONE=1.0D0
TWO=2.0D0
SUM=0.0D0
FN=N
DO 1 J=1,N
DO 2 K=1,J
XJ=X(J)
XK=X(K)
SXJK=XJ+XK
PXJK=XJ*XK
DEN1=SXJK+AL
DEN2=DEN1*DEN1
DEN3=DEN2*DEN1
FNUM1=PXJK-(PHI*SXJK)+(PHI*PHI)
FNUM2=(TWO*PXJK)-(PHI*SXJK)
FNUM3=TWO*PXJK
TER1=FNUM1/DEN1
TER2=FNUM2/DEN2
TER3=FNUM3/DEN3
TER=TER1+TER2+TER3
IF(J.NE.K) TER=TWO*TER
SUM=SUM+TER
2 CONTINUE
1 CONTINUE
FAC=ONE/FN
Tn=FAC*SUM
RETURN
END
CC=======================================================================
CC======CALCULATES THE TEST STATISTIC T2_{n,a}===========================
CC=======================================================================
SUBROUTINE TESTLP2(AL,PHI,X,N,Tn)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION X(N)
PI=3.14159265358979324D0
ONE=1.0D0
TWO=2.0D0
SUM=0.0D0
FOR=4.0D0
XLIM=700.0D0
FN=N
PRO=DSQRT(PI/AL)
DO 1 J=1,N
DO 2 K=1,J
XJ=X(J)
XK=X(K)
SXJK=XJ+XK
PXJK=XJ*XK
EX=SXJK*SXJK/(FOR*AL)
ARG=SXJK/(TWO*DSQRT(AL))
FAC1=ONE-DERF(ARG)
IF(EX.LE.XLIM) FAC=DEXP(EX)*FAC1
IF(EX.GT.XLIM) FAC=0.0D0
TER1=PXJK+(PHI*PHI)-(PHI*SXJK)
TER1=TER1*FAC*PRO
TER2=(TWO*PXJK)-(PHI*SXJK)
FAC1=FAC*SXJK*PRO
FAC1=TWO-FAC1
TER2=TER2*(FAC1/(TWO*AL))
TER3=PXJK
FAC1=FAC*((SXJK*SXJK)+(TWO*AL))*PRO
FAC1=FAC1-(TWO*SXJK)
TER3=TER3*FAC1*(ONE/(FOR*AL*AL))
TER=TER1+TER2+TER3
IF(J.NE.K) TER=TWO*TER
SUM=SUM+TER
2 CONTINUE
1 CONTINUE
FAC=ONE/(TWO*FN)
Tn=FAC*SUM
RETURN
END
- 14
- Moderately OT: Scientific File DesignHi
I'm looking for some input on file designs for scientific data - if
you're not interested in this sort of thing you should ignore this
posting completely. If you are, please read on:
We're soon to embark on the redesign of one of our systems. One of
the main areas of functionality of the system is data management. The
basic data is geophysical signal records from our instruments. The
records are processed, transformed, manipulated etc, and a variety of
modelling and inversion operations carried out. The data management
issues will be familiar: issues of auditability, traceability,
provenance etc: what operations were carried out to transform signal A
into signal A', who carried them out, what versions of what programs
were used, etc.
For each project we carry out we'll typically collect data from a
handful of lines of instrumentation (survey data), each of which
comprises 10s (that's 10-off, not 10 seconds) -- 100s of sensors, each
of which records 10s -- 100s of signals. Back home the data is
processed, so each input signal might give rise to multiple output
signals (different filters, different downsampling, etc), and so on.
In short, the data fits quite naturally into a hierarchical structure.
Right now we manage our data in what I would describe as a 'file
forest' -- each signal is in a file, which is in a directory, which is
in a directory, and so on. In a typical project the directory
structure might be 8 layers deep, with an average branching factor of
3 - 4 -- seriously some of our projects ultimately comprise 20,000
files or more. Each of the files contains a bunch of (text) header
data, maybe 80 lines of up to 80 characters, and signal data which is
of the order of 4 columns of up to about 1000 rows of floating-point
numbers. There's a lot of redundant duplication of data -- when a
signal is transformed the output file might contain the same header
info as the input file, plus a few more lines describing the
transformation, and the same data, but with a new column of figures
added (the transform of one of the other columns of data). And
there's an awful lot of files. Mostly the directories and files are
created and managed by the existing system, but users can open up a
file and tweak it if they wish to.
So, wearing my software engineering hat, I'm thinking -- this is a
mess, the new system should rationalise this data management and
introduce some structured file formats. I'm thinking XML, HDF5, maybe
Infosets. Now, there's a wealth of information on XML, and pretty
good documentation on the others, most of it directed to telling you
how to use the formats and their associated tools. But everything I
find leaves me with 3 questions, and this is what I'm hoping some of
you might be able to give me pointers on:
1. What are the relative merits of XML, HDF5 and Infosets ? I think
I've figured out that plain XML is limited in file size to about the
size of my computer's RAM since parsing an XML file requires it to be
read in one go (but that standards like Xlink (?) might help us round
this). And yes, XML is kind of bloated for scientific data sets, but
we're only talking GBs of data, not TBs, and there are good reasons
for having readable data sets -- much easier for geophysicists to
prototype bits and pieces of code for one. But is there any hard info
out there on why to choose one rather than the others ? Or why to
avoid one or all like the plague ?
2. OK, having chosen my favourite approach to file design, how do I
design a file ? If we choose to go XML, how do I decide what become
attributes, what are tags, and what are just text ? The published
info I've found is quite good at telling you how to implement a
design, but less good at how to derive a design in the first place.
3. How do I persuade my boss that the effort associated with
modifying our working practices will be repaid ? As a software
engineer the sheer inelegance of our current approach persuades me
that it is bad -- but I'm not sure that's strong enough. Another
argument is that our current approach duplicates a lot of data, but we
haven't yet had a horrendous incident arising from this (ie non-
agreement of what should be identical data) which would make a
compelling case for change. And the argument about wasting disk space
is not an argument now that disks are so cheap.
OK, I realise I'm asking for a lot, and I don't really expect a load
of free consultancy, but if anyone cares to send me some links to
useful sites, or published papers, I'd really appreciate it.
And, in case you were wondering why this message is being posted to
comp.lang.fortran, it's because our language of choice is Fortran
(though we do dabble in C, C++, Python and Java too).
Thanks
Mark Westwood
- 15
- Allocatable derived type with allocatable components in fortran 90
"Ben Hetland" <email***@***.com> wrote in message
news:e09972$t2g$email***@***.com...
>
> Yes, actually I guess the TARGET attribute is what helps Fortran
> compilers do a good optimization.
It was added to the language for precisely that reason.
Regards,
Mike Metcalf
|
|
|