From: Baalzamon on 25 May 2010 18:14 Ah I know i said i only had a couple more questions...but .... I stumbled across something that told me that indices in arrays can be negative numbers; is this true? If so how does the 'mex' thingy cope with this? One of my options for my conversion is to, as someone pointed out previously, is to call the functions, subroutines etc straight from matlab. Which I shall implement but more as a timing experiment. The first priority is to convert the code. This is one for the Fortran programmers. Could anyone explain, line by line, if possible the code for 'DAXPY'. Why the need for unequal increments (and what does this mean)? If I understand we are trying to work out z=Ax + y where x and y are vectors. Thus I thought the situtations are A=0 so z=y A=1 so z=x+y A=-1 so z=y-x in theory these should be less calculations, as such faster to work out so check for this first. Only situtaions that are left A>1 or A<-1 As such why is the code not something like this? DO 10 I=1, N Z(I)=A*(x(I)) + y(I) 10 CONTINUE
From: James Tursa on 25 May 2010 19:13 "Baalzamon " <baalzamon_moridin(a)yahoo.com> wrote in message <hthi3g$347$1(a)fred.mathworks.com>... > Ah I know i said i only had a couple more questions...but .... > I stumbled across something that told me that indices in arrays can be negative numbers; is this true? Yes. In Fortran you can set up the array indexing to have any range you want. However, based on your further comments I don't think this is the case for your example. > If so how does the 'mex' thingy cope with this? If the Fortran is written correctly no adjustment is necessary. > One of my options for my conversion is to, as someone pointed out previously, is to call the functions, subroutines etc straight from matlab. Which I shall implement but more as a timing experiment. The first priority is to convert the code. > This is one for the Fortran programmers. Could anyone explain, line by line, if possible the code for 'DAXPY'. DAXPY is a BLAS routine. Please don't tell me you are converting a BLAS routine to MATLAB m-code! MATLAB already has a BLAS library you can call directly from a mex routine that implements all of the BLAS routines, including DAXPY. If you are just trying to understand what DAXPY does, then google "netlib daxpy" and click on the netlib link to see the source code with comments. Here is what the first section says for DAXPY: SUBROUTINE DAXPY(N,DA,DX,INCX,DY,INCY) * .. Scalar Arguments .. DOUBLE PRECISION DA INTEGER INCX,INCY,N * .. * .. Array Arguments .. DOUBLE PRECISION DX(*),DY(*) * .. * * Purpose * ======= * * constant times a vector plus a vector. It is basically doing the calculation DY = DY + DA * DX. If you examine the code you find that the code allows for traversing the input vectors in either order (first-to-last or last-to-first) and with a non-unit step. That is what the INCX and INCY inputs are for. The same thing can be handled in m-code with the loops replaced with vector calculation using colon indexing. (btw, the same can be said for modern Fortran). James Tursa
From: dpb on 26 May 2010 00:18 dpb wrote: > James Tursa wrote: >> "Baalzamon " <baalzamon_moridin(a)yahoo.com> wrote in message >> <htgngo$3ig$1(a)fred.mathworks.com>... >>> >>> DO 10 I=1, N >>> a(I)=b(I)/5 >>> 10 z(I)=a(I)**2 >>> Is the statement at the end label a part of the loop, I much thought >>> it is.... >> >> Yes. The above is the same as: >> >> a(1:N) = b(1:N) ./ 5; >> z(1:N) = a(1:N) .^ 2; >> >> James Tursa > > Which is the same as > > a(1:N) = b(1:N)/5.0 > z(1:N) = a(1:N)^2 > > In F90 and later... > > :) > > Or, of course, if the arrays a and b are of size N then one can as in ML > dispense w/ the subscript range expressions as well. Ooops... >> z(1:N) = a(1:N) .^ 2; goes to z(1:N) = a(1:N)**2 "**" is Fortran exponentiation operator, not "^" ... --
From: us on 26 May 2010 02:48 "Baalzamon " <baalzamon_moridin(a)yahoo.com> wrote in message <ht36t0$dc8$1(a)fred.mathworks.com>... > I am attempting to convert some old fortran codes and becoming somewhat annoyed by the apparent jumping of code. WOuld I be correct in assuming that the code is read top to bottom and in line number order? If so where does the do label numbers figure into this scheme? Any advice from fortan programmers would be appreciated. To be explicit I think the coxde was written in F77... why not simply use ML's F interface(?)... http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f23224.html us
From: dpb on 26 May 2010 08:11
James Tursa wrote: > "Baalzamon " <baalzamon_moridin(a)yahoo.com> wrote in message > <hthi3g$347$1(a)fred.mathworks.com>... .... >> This is one for the Fortran programmers. Could anyone explain, line by >> line, if possible the code for 'DAXPY'. > > DAXPY is a BLAS routine. Please don't tell me you are converting a BLAS > routine to MATLAB m-code! ... .... > * Purpose > * ======= > * > * constant times a vector plus a vector. > > It is basically doing the calculation DY = DY + DA * DX. If you examine > the code you find that the code allows for traversing the input vectors > in either order (first-to-last or last-to-first) and with a non-unit > step. That is what the INCX and INCY inputs are for. The same thing can > be handled in m-code with the loops replaced with vector calculation > using colon indexing. (btw, the same can be said for modern Fortran). And, I'll note that the vector notation of both Matlab and Fortran in the source code will be turned into the same DO loop by the compilers for execution and as would also be done by a C or Cpp or virtually any other optimizing compiler language. -- |