May I suggest to add one more topic for a discussion:
Comparison of particular languages AND compilers for numerical calculations,
primarily by those who use several languages in one project.
Particularly I would be interested in comparing fortran90 and C++.
I use a mixture of fortran90, fortran77 and C but did not do real work
with C++. I did make various test for Sun compilers and as
a general rule, f77 was 30-50% faster than f90 and cc (C compiler).
I talked people from Sun who developed compilers and they said
the cause is in a different technology they use for f90 which is still not
optimized for Sparc processor. It will be done starting with version 2.0
(the latest is 1.2).
However, it makes difference to program with f90,
particularly modules and matrix manipulations are extremely useful.
:-) From: Alan Williams <william@california.sandia.gov>
:-) Date: Tue, 18 Mar 1997 14:06:42 -0800
:-) Subject: Re: OON: matrix 'object' operations
:-)
:-) Chris Hecker wrote:
:-) >Todd Veldhuizen wrote:
:-) >> A = product(B, C);
:-) >> for a matrix product on our desktop Mac.
:-) >
:-) >Yes, we can write it (and even as A = B * C; in C++, if you're into that
:-) >sort of thing), but I think it's unclear how to make it both easy to use and
:-) >efficient. If you want your code to look exactly like that, what does
:-) >product(,) return? My experience is with C++, where this becomes a real
:-) >problem. product(,) can't return strictly by value or you've just copied
:-) >the A matrix. It can't return by reference for obvious reasons.
:-)
:-) I would do something like A.product(B,C);
:-)
:-) A is created by the caller, and dilemmas about what to
:-) return are avoided. It doesn't solve the problem of overloading "=",
:-) but it still makes code which is very readable.
:-)
:-) > ... what do you get
:-) >when you do this: D = A; Is D a new copy of A, or just another reference to
:-) >its data? Do you give it copy on write semantics?
:-)
:-) In this case, D is a new copy of A. If you want D to be a reference to A,
:-) you can do that with something like:
:-) Matrix& D = A;
In f90 it is up to a programmer to decide whether you want to copy or
a reference. If you write A=B+C (where A and B are matrixes of the same shape)
you will get A with elements obtained by `elemental' addition
(possibly obtained by simultaneous addition, if you processor has this
capability).
If you want to overload multiplication and then write A=B*C, you have a choice:
1) if you need to construct a result in A then the function defining
multiplication should return a matrix
(in f90, a function can return a matrix),
and elements will be simply computed in A.
E.g function mult(B,C)
real, dimension(:,:), intent(in) :: B, C
real, dimension(size(B,1),size(B,1)) :: mult
integer :: N = size(B,1)
integer :: K,J
mult=0. ; do J=1,N ; do K=1,N
mult(1:N,J)=mult(1:N,J)+B(1:N,K)*C(K,J) ; endo ; endo
end function mult
2) if you need a reference (means you already provided space for A, or
allocated before), you declare A and `function mult' to have
a pointer attribute, the multiplying function should return
a poiner to a matrix and
you assign this pointer by writing A=>B*C.
You can always have a copy if you need it writing A_prime=A.
But a space always has to to provided to preserve efficency.
+----------------------------------------------------------------+
| Nikolai Bannov Box 7911 |
| bannov@ecehlt1.ece.ncsu.edu Department of Electrical & |
| Computer Engineering |
| tel: +1-919-515-5080 North Carolina State University |
| fax: +1-919-515-3027 Raleigh, NC 27695-7911 |
+----------------------------------------------------------------+
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:05 EST